Build docker images #4399
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build docker images | |
| on: | |
| workflow_dispatch: | |
| push: | |
| paths: | |
| - 'Dockerfile' | |
| - '.github/workflows/publish_images.yml' | |
| schedule: | |
| - cron: '0 * * * *' | |
| permissions: | |
| contents: read | |
| packages: write | |
| env: | |
| DOCKER_IMAGE: brammys/necesse-server | |
| jobs: | |
| build: | |
| name: Build latest Necesse server | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| steps: | |
| - name: Check out the repo | |
| uses: actions/checkout@v6 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v4 | |
| with: | |
| platforms: arm64 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Scrape latest download info | |
| id: scrape | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| page=$(curl -s https://necessegame.com/server/) | |
| rel=$(echo "$page" | grep -Eo 'content/server/[0-9]+(-[0-9]+)+/necesse-server-linux64-[0-9]+(-[0-9]+)+\.zip' | head -n 1 || true) | |
| if [[ -z "${rel}" ]]; then | |
| echo "Could not find server download URL on necessegame.com/server/" | |
| exit 1 | |
| fi | |
| url="https://necessegame.com/${rel}" | |
| fname=$(basename "$url") | |
| # Strip prefix and suffix to get version-build, e.g. 1-0-1-20436084 | |
| vb=${fname#necesse-server-linux64-} | |
| vb=${vb%.zip} | |
| version=$(echo "$vb" | grep -Eo '^[0-9]{1,2}-[0-9]{1,2}-[0-9]{1,2}') | |
| build=$(echo "$vb" | grep -Eo '[0-9]+$') | |
| echo "Found: url=$url, version=$version, build=$build" | |
| echo "url=$url" >> "$GITHUB_OUTPUT" | |
| echo "version=$version" >> "$GITHUB_OUTPUT" | |
| echo "build=$build" >> "$GITHUB_OUTPUT" | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v4 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Check if image already exists | |
| id: check | |
| shell: bash | |
| env: | |
| VERSION: ${{ steps.scrape.outputs.version }} | |
| BUILD: ${{ steps.scrape.outputs.build }} | |
| run: | | |
| set -euo pipefail | |
| TAG="${VERSION}-${BUILD}" | |
| if ! docker manifest inspect "${{ env.DOCKER_IMAGE }}:${TAG}" >/tmp/manifest.json 2>/dev/null; then | |
| echo "Tag not found; will build." | |
| echo "should_build=true" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| if grep -q '"architecture":\s*"arm64"' /tmp/manifest.json && grep -q '"architecture":\s*"amd64"' /tmp/manifest.json; then | |
| echo "Both amd64 and arm64 already present — skipping build." | |
| echo "should_build=false" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "Multi-arch not complete (will build/push for missing arch)." | |
| echo "should_build=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Docker meta | |
| id: meta | |
| uses: docker/metadata-action@v6 | |
| if: steps.check.outputs.should_build == 'true' | |
| with: | |
| images: | | |
| ${{ env.DOCKER_IMAGE }} | |
| ghcr.io/${{ github.repository_owner }}/necesse-server | |
| tags: | | |
| type=raw,value=latest | |
| type=raw,value=${{ steps.scrape.outputs.version }} | |
| type=raw,value=${{ steps.scrape.outputs.version }}-${{ steps.scrape.outputs.build }} | |
| - name: Build and push images (Docker Hub + GHCR) | |
| uses: docker/build-push-action@v7 | |
| if: steps.check.outputs.should_build == 'true' | |
| with: | |
| push: true | |
| platforms: linux/amd64,linux/arm64 | |
| context: . | |
| file: ./Dockerfile | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| build-args: | | |
| url=${{ steps.scrape.outputs.url }} | |
| version=${{ steps.scrape.outputs.version }} | |
| build=${{ steps.scrape.outputs.build }} | |
| - name: Done (no build necessary) | |
| if: steps.check.outputs.should_build != 'true' | |
| run: echo "Already up to date; no new server release detected." |