feat: create Docker image, set up Docker CI (#528)

This commit is contained in:
sw5ciprl 2024-10-10 23:07:37 +03:00 committed by GitHub
parent d9c95e676d
commit 533c249e68
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 131 additions and 31 deletions

5
.dockerignore Normal file
View File

@ -0,0 +1,5 @@
**/.dockerignore
**/.git
Dockerfile*
.*
docker-data/

View File

@ -1,4 +0,0 @@
# Docker may need a .env file for the following settings:
DATABASE_PORT=27017
DATABASE_USERNAME=root
DATABASE_PASSWORD=database

25
.github/workflows/docker.yml vendored Normal file
View File

@ -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 }}

3
.gitignore vendored
View File

@ -16,3 +16,6 @@ yarn.lock
# MongoDB VSCode extension playground scripts
/database_scripts
# Default Docker directory
/docker-data

View File

@ -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"]
RUN apk add --no-cache bash sed wget jq
COPY . /app
WORKDIR /app
ENTRYPOINT ["/app/docker-entrypoint.sh"]

View File

@ -1,24 +1,43 @@
version: "3.9"
services:
mongodb:
container_name: mongodb
image: mongodb
restart: always
build:
context: .
dockerfile: Dockerfile
target: base
openwf:
# build: .
image: ghcr.io/spaceninjaserver/SpaceNinjaServer:latest
environment:
MONGO_INITDB_ROOT_USERNAME: ${DATABASE_USERNAME}
MONGO_INITDB_ROOT_PASSWORD: ${DATABASE_PASSWORD}
ports:
- ${DATABASE_PORT}:${DATABASE_PORT}
expose:
- "${DATABASE_PORT}"
networks:
- docker
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

29
docker-entrypoint.sh Executable file
View File

@ -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