From b3a007c1e7473c463d8614c32d1a0c249ed5aecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=BCdi=20Tam=C3=A1s?= Date: Thu, 26 Sep 2024 18:31:03 +0200 Subject: [PATCH] Refactor Docker image building workflow and action --- .github/workflows/self-images-worker.yml | 26 ---------------- .github/workflows/self-prod.yml | 39 ++++++++++++++++++++++++ actions/infra-build-images/action.yml | 3 +- 3 files changed, 40 insertions(+), 28 deletions(-) delete mode 100644 .github/workflows/self-images-worker.yml create mode 100644 .github/workflows/self-prod.yml diff --git a/.github/workflows/self-images-worker.yml b/.github/workflows/self-images-worker.yml deleted file mode 100644 index 3ad737c..0000000 --- a/.github/workflows/self-images-worker.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Automation Images - Worker - -on: - workflow_call: - inputs: - environment: - required: true - type: "string" - -jobs: - build-and-push: - environment: ${{ inputs.environment }} - env: - DOCKER_TAG: ${{ inputs.environment == 'production' && 'latest' || (inputs.environment == 'staging' && 'edge' || github.sha )}} - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - uses: docker/setup-buildx-action@v3 - - - run: | - ./scripts/build-docker-actions.sh \ - ghcr.io/${{ github.repository_owner }}/infra \ - ${{ env.DOCKER_TAG }} \ - '--push --cache-from type=gha,mode=max --cache-to type=gha,mode=max --label org.opencontainers.image.source=https://github.com/${{ github.repository }}' diff --git a/.github/workflows/self-prod.yml b/.github/workflows/self-prod.yml new file mode 100644 index 0000000..e95b1c9 --- /dev/null +++ b/.github/workflows/self-prod.yml @@ -0,0 +1,39 @@ +name: Deployment workflow + +on: + push: + branches: + - main + workflow_call: + +jobs: + staging: + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + + strategy: + matrix: + environment: + - staging + - production + max-parallel: 1 + + environment: ${{ matrix.environment }} + + env: + DOCKER_TAG: ${{ matrix.environment == 'production' && 'latest' || 'edge' }} + DOCKER_REGISTRY: ghcr.io + DOCKER_NAMESPACE: ${{ github.repository_owner }} + DOCKER_EXTRA_ARGS: --label org.opencontainers.image.source=https://github.com/${{ github.repository }} --cache-from type=gha,mode=max --cache-to type=gha,mode=max + + steps: + - uses: actions/checkout@v4 + - uses: kir-dev/automations/actions/infra-build-images@feat/build-docker-actions + with: + registry: ${{ env.DOCKER_NAMESPACE }} + namespace: ${{ env.DOCKER_NAMESPACE }} + docker-tag: ${{ env.DOCKER_TAG }} + extra-args: --push ${{ env.DOCKER_EXTRA_ARGS }} diff --git a/actions/infra-build-images/action.yml b/actions/infra-build-images/action.yml index b69a810..ddb5fb1 100644 --- a/actions/infra-build-images/action.yml +++ b/actions/infra-build-images/action.yml @@ -3,7 +3,6 @@ description: Automation Images Manager Action inputs: registry: required: true - default: 'ghcr.io' description: 'The docker registry to use' namespace: required: true @@ -27,4 +26,4 @@ runs: ${{ inputs.command_path }}/build-docker-actions.sh \ ${{ inputs.registry }}/${{ inputs.namespace }} \ ${{ inputs.docker-tag }} \ - '--push --cache-from type=gha,mode=max --cache-to type=gha,mode=max --label org.opencontainers.image.source=https://github.com/${{ github.repository }}' + '${{ inputs.extra-args }}'