Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reusable build docker action #10017

Merged
merged 3 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
105 changes: 105 additions & 0 deletions .github/actions/build-docker/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# This action expects the code to have been checked out beforehand, e.g. via actions/checkout@v3
# It will set up Java and maven as dependencies. If requested to package Zeebe, it will also set up
# Go, build zbctl, then build the Zeebe distribution.
#
# If no version is given, the version is set to the Maven project version.
#
# This action does NOT work on self-hosted runners unless they have buildx already set up. See
npepinpe marked this conversation as resolved.
Show resolved Hide resolved
# https://github.com/docker/setup-buildx-action for more

---
name: Build Docker Image
description: Builds the Zeebe Docker image

inputs:
repository:
description: 'The image repository, e.g. camunda/zeebe'
default: 'camunda/zeebe'
required: true
version:
description: 'The image version, e.g. SNAPSHOT, 8.1.0'
required: false
package:
description: 'If true, will package Zeebe, otherwise uses the tar-ball under dist/target'
default: 'false'
required: false
push:
description: 'If true, will push the image'
required: false
default: 'false'

outputs:
image:
description: "Fully qualified image name available in your local Docker daemon"
value: ${{ steps.get-image.outputs.result }}
date:
description: "The ISO 8601 date at which the image was created"
value: ${{ steps.get-date.outputs.result }}
version:
description: "The semantic version of the packaged artifact"
value: ${{ steps.get-version.outputs.result }}

runs:
using: composite
steps:
# Creating a context is required when installing buildx on self-hosted runners
- name: Create context
shell: bash
run: |
docker context create zeebe-context
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
# to be able to push to local registry, which we use in our tests, we need to use host network
driver-opts: network=host
endpoint: zeebe-context
install: true
# We need maven and Java (indirectly) to get properties from the project
- uses: actions/setup-java@v3.4.1
with:
distribution: 'temurin'
java-version: '17'
- uses: stCarolas/setup-maven@v4.4
with:
maven-version: 3.8.5
- if: ${{ inputs.package == 'true' }}
uses: actions/setup-go@v3
with:
go-version-file: 'clients/go/go.mod'
cache: true
cache-dependency-path: 'clients/go/go.sum'
- if: ${{ inputs.package == 'true' }}
name: Build Go
shell: bash
run: ./build.sh
working-directory: clients/go/cmd/zbctl
- if: ${{ inputs.package == 'true' }}
name: Package Zeebe
shell: bash
run: mvn -B -DskipTests -DskipChecks package -T1C
- name: Set semantic version from Maven project
id: get-version
shell: bash
run: echo ::set-output name=result::$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
- name: Set image build label from ISO 8601 DATE
id: get-date
shell: bash
run: echo "::set-output name=result::$(date --iso-8601=seconds)"
- name: Set image name from params or project version
id: get-image
shell: bash
run: echo "::set-output name=result::${{ inputs.repository }}:${{ inputs.version || steps.get-version.outputs.result }}"
- name: Build Docker image
uses: docker/build-push-action@v3
with:
context: .
tags: ${{ steps.get-image.outputs.result }}
load: ${{ inputs.push != 'true' }}
npepinpe marked this conversation as resolved.
Show resolved Hide resolved
push: ${{ inputs.push }}
no-cache: true
build-args: |
DISTBALL=dist/target/camunda-zeebe-${{ steps.get-version.outputs.result }}.tar.gz
DATE=${{ steps.get-date.outputs.result }}
REVISION=${{ github.sha }}
VERSION=${{ steps.get-version.outputs.result }}
target: app
39 changes: 8 additions & 31 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,38 +95,15 @@ jobs:
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: ./hadolint.sarif
- uses: actions/setup-java@v3.4.1
with:
distribution: 'temurin'
java-version: '17'
- uses: stCarolas/setup-maven@v4.4
with:
maven-version: 3.8.5
- name: Package Zeebe
run: mvn -B -DskipTests -DskipChecks package -T1C
- name: Set project version
run: echo ::set-output name=result::$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
id: get-version
- name: Get build timestamp
id: get-date
run: echo "::set-output name=result::$(date --iso-8601=seconds)"
- name: Build Docker image
uses: docker/build-push-action@v3
- uses: ./.github/actions/build-docker
id: build-docker
with:
context: .
# give it a fake registry to make sure we don't accidentally push it
tags: localhost:5000/camunda/zeebe:${{ steps.get-version.outputs.result }}
load: true
no-cache: true
build-args: |
DISTBALL=dist/target/camunda-zeebe-${{ steps.get-version.outputs.result }}.tar.gz
DATE=${{ steps.get-date.outputs.result }}
REVISION=${{ github.sha }}
VERSION=${{ steps.get-version.outputs.result }}
target: app
# give it a fake name to ensure we never try pushing it
repository: localhost:5000/camunda/zeebe
package: true
- name: Verify Docker image
env:
DATE: ${{ steps.get-date.outputs.result }}
DATE: ${{ steps.build-docker.outputs.date }}
REVISION: ${{ github.sha }}
VERSION: ${{ steps.get-version.outputs.result }}
run: ${PWD}/docker/test/verify.sh 'localhost:5000/camunda/zeebe:${{ steps.get-version.outputs.result }}'
VERSION: ${{ steps.build-docker.outputs.version }}
run: ${PWD}/docker/test/verify.sh '${{ steps.build-docker.outputs.image }}'
36 changes: 5 additions & 31 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,44 +64,18 @@ jobs:
secrets: |
secret/data/products/zeebe/ci/zeebe REGISTRY_HUB_DOCKER_COM_USR;
secret/data/products/zeebe/ci/zeebe REGISTRY_HUB_DOCKER_COM_PSW;
- uses: actions/setup-java@v3.4.1
with:
distribution: 'temurin'
java-version: '17'
- uses: actions/setup-go@v3
with:
go-version-file: 'clients/go/go.mod'
cache: true
cache-dependency-path: 'clients/go/go.sum'
- name: Build Go
run: ./build.sh
working-directory: clients/go/cmd/zbctl
- name: Package Zeebe
run: mvn -B -DskipTests -DskipChecks package -T1C
- name: Set project version
run: echo ::set-output name=result::$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
id: get-version
- name: Get build timestamp
id: get-date
run: echo "::set-output name=result::$(date --iso-8601=seconds)"
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ steps.secrets.outputs.REGISTRY_HUB_DOCKER_COM_USR }}
password: ${{ steps.secrets.outputs.REGISTRY_HUB_DOCKER_COM_PSW }}
- name: Build and push Docker image
uses: docker/build-push-action@v3
- uses: ./.github/actions/build-docker
id: build-docker
with:
context: .
tags: camunda/zeebe:SNAPSHOT
repository: camunda/zeebe
version: SNAPSHOT
package: true
push: true
no-cache: true
build-args: |
DISTBALL=dist/target/camunda-zeebe-${{ steps.get-version.outputs.result }}.tar.gz
DATE=${{ steps.get-date.outputs.result }}
REVISION=${{ github.sha }}
VERSION=${{ steps.get-version.outputs.result }}
target: app

notify-if-failed:
name: Send slack notification on build failure
Expand Down
22 changes: 12 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ jobs:
with:
maven-version: 3.8.5
- uses: ./.github/actions/use-ci-nexus-cache
- run: mvn -B -DskipChecks -DskipTests install
- run: docker build --build-arg DISTBALL=dist/target/camunda-zeebe-*.tar.gz --build-arg APP_ENV=dev -t "${ZEEBE_TEST_DOCKER_IMAGE}" .
- run: docker push "${ZEEBE_TEST_DOCKER_IMAGE}"
- uses: ./.github/actions/build-docker
with:
repository: localhost:5000/camunda/zeebe
version: current-test
push: true
package: true
- name: Prepare Testcontainers Cloud agent
if: env.TC_CLOUD_TOKEN != ''
run: |
Expand Down Expand Up @@ -77,7 +80,6 @@ jobs:
maven-version: 3.8.5
- uses: ./.github/actions/use-ci-nexus-cache
- run: mvn -B -DskipChecks -DskipTests install
- run: docker build --build-arg DISTBALL=dist/target/camunda-zeebe-*.tar.gz --build-arg APP_ENV=dev -t camunda/zeebe:current-test .
- run: >
mvn -B --no-snapshot-updates
-D skipUTs -D skipChecks -D failsafe.rerunFailingTestsCount=3
Expand Down Expand Up @@ -249,10 +251,6 @@ jobs:
go-version-file: 'clients/go/go.mod'
cache: true
cache-dependency-path: 'clients/go/go.sum'
- uses: actions/setup-java@v3.4.1
with:
java-version: '17'
distribution: 'temurin'
- name: Check gocompat
run: |
curl -sL https://github.com/smola/gocompat/releases/download/v0.3.0/gocompat_linux_amd64.tar.gz | tar xzvf - gocompat_linux_amd64
Expand All @@ -263,8 +261,12 @@ jobs:
done
./gocompat_linux_amd64 compare --go1compat ${EXCLUDE} ./...
working-directory: clients/go/
- run: mvn -B -DskipChecks -DskipTests install
- run: docker build --build-arg DISTBALL=dist/target/camunda-zeebe-*.tar.gz --build-arg APP_ENV=dev -t camunda/zeebe:current-test .
- uses: ./.github/actions/build-docker
id: build-docker
with:
repository: camunda/zeebe
version: current-test
package: true
- run: go test -mod=vendor -v ./...
working-directory: clients/go
java-client:
Expand Down