diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..ca89b6ae8 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +**/.dockerignore +**/.git +Dockerfile* +.* +docker-data/ diff --git a/.env.example b/.env.example deleted file mode 100644 index 1a455025a..000000000 --- a/.env.example +++ /dev/null @@ -1,4 +0,0 @@ -# Docker may need a .env file for the following settings: -DATABASE_PORT=27017 -DATABASE_USERNAME=root -DATABASE_PASSWORD=database diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3aa07742f..694189932 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,4 +19,4 @@ jobs: - run: cp config.json.example config.json - run: echo '{"version":"","buildLabel":"","matchmakingBuildId":""}' > static/data/buildConfig.json - run: npm run build - - run: npm run lint + - run: npm run lint \ No newline at end of file diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 000000000..803e67824 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,25 @@ +name: Build Docker image +on: + push: + branches: + - main +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Set up Docker buildx + uses: docker/setup-buildx-action@v3 + - name: Log in to container registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push + uses: docker/build-push-action@v6 + with: + platforms: linux/amd64,linux/arm64 + push: true + tags: | + ghcr.io/spaceninjaserver/spaceninjaserver:latest + ghcr.io/spaceninjaserver/spaceninjaserver:${{ github.sha }} diff --git a/.gitignore b/.gitignore index d1ec73738..2661a52ae 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,7 @@ yarn.lock /logs # MongoDB VSCode extension playground scripts -/database_scripts \ No newline at end of file +/database_scripts + +# Default Docker directory +/docker-data diff --git a/Dockerfile b/Dockerfile index c218511b2..f265957f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,28 @@ -FROM mongo as base +FROM node:18-alpine3.19 -EXPOSE 27017 +ENV APP_MONGODB_URL=mongodb://mongodb:27017/openWF +ENV APP_MY_ADDRESS=localhost +ENV APP_HTTP_PORT=80 +ENV APP_HTTPS_PORT=443 +ENV APP_AUTO_CREATE_ACCOUNT=true +ENV APP_SKIP_STORY_MODE_CHOICE=true +ENV APP_SKIP_TUTORIAL=true +ENV APP_SKIP_ALL_DIALOGUE=true +ENV APP_UNLOCK_ALL_SCANS=true +ENV APP_UNLOCK_ALL_MISSIONS=true +ENV APP_UNLOCK_ALL_QUESTS=true +ENV APP_COMPLETE_ALL_QUESTS=true +ENV APP_INFINITE_RESOURCES=true +ENV APP_UNLOCK_ALL_SHIP_FEATURES=true +ENV APP_UNLOCK_ALL_SHIP_DECORATIONS=true +ENV APP_UNLOCK_ALL_FLAVOUR_ITEMS=true +ENV APP_UNLOCK_ALL_SKINS=true +ENV APP_UNIVERSAL_POLARITY_EVERYWHERE=true +ENV APP_SPOOF_MASTERY_RANK=-1 -CMD ["mongod"] \ No newline at end of file +RUN apk add --no-cache bash sed wget jq + +COPY . /app +WORKDIR /app + +ENTRYPOINT ["/app/docker-entrypoint.sh"] diff --git a/docker-compose.yml b/docker-compose.yml index 085c452e4..5882ad5d1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,24 +1,43 @@ -version: "3.9" - services: - mongodb: - container_name: mongodb - image: mongodb - restart: always - build: - context: . - dockerfile: Dockerfile - target: base - environment: - MONGO_INITDB_ROOT_USERNAME: ${DATABASE_USERNAME} - MONGO_INITDB_ROOT_PASSWORD: ${DATABASE_PASSWORD} - ports: - - ${DATABASE_PORT}:${DATABASE_PORT} - expose: - - "${DATABASE_PORT}" - networks: - - docker + openwf: + # build: . + image: ghcr.io/spaceninjaserver/SpaceNinjaServer:latest + environment: + APP_MONGODB_URL: mongodb://openwfagent:spaceninjaserver@mongodb:27017/ -networks: - docker: - external: true + # Following environment variables are set to default image values. + # Uncomment to edit. + + # APP_MY_ADDRESS: localhost + # APP_HTTP_PORT: 80 + # APP_HTTPS_PORT: 443 + # APP_AUTO_CREATE_ACCOUNT: true + # APP_SKIP_STORY_MODE_CHOICE: true + # APP_SKIP_TUTORIAL: true + # APP_SKIP_ALL_DIALOGUE: true + # APP_UNLOCK_ALL_SCANS: true + # APP_UNLOCK_ALL_MISSIONS: true + # APP_UNLOCK_ALL_QUESTS: true + # APP_COMPLETE_ALL_QUESTS: true + # APP_INFINITE_RESOURCES: true + # APP_UNLOCK_ALL_SHIP_FEATURES: true + # APP_UNLOCK_ALL_SHIP_DECORATIONS: true + # APP_UNLOCK_ALL_FLAVOUR_ITEMS: true + # APP_UNLOCK_ALL_SKINS: true + # APP_UNIVERSAL_POLARITY_EVERYWHERE: true + # APP_SPOOF_MASTERY_RANK: -1 + volumes: + - ./docker-data/static:/app/static/data + - ./docker-data/logs:/app/logs + ports: + - 80:80 + - 443:443 + depends_on: + - mongodb + mongodb: + image: docker.io/library/mongo:8.0.0-noble + environment: + MONGO_INITDB_ROOT_USERNAME: openwfagent + MONGO_INITDB_ROOT_PASSWORD: spaceninjaserver + volumes: + - ./docker-data/database:/data/db diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 000000000..f6523d8b9 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,29 @@ +#!/bin/bash +set -e + +# Set up the configuration file using environment variables. +echo '{ + "logger": { + "files": true, + "level": "trace", + "__valid_levels": "fatal, error, warn, info, http, debug, trace" + } +} +' > config.json + +for config in $(env | grep "APP_") +do + var=$(echo "${config}" | tr '[:upper:]' '[:lower:]' | sed 's/app_//g' | sed -E 's/_([a-z])/\U\1/g' | sed 's/=.*//g') + val=$(echo "${config}" | sed 's/.*=//g') + jq --arg variable "$var" --arg value "$val" '.[$variable] += $value' config.json > config.tmp + mv config.tmp config.json +done + +if [ ! -f "/app/static/data/buildConfig.json" ] +then + echo "buildConfig not found, refusing to start." + exit 1 +fi + +npm install +exec npm run dev