-
Notifications
You must be signed in to change notification settings - Fork 556
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
10017: Reusable build docker action r=npepinpe a=npepinpe ## Description This PR aggregates the steps required to build the Docker image into a reusable action called `build-docker`. The action can build and push the Docker image, as well as package the artifacts for it if need be. Further iterations may want to split packaging out into its own action. Its usage is as: ```yaml - uses: ./.github/actions/build-docker with: repository: localhost:5000/camunda/zeebe version: current-test push: true package: true ``` The action will set up Docker & Buildx, Java, and Maven. If `package` is true, it will also setup `Go` in order to build `zbctl`. When `push` is true, the image is pushed to the given repository, with the tag being made of the `repository` and `version`. In the above, this would be equivalent to `docker push localhost:5000/camunda/zeebe:current-test`. If `push` is false, then the image is built and loaded into the local Docker registry only. If `package` is true, then `zbctl` is compiled, and all the modules are built and installed to the local maven repository. Additionally, the distribution TAR ball is built. If it's false, then the distribution TAR ball is expected to already be present under `dist/target/camunda-zeebe-<VERSION>-tar.gz`. If the `version` is omitted, it will be read from the Maven project. ## Related issues related to #10013 (as a follow up) Co-authored-by: Nicolas Pepin-Perreault <nicolas.pepin-perreault@camunda.com>
- Loading branch information
Showing
4 changed files
with
127 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# 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. | ||
|
||
--- | ||
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' }} | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters