diff --git a/.github/workflows/build-quesma-docker-image.yml b/.github/workflows/build-quesma-docker-image.yml new file mode 100644 index 000000000..106c8c7e5 --- /dev/null +++ b/.github/workflows/build-quesma-docker-image.yml @@ -0,0 +1,90 @@ +# Reusable workflow that builds Quesma Docker image and either: +# - pushes it to Docker Hub +# - or exports it to .tar artifact + +name: Docker image build +on: + workflow_call: # Can be reused from another workflow + inputs: + VERSION: + description: 'Version number to tag the image with (optional)' + default: nightly + required: false + type: string + PUSH: + description: 'Whether to push the image to the registry (optional)' # if not, we will export it to .tar artifact + default: false + required: false + type: boolean + +jobs: + build-quesma-docker-image: + strategy: + matrix: + module: [ "quesma" ] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + cache-dependency-path: ${{ matrix.module }}/go.sum + go-version: '1.22' + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + if: ${{ inputs.PUSH }} + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PAT }} + + - name: Set the build date + run: echo QUESMA_BUILD_DATE=$(git --no-pager log -1 --date=format:'%Y-%m-%d' --format="%ad") >> $GITHUB_ENV + + # If we don't push the image, we build it only for the host architecture and export it to .tar file + # This step is similar to "Build and push", but avoids building arm64 image, which takes + # a lot of time on GitHub Actions. + - name: Build and export + uses: docker/build-push-action@v6 + if: ${{ !inputs.PUSH }} + with: + context: ${{ matrix.module }}/. + tags: | + quesma/quesma:${{ inputs.VERSION }} + quesma/quesma:nightly + push: false + outputs: type=docker,dest=/tmp/image.tar + cache-from: type=gha + cache-to: type=gha,mode=max + env: + DOCKER_BUILD_SUMMARY: false + + # If we push the image, we build it for both amd64 and arm64 and don't export it + - name: Build and push + uses: docker/build-push-action@v6 + if: ${{ inputs.PUSH }} + with: + context: ${{ matrix.module }}/. + tags: | + quesma/quesma:${{ inputs.VERSION }} + quesma/quesma:nightly + push: true + build-args: | + QUESMA_BUILD_SHA=${{ github.sha }} + QUESMA_VERSION=${{ inputs.VERSION }} + QUESMA_BUILD_DATE=${{ env.QUESMA_BUILD_DATE }} + platforms: linux/amd64,linux/arm64 + env: + DOCKER_BUILD_SUMMARY: false + + - name: Upload artifact + uses: actions/upload-artifact@v4 + if: ${{ !inputs.PUSH }} + with: + name: ${{ matrix.module }} + path: /tmp/image.tar + retention-days: 1 diff --git a/.github/workflows/docker-image-latest.yml b/.github/workflows/docker-image-latest.yml deleted file mode 100644 index 4fe49c0f7..000000000 --- a/.github/workflows/docker-image-latest.yml +++ /dev/null @@ -1,65 +0,0 @@ -name: Docker image build (nightly) -# Pipeline which builds `nightly` Docker images for Quesma -# pushes them to Docker Hub as `quesma/quesma:nightly` (and `quesma/quesma:`, if VERSION is specified explicitly) -# -# This workflow is triggered by a push/merge to the `main` branch -# quesma/quesma:latest image is a pointer to latest released version. - -on: - push: - branches: [ "main" ] - workflow_dispatch: # Handy for testing - inputs: - VERSION: - description: 'Version number to tag the image with (optional)' - default: nightly - required: true - PUSH: - description: 'Whether to push the image to the registry' - default: false - required: true - -jobs: - build-quesma-docker-image: - strategy: - matrix: - module: [ "quesma" ] - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - cache-dependency-path: ${{ matrix.module }}/go.sum - go-version: '1.22' - - - name: Log in to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USER }} - password: ${{ secrets.DOCKER_PAT }} - - - name: Set the build date - run: echo QUESMA_BUILD_DATE=$(git --no-pager log -1 --date=format:'%Y-%m-%d' --format="%ad") >> $GITHUB_ENV - - - name: Build and export - uses: docker/build-push-action@v6 - with: - context: ${{ matrix.module }}/. - # when called from the main branch, `github.event.inputs.VERSION` doesn't use default value and is just empty - tags: | - quesma/quesma:${{ github.event.inputs.VERSION || 'nightly' }} - quesma/quesma:nightly - # Pushes to DockerHub only for `main` branch builds, unless set explicitly in the job input - push: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event.inputs.PUSH }} - build-args: | - QUESMA_BUILD_SHA=${{ github.sha }} - QUESMA_VERSION=${{ github.event.inputs.VERSION }} - QUESMA_BUILD_DATE=${{ env.QUESMA_BUILD_DATE }} - platforms: linux/amd64,linux/arm64 - env: - DOCKER_BUILD_SUMMARY: false diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 8fcbf2e50..413a7a8ae 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -10,43 +10,8 @@ on: # @TODO should we run it on PRs? description: 'Commit hash to run the tests' required: true jobs: - build-quesma-docker-image: - strategy: - matrix: - module: [ "quesma" ] - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: ## @TODO REMOVE - ref: ${{ github.event.inputs.GIT_REF }} - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - cache-dependency-path: ${{ matrix.module }}/go.sum - go-version: '1.22' - - - name: Build and export - uses: docker/build-push-action@v6 - with: - context: ${{ matrix.module }}/. - tags: ${{ matrix.module }}:latest - outputs: type=docker,dest=/tmp/image.tar - cache-from: type=gha - cache-to: type=gha,mode=max - env: - DOCKER_BUILD_SUMMARY: false - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: ${{ matrix.module }} - path: /tmp/image.tar - retention-days: 1 + uses: ./.github/workflows/build-quesma-docker-image.yml e2e-test-run: runs-on: ubuntu-latest diff --git a/.github/workflows/nightly-docker-build-and-push.yml b/.github/workflows/nightly-docker-build-and-push.yml new file mode 100644 index 000000000..e71d24bed --- /dev/null +++ b/.github/workflows/nightly-docker-build-and-push.yml @@ -0,0 +1,28 @@ +name: Docker image build (nightly) +# Pipeline which builds `nightly` Docker images for Quesma +# pushes them to Docker Hub as `quesma/quesma:nightly` (and `quesma/quesma:`, if VERSION is specified explicitly) +# +# This workflow is triggered by a push/merge to the `main` branch +# quesma/quesma:nightly image is a pointer to latest released version. +# +# This workflow is not reusable, use build-quesma-docker-image.yml as a reusable workflow. +on: + push: + branches: [ "main" ] + workflow_dispatch: # Handy for testing + inputs: + VERSION: + description: 'Version number to tag the image with (optional)' + default: nightly + required: true + PUSH: + description: 'Whether to push the image to the registry' + default: false + required: true +jobs: + build-quesma-docker-image: + uses: ./.github/workflows/build-quesma-docker-image.yml + with: + VERSION: ${{ inputs.VERSION || 'nightly' }} # when called from the main branch, `github.event.inputs.VERSION` doesn't use default value and is just empty + # Pushes to DockerHub only for `main` branch builds, unless set explicitly in the job input + PUSH: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || inputs.PUSH }} diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 6eb3bead1..fbffb37c6 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -70,39 +70,7 @@ jobs: run: go run gotest.tools/gotestsum@latest --format pkgname-and-test-fails ./... build-quesma-docker-image: - strategy: - matrix: - module: [ "quesma" ] - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - cache-dependency-path: ${{ matrix.module }}/go.sum - go-version: '1.22' - - - name: Build and export - uses: docker/build-push-action@v6 - with: - context: ${{ matrix.module }}/. - tags: ${{ matrix.module }}:latest - outputs: type=docker,dest=/tmp/image.tar - cache-from: type=gha - cache-to: type=gha,mode=max - env: - DOCKER_BUILD_SUMMARY: false - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: ${{ matrix.module }} - path: /tmp/image.tar - retention-days: 1 + uses: ./.github/workflows/build-quesma-docker-image.yml build-log-generator: strategy: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index af6f68f21..5a396e834 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,7 +13,7 @@ permissions: contents: write # To be able to create a release via GitHub API jobs: - build-quesma-docker-image: + build-quesma-docker-image: # based on nightly-docker-build-and-push.yml, but heavily modified strategy: matrix: module: [ "quesma" ]