Skip to content

Commit

Permalink
build(github): add reusable build docker action
Browse files Browse the repository at this point in the history
  • Loading branch information
npepinpe committed Aug 9, 2022
1 parent 51716bb commit aac645b
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 69 deletions.
92 changes: 92 additions & 0 deletions .github/actions/build-docker/action.yml
@@ -0,0 +1,92 @@
# 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
# 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:
- 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: true
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
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
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
13 changes: 6 additions & 7 deletions .github/workflows/test.yml
Expand Up @@ -77,7 +77,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 +248,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 +258,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

0 comments on commit aac645b

Please sign in to comment.