From 748813bc050567a36f5e33af658c9a6e29595311 Mon Sep 17 00:00:00 2001 From: sw5ciprl <51961935+sw5ciprl@users.noreply.github.com> Date: Thu, 10 Oct 2024 19:20:30 +0300 Subject: [PATCH 1/7] feat: add Docker image, Compose file and image CI --- .dockerignore | 4 +++ .env.example | 4 --- .github/workflows/build.yml | 20 ++++++++++++ .gitignore | 6 +++- Dockerfile | 29 +++++++++++++++-- docker-compose.yml | 62 ++++++++++++++++++++++++------------- docker-entrypoint.sh | 29 +++++++++++++++++ 7 files changed, 124 insertions(+), 30 deletions(-) create mode 100644 .dockerignore delete mode 100644 .env.example create mode 100755 docker-entrypoint.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..3a396c8c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +**/.dockerignore +**/.git +Dockerfile* +.* diff --git a/.env.example b/.env.example deleted file mode 100644 index 1a455025..00000000 --- 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 3aa07742..dc21492f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,3 +20,23 @@ jobs: - run: echo '{"version":"","buildLabel":"","matchmakingBuildId":""}' > static/data/buildConfig.json - run: npm run build - run: npm run lint + docker: + runs-on: ubuntu-latest + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + 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/${{ github.repository }}:latest + ghcr.io/${{ github.repository}}:${{ github.sha }} diff --git a/.gitignore b/.gitignore index d1ec7373..26f6f920 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,8 @@ yarn.lock /logs # MongoDB VSCode extension playground scripts -/database_scripts \ No newline at end of file +/database_scripts + +# Default Docker directories +/static-data +/database diff --git a/Dockerfile b/Dockerfile index c218511b..f265957f 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 085c452e..b92f9c96 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,24 +1,42 @@ -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: + - ./static-data:/app/static/data + 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: + - ./database:/app/static/data diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 00000000..f6523d8b --- /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 -- 2.47.2 From c954ccd9b6c6aef1ad3c135d0a05fc47329b9585 Mon Sep 17 00:00:00 2001 From: sw5ciprl <51961935+sw5ciprl@users.noreply.github.com> Date: Thu, 10 Oct 2024 21:27:50 +0300 Subject: [PATCH 2/7] chore: fix data volumes in Compose file --- .dockerignore | 1 + .gitignore | 5 ++--- docker-compose.yml | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.dockerignore b/.dockerignore index 3a396c8c..bb49c7dc 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,3 +2,4 @@ **/.git Dockerfile* .* +data/ \ No newline at end of file diff --git a/.gitignore b/.gitignore index 26f6f920..bfa19b8b 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,5 @@ yarn.lock # MongoDB VSCode extension playground scripts /database_scripts -# Default Docker directories -/static-data -/database +# Default Docker directory +/data diff --git a/docker-compose.yml b/docker-compose.yml index b92f9c96..2628f6d2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,7 +27,8 @@ services: # APP_UNIVERSAL_POLARITY_EVERYWHERE: true # APP_SPOOF_MASTERY_RANK: -1 volumes: - - ./static-data:/app/static/data + - ./data/static:/app/static/data + - ./data/logs:/app/logs ports: - 80:80 - 443:443 @@ -39,4 +40,4 @@ services: MONGO_INITDB_ROOT_USERNAME: openwfagent MONGO_INITDB_ROOT_PASSWORD: spaceninjaserver volumes: - - ./database:/app/static/data + - ./data/database:/data/db \ No newline at end of file -- 2.47.2 From 1818c26a714fad0dfa760b67f5fac027e2089d62 Mon Sep 17 00:00:00 2001 From: sw5ciprl <51961935+sw5ciprl@users.noreply.github.com> Date: Thu, 10 Oct 2024 22:36:55 +0300 Subject: [PATCH 3/7] chore: separate Docker build workflow --- .github/workflows/build.yml | 22 +--------------------- .github/workflows/docker.yml | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dc21492f..69418993 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,24 +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 - docker: - runs-on: ubuntu-latest - if: github.event_name == 'push' && github.ref == 'refs/heads/main' - 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/${{ github.repository }}:latest - ghcr.io/${{ github.repository}}:${{ github.sha }} + - 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 00000000..e4e0ebd4 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,26 @@ +name: Build Docker image +on: + push: + branches: + - main + pull_request: {} +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/${{ github.repository }}:latest + ghcr.io/${{ github.repository}}:${{ github.sha }} -- 2.47.2 From 3401d185e8005b3a041f6c8419dd52da22050898 Mon Sep 17 00:00:00 2001 From: sw5ciprl <51961935+sw5ciprl@users.noreply.github.com> Date: Thu, 10 Oct 2024 22:39:22 +0300 Subject: [PATCH 4/7] chore: sanitize repository name --- .github/workflows/docker.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index e4e0ebd4..803e6782 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -3,7 +3,6 @@ on: push: branches: - main - pull_request: {} jobs: docker: runs-on: ubuntu-latest @@ -22,5 +21,5 @@ jobs: platforms: linux/amd64,linux/arm64 push: true tags: | - ghcr.io/${{ github.repository }}:latest - ghcr.io/${{ github.repository}}:${{ github.sha }} + ghcr.io/spaceninjaserver/spaceninjaserver:latest + ghcr.io/spaceninjaserver/spaceninjaserver:${{ github.sha }} -- 2.47.2 From 4d7bf6de3bae43df8f2e94b7bdead0433c68a777 Mon Sep 17 00:00:00 2001 From: sw5ciprl <51961935+sw5ciprl@users.noreply.github.com> Date: Thu, 10 Oct 2024 22:57:25 +0300 Subject: [PATCH 5/7] chore: rename in gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index bfa19b8b..2661a52a 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,4 @@ yarn.lock /database_scripts # Default Docker directory -/data +/docker-data -- 2.47.2 From ef4da5f2d1ca746f47091daeff13c8854f9071db Mon Sep 17 00:00:00 2001 From: sw5ciprl <51961935+sw5ciprl@users.noreply.github.com> Date: Thu, 10 Oct 2024 22:58:24 +0300 Subject: [PATCH 6/7] chore: update Compose --- docker-compose.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 2628f6d2..5882ad5d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,8 +27,8 @@ services: # APP_UNIVERSAL_POLARITY_EVERYWHERE: true # APP_SPOOF_MASTERY_RANK: -1 volumes: - - ./data/static:/app/static/data - - ./data/logs:/app/logs + - ./docker-data/static:/app/static/data + - ./docker-data/logs:/app/logs ports: - 80:80 - 443:443 @@ -40,4 +40,4 @@ services: MONGO_INITDB_ROOT_USERNAME: openwfagent MONGO_INITDB_ROOT_PASSWORD: spaceninjaserver volumes: - - ./data/database:/data/db \ No newline at end of file + - ./docker-data/database:/data/db -- 2.47.2 From 367e3eff6f1d3815158d18154e0a5d586c19de43 Mon Sep 17 00:00:00 2001 From: sw5ciprl <51961935+sw5ciprl@users.noreply.github.com> Date: Thu, 10 Oct 2024 22:59:00 +0300 Subject: [PATCH 7/7] chore: update in dockerignore --- .dockerignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index bb49c7dc..ca89b6ae 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,4 +2,4 @@ **/.git Dockerfile* .* -data/ \ No newline at end of file +docker-data/ -- 2.47.2