From 4908b5b17c1000bee0b8e399783b7c9f52d988f6 Mon Sep 17 00:00:00 2001 From: Alex Graf Date: Wed, 27 Mar 2024 13:31:58 +0100 Subject: [PATCH] update dev-deploy action --- .github/actions/create-image/action.yaml | 61 ++++++++++++++++++++++++ .github/workflows/ci.yml | 2 +- .github/workflows/codeql.yml | 2 +- .github/workflows/dev-deploy.yml | 41 ++++++++++++++++ .github/workflows/pre-release.yml | 13 ++--- .github/workflows/release.yml | 2 +- 6 files changed, 110 insertions(+), 11 deletions(-) create mode 100644 .github/actions/create-image/action.yaml create mode 100644 .github/workflows/dev-deploy.yml diff --git a/.github/actions/create-image/action.yaml b/.github/actions/create-image/action.yaml new file mode 100644 index 00000000..4a106270 --- /dev/null +++ b/.github/actions/create-image/action.yaml @@ -0,0 +1,61 @@ +name: 'create docker image' +description: 'Builds a docker image and tags it' +inputs: + - name: 'IMAGE_NAME' + description: 'The image name' + required: true + - name: 'VERSION' + description: 'The version of the image' + required: true + - name: 'TAG' + description: 'The tag of the image' + required: true + - name: 'DOCKERFILE' + description: 'The path to the Dockerfile' + required: true +runs: + using: 'composite' + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set environment variables + run: | + echo COMMITED_AT=$(git show -s --format=%cI `git rev-parse HEAD`) >> $GITHUB_ENV + echo REVISION=$(git rev-parse --short HEAD) >> $GITHUB_ENV + + - name: Collect docker image metadata + id: meta-data + uses: docker/metadata-action@v5 + with: + images: ${{ inputs.IMAGE_NAME }} + labels: | + org.opencontainers.image.created=${{ env.COMMITED_AT }} + org.opencontainers.image.version=${{ inputs.VERSION }} + org.opencontainers.image.maintainer=EBP Schweiz AG + flavor: | + latest=false + tags: | + type=${{ inputs.TAG }} + type=semver,pattern={{version}},value=${{ inputs.VERSION }} + + - name: Log in to the GitHub container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: ./ + file: ${{ inputs.DOCKERFILE }} + push: true + build-args: | + VERSION=${{ inputs.VERSION }} + REVISION=${{ env.REVISION }} + tags: ${{ steps.meta-data.outputs.tags }} + labels: ${{ steps.meta-data.outputs.labels }} + cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:${{ inputs.TAG }} + cache-to: type=inline diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1586bfab..5503ea8e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: CI +name: ci on: push: diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 9cb1fc1d..6c1998ab 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -1,4 +1,4 @@ -name: "CodeQL" +name: code-ql on: push: diff --git a/.github/workflows/dev-deploy.yml b/.github/workflows/dev-deploy.yml new file mode 100644 index 00000000..88c9a1bd --- /dev/null +++ b/.github/workflows/dev-deploy.yml @@ -0,0 +1,41 @@ +name: dev-deploy + +on: + push: + branches: + - develop + workflow_dispatch: + +env: + REGISTRY: ghcr.io + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BASE_IMAGE_NAME: ghcr.io/geoadmin/swissgeol-assets + +jobs: + build-push-docker-images: + runs-on: ubuntu-latest + name: Build and push docker images + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Define version + run: | + echo VERSION=$(cat VERSION).$GITHUB_RUN_NUMBER >> $GITHUB_ENV + + - name: Build and push docker image (app) + uses: ./.github/actions/create-image + with: + IMAGE_NAME: ${{ env.BASE_IMAGE_NAME }}-app + VERSION: ${{ env.VERSION }} + TAG: edge + DOCKERFILE: ./apps/client-asset-sg/docker/Dockerfile + + - name: Build and push docker image (api) + uses: ./.github/actions/create-image + with: + IMAGE_NAME: ${{ env.BASE_IMAGE_NAME }}-api + VERSION: ${{ env.VERSION }} + TAG: edge + DOCKERFILE: ./apps/server-asset-sg/docker/Dockerfile \ No newline at end of file diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml index ee8f2d47..d14846a3 100644 --- a/.github/workflows/pre-release.yml +++ b/.github/workflows/pre-release.yml @@ -1,9 +1,6 @@ -name: Pre-release +name: pre-release on: - # push: - # branches: - # - develop workflow_dispatch: env: @@ -38,7 +35,7 @@ jobs: flavor: | latest=false tags: | - type=edge + type=rc type=semver,pattern={{version}},value=${{ env.VERSION }} - name: Collect Docker image metadata (api) @@ -53,7 +50,7 @@ jobs: flavor: | latest=false tags: | - type=edge + type=rc type=semver,pattern={{version}},value=${{ env.VERSION }} - name: Log in to the GitHub container registry @@ -74,7 +71,7 @@ jobs: REVISION=${{ env.REVISION }} tags: ${{ steps.meta-app.outputs.tags }} labels: ${{ steps.meta-app.outputs.labels }} - cache-from: type=registry,ref=${{ env.BASE_IMAGE_NAME }}-app:edge + cache-from: type=registry,ref=${{ env.BASE_IMAGE_NAME }}-app:rc cache-to: type=inline - name: Build and push Docker image (api) @@ -88,7 +85,7 @@ jobs: REVISION=${{ env.REVISION }} tags: ${{ steps.meta-api.outputs.tags }} labels: ${{ steps.meta-api.outputs.labels }} - cache-from: type=registry,ref=${{ env.BASE_IMAGE_NAME }}-api:edge + cache-from: type=registry,ref=${{ env.BASE_IMAGE_NAME }}-api:rc cache-to: type=inline - name: Create pre-elease diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c40db2cd..368c9d15 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Release +name: release on: release: