From 4c8f3dd8705095afca0ff409a059074d9b43148c Mon Sep 17 00:00:00 2001 From: Jonas Holst Damtoft Date: Thu, 15 Feb 2024 13:46:49 +0100 Subject: [PATCH] chore: deploy to ghcr.io instead --- .github/workflows/build.yml | 28 ++++++++ .../{build-and-push.yml => deploy-image.yml} | 68 +++++++++---------- .github/workflows/release-drafter.yml | 2 + docker-compose.yml | 2 +- 4 files changed, 65 insertions(+), 35 deletions(-) create mode 100644 .github/workflows/build.yml rename .github/workflows/{build-and-push.yml => deploy-image.yml} (52%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..eb785df --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,28 @@ +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@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + build-args: | + NODE_VERSION=${{ matrix.node }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/deploy-image.yml similarity index 52% rename from .github/workflows/build-and-push.yml rename to .github/workflows/deploy-image.yml index fc0b87c..283705f 100644 --- a/.github/workflows/build-and-push.yml +++ b/.github/workflows/deploy-image.yml @@ -1,62 +1,62 @@ -name: Build and push to Docker Hub +name: Deploy Images to GHCR -on: - workflow_dispatch: +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} +on: push: - paths: - - "Dockerfile" - - "screeps-cli.js" - - "screeps-start.js" - - "package-lock.json" - tags: - - "v*.*.*" - branches: - - "main" - pull_request: branches: - - "main" + - main + tags: + - "v*" + release: + types: + - published + + workflow_dispatch: jobs: - release: + push-image: runs-on: ubuntu-latest strategy: matrix: node: [10, 12] + permissions: + contents: read + packages: write steps: - - name: Checkout + - name: "Checkout GitHub Action" uses: actions/checkout@v4 - - name: Docker meta + - name: Log in to the Container registry + uses: docker/login-action@3d58c274f17dffee475a5520cbe67f0a882c4dbb + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Extract metadata (tags, labels) for Docker id: meta - uses: docker/metadata-action@v4 - if: ${{ github.event_name != 'pull_request' }} + uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} github-token: ${{ github.token }} flavor: | latest=auto suffix=${{ matrix.node != 10 && format('-node{0}', matrix.node) || '' }},onlatest=true - images: | - ${{ secrets.DOCKER_HUB_USERNAME }}/screeps-server tags: | type=edge,branch=main type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }} type=sha - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Login to DockerHub - uses: docker/login-action@v3 - if: ${{ github.event_name != 'pull_request' }} - with: - username: ${{ secrets.DOCKER_HUB_USERNAME }} - password: ${{ secrets.DOCKER_HUB_TOKEN }} - - name: Build and push - uses: docker/build-push-action@v5 + - name: Build and push Docker image + uses: docker/build-push-action@4976231911ebf5f32aad765192d35f942aa48cb8 with: context: . - push: ${{ github.event_name != 'pull_request' }} + push: true build-args: | NODE_VERSION=${{ matrix.node }} - cache-from: type=gha - cache-to: type=gha,mode=max tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 8e16707..e987131 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -22,5 +22,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: release-drafter/release-drafter@v5 + with: + publish: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/docker-compose.yml b/docker-compose.yml index 3e76fa3..c3e5304 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: "3" services: screeps: platform: linux/x86_64 - image: jomik/screeps-server:edge + image: ghcr.io/jomik/screeps-server:edge depends_on: - mongo - redis