diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 87340cf..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Build docker image - -on: - workflow_dispatch: - - pull_request: - branches: - - "main" - -jobs: - release: - runs-on: ubuntu-latest - strategy: - matrix: - node: [10, 12] - steps: - - name: Checkout - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3 - - name: Build and push - uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5 - with: - context: . - build-args: | - NODE_VERSION=${{ matrix.node }} - cache-from: type=gha - cache-to: type=gha,mode=max diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..d96c6b9 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,65 @@ +name: Test server image + +on: + workflow_dispatch: + + pull_request: + branches: + - "main" + +env: + TEST_TAG: jomik/screeps-server:test + +jobs: + release: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node: [10, 12] + steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3 + - name: Build + uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5 + with: + context: . + build-args: | + NODE_VERSION=${{ matrix.node }} + cache-from: type=gha + cache-to: type=gha,mode=max + tags: ${{ env.TEST_TAG }} + load: true + - name: Start the container + run: | + docker run --rm -di -p 21025:21025 -p 21028:21028 --env STEAM_KEY --name screeps -v ${CONFIG_FILE}:/screeps/config.yml ${TEST_TAG} + env: + STEAM_KEY: ${{ secrets.STEAM_KEY }} + CONFIG_FILE: ${{ format('{0}/{1}', github.workspace, 'test-config.yml') }} + - name: Wait for container to be healthy + uses: stringbean/docker-healthcheck-action@v3 + with: + container: screeps + wait-time: 600 + require-status: running + require-healthy: true + - name: Show container logs + if: always() + run: docker container logs screeps + - name: Check that mods are registered + run: | + set -eu + server_data=$(curl http://localhost:21025/api/version | jq -c '.serverData') + echo $server_data | jq -e '.features | any(.name == "screepsmod-auth")' + echo $server_data | jq -e '.features | any(.name == "screepsmod-admin-utils")' + echo $server_data | jq -e '.features | any(.name == "screepsmod-cli")' + - name: Check that bots are registered + run: | + set -eu + bots=$(curl -X POST http://localhost:21028/cli -d "help(bots)" | grep -A 10 "Bot AIs:") + echo $bots | grep 'simplebot' | grep "screepsbot-zeswarm" + - name: Stop container + if: always() + run: docker container stop screeps diff --git a/Dockerfile b/Dockerfile index e42c132..fc2e372 100644 --- a/Dockerfile +++ b/Dockerfile @@ -50,6 +50,6 @@ VOLUME [ "/data" ] EXPOSE 21025 HEALTHCHECK --start-period=5m --interval=5m --timeout=3s \ - CMD wget --no-verbose --tries=1 --spider http://localhost:21025/ || exit 1 + CMD wget --no-verbose --tries=1 --spider http://localhost:21025/api/version || exit 1 ENTRYPOINT ["start"] diff --git a/config.yml b/config.yml index 9d3d967..bae38e3 100644 --- a/config.yml +++ b/config.yml @@ -5,6 +5,6 @@ mods: bots: simplebot: screepsbot-zeswarm -serverOptions: +launcherOptions: # If set, forward console messages to terminal logConsole: false diff --git a/package.json b/package.json index e424b70..9f54de4 100644 --- a/package.json +++ b/package.json @@ -15,9 +15,6 @@ "js-yaml": "4.1.0" }, "scripts": { - "bootstrap": "mkdir -p server/mods && cd server && cp -a ../node_modules/@screeps/launcher/init_dist/{.screepsrc,db.json,assets} ./ && cd mods && npm init -y", - "clean": "rm -r server && yarn bootstrap", - "start": "CONFIG_FILE=../config.yml SERVER_DIR=./server/ ./screeps-start.js", "cli": "docker compose exec screeps cli" } } diff --git a/screeps-start.js b/screeps-start.js index d023b8b..b7ccc62 100755 --- a/screeps-start.js +++ b/screeps-start.js @@ -8,10 +8,9 @@ const RootDir = process.env["SERVER_DIR"]; if (!RootDir) { throw new Error("Missing environment variable $SERVER_DIR"); } -const ConfigPath = process.env["CONFIG_FILE"] || "./config.yml"; - process.chdir(RootDir); +const ConfigPath = path.join(RootDir, "config.yml"); const config = yaml.load(fs.readFileSync(ConfigPath, "utf8")); const loadPackage = (dir) => diff --git a/test-config.yml b/test-config.yml new file mode 100644 index 0000000..14e3394 --- /dev/null +++ b/test-config.yml @@ -0,0 +1,14 @@ +mods: + - screepsmod-auth + - screepsmod-admin-utils + - screepsmod-cli +bots: + simplebot: screepsbot-zeswarm + +cli: + host: 0.0.0.0 + port: 21028 + +launcherOptions: + runnerThreads: 1 + processorCount: 1