From baa7e25e30428dade3a39f62c70864ed996b162f Mon Sep 17 00:00:00 2001 From: Sebastian Di Luzio Date: Sat, 3 May 2025 00:10:09 +0200 Subject: [PATCH] feat: build and release docker images using github actions and container registry (#5807) * feat: build and release docker images using github cicd * fix: attempt to publish to specific image name * fix: typo in pipeline step * typo * typo * limit to certain paths for PRs & naming * ci: configure image title and url * docker: include only necessary files and directories this should make caching more powerful * docker: reorder COPY with best guess of what changes least * build(docker): remove seemingly unnecessary files * fix: clean up docker metadata remove annotations, it seems they're applied from the labels already, add description * fix(ci): add back docker image annotations * Update desktop-build.yml * Update desktop-lint.yml * Update desktop-build.yml * Update docker-release.yml * fix: remove run on master and add affected files to PR trigger * metadata * ci: run pipeline on main this will ensure the container can always build and keep caches ready for release. push should only happen on tag triggers It also removes some files from the PR trigger that should never break the build, and would just invalidate cache. * Update docker-release.yml --------- Co-authored-by: tooomm --- .github/workflows/desktop-build.yml | 1 + .github/workflows/desktop-lint.yml | 1 + .github/workflows/docker-release.yml | 71 ++++++++++++++++++++++++++++ Dockerfile | 6 ++- README.md | 1 - 5 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/docker-release.yml diff --git a/.github/workflows/desktop-build.yml b/.github/workflows/desktop-build.yml index 79bc1b815..4d406c1b6 100644 --- a/.github/workflows/desktop-build.yml +++ b/.github/workflows/desktop-build.yml @@ -9,6 +9,7 @@ on: - 'webclient/**' - '.github/workflows/web-*.yml' - '.github/workflows/translations-*.yml' + - '.github/workflows/docker-release.yml' tags: - '*' pull_request: diff --git a/.github/workflows/desktop-lint.yml b/.github/workflows/desktop-lint.yml index 4ebfd9b79..aee6e81d5 100644 --- a/.github/workflows/desktop-lint.yml +++ b/.github/workflows/desktop-lint.yml @@ -7,6 +7,7 @@ on: - 'webclient/**' - '.github/workflows/web-*.yml' - '.github/workflows/translations-*.yml' + - '.github/workflows/docker-release.yml' jobs: format: diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml new file mode 100644 index 000000000..439ea24cd --- /dev/null +++ b/.github/workflows/docker-release.yml @@ -0,0 +1,71 @@ +name: Build Docker Container + +on: + push: + tags: + - '*Release*' + branches: + - master + pull_request: + branches: + - master + paths: + - '.github/workflows/docker-release.yml' + - 'CMakeLists.txt' + - 'Dockerfile' + - 'servatrice/**' + - 'common/**' + - 'cmake/**' + - '!**.md' + +jobs: + docker: + name: amd64 & arm64 + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Docker metadata + id: metadata + uses: docker/metadata-action@v5 + with: + images: | + ghcr.io/cockatrice/servatrice + labels: | + org.opencontainers.image.title=Servatrice + org.opencontainers.image.url=https://cockatrice.github.io/ + org.opencontainers.image.description=Server for Cockatrice, a cross-platform virtual tabletop for multiplayer card games + annotations: | + org.opencontainers.image.title=Servatrice + org.opencontainers.image.url=https://cockatrice.github.io/ + org.opencontainers.image.description=Server for Cockatrice, a cross-platform virtual tabletop for multiplayer card games + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + if: github.ref_type == 'tag' + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ github.token }} + + - name: Build and push Docker Image + uses: docker/build-push-action@v6 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: ${{ github.ref_type == 'tag' }} + tags: ${{ steps.metadata.outputs.tags }} + labels: ${{ steps.metadata.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile index 330c51b4a..2a0d10eba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,11 @@ RUN apt-get update && apt-get install -y\ qt6-tools-dev \ qt6-tools-dev-tools -COPY . /home/servatrice/code/ +COPY ./CMakeLists.txt ./LICENSE ./README.md /home/servatrice/code/ +COPY ./cmake /home/servatrice/code/cmake +COPY ./common /home/servatrice/code/common +COPY ./servatrice /home/servatrice/code/servatrice + WORKDIR /home/servatrice/code WORKDIR build diff --git a/README.md b/README.md index 0a8058bba..48cacff78 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,6 @@ The following flags (with their non-default values) can be passed to `cmake`: # Run - Cockatrice is the game client
Oracle fetches card data
Servatrice is the server