Skip to content

Commit 3f8ef31

Browse files
mirceamogosmmogos
andauthored
CAT-26299 Allow passing build args to build workflow (#57)
* CAT-26299 Allow passing build args to build workflow * CAT-26299 Allow passing build args to build workflow * CAT-26299 Allow passing build args to build workflow * CAT-26299 Allow passing build args to build workflow * CAT-26299 Allow passing build args to build workflow * CAT-26299 Allow passing build args to build workflow * CAT-26299 Allow passing build args to build workflow --------- Co-authored-by: mmogos <mmogos@pbs.com>
1 parent 7f5994c commit 3f8ef31

File tree

3 files changed

+48
-20
lines changed

3 files changed

+48
-20
lines changed

.github/workflows/docker-build-push-test.yml

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,40 @@ permissions:
88
contents: read
99

1010
jobs:
11-
build:
12-
uses: ./.github/workflows/docker-build-push.yml
13-
secrets: inherit
14-
with:
15-
env: test
16-
immutable: false
17-
image_name: test-templates
18-
image_build_tag: latest
19-
image_test_tag: test
20-
before_command: |
21-
pwd
22-
CUSTOM_TAG="latest-custom"
23-
echo "CUSTOM_TAG=$CUSTOM_TAG" >> "$GITHUB_ENV"
24-
test_command: |
25-
pwd
26-
after_command: |
27-
pwd
28-
# sbom: true
29-
# parser: true
30-
# sonarqube: true
11+
setup:
12+
runs-on: ubuntu-latest
13+
environment: test
14+
outputs:
15+
slack_channel_id: ${{ vars.SLACK_CHANNEL_ID }}
16+
aws_account: ${{ vars.AWS_ACCOUNT }}
17+
aws_region: ${{ vars.AWS_REGION }}
18+
steps:
19+
- name: Expose environment variables
20+
run: echo "Capturing environment variables"
21+
22+
build:
23+
needs: setup
24+
uses: ./.github/workflows/docker-build-push.yml
25+
secrets: inherit
26+
with:
27+
env: test
28+
immutable: true
29+
image_name: test-templates
30+
image_build_tag: latest
31+
image_test_tag: test
32+
build_args: |
33+
TESTING_BUILD_ARG1=testVALUE
34+
TESTING_BUILD_ARG2=${{ needs.setup.outputs.slack_channel_id }}
35+
before_command: |
36+
pwd
37+
CUSTOM_TAG="latest-custom"
38+
echo "CUSTOM_TAG=$CUSTOM_TAG" >> "$GITHUB_ENV"
39+
test_command: |
40+
pwd
41+
docker run --rm ${{ format('{0}.dkr.ecr.{1}.amazonaws.com', needs.setup.outputs.aws_account, needs.setup.outputs.aws_region) }}/test-templates:test cat /build_args.txt
42+
after_command: |
43+
pwd
44+
# sbom: true
45+
# parser: true
46+
# sonarqube: true
47+

.github/workflows/docker-build-push.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ on:
9696
description: 'Custom registry path'
9797
required: false
9898
default: ''
99+
build_args:
100+
type: string
101+
description: 'Docker build arguments'
102+
required: false
103+
default: ''
99104

100105
outputs:
101106
image:
@@ -249,6 +254,7 @@ jobs:
249254
tags: ${{ env.DOCKER_REGISTRY }}/${{ env.APP_NAME }}:${{ inputs.image_test_tag }}
250255
builder: builder
251256
cache-from: type=registry,ref=${{ env.DOCKER_REGISTRY }}/${{ env.APP_NAME }}:cache-${{ inputs.image_build_tag }}
257+
build-args: ${{ inputs.build_args }}
252258

253259
- name: Update Slack
254260
uses: pbs/gha-public-workflows/.github/actions/slack-message@main
@@ -311,6 +317,7 @@ jobs:
311317
push: true
312318
tags: ${{ env.DOCKER_REGISTRY }}/${{ env.APP_NAME }}:${{ inputs.image_build_tag }}
313319
cache-to: type=registry,mode=max,image-manifest=true,oci-mediatypes=true,ref=${{ env.DOCKER_REGISTRY }}/${{ env.APP_NAME }}:cache-${{ inputs.image_build_tag }}
320+
build-args: ${{ inputs.build_args }}
314321

315322
- name: Docker Push Image Custom Tag
316323
uses: docker/build-push-action@v6
@@ -321,6 +328,7 @@ jobs:
321328
file: ${{ inputs.dockerfile }}
322329
push: true
323330
tags: ${{ env.DOCKER_REGISTRY }}/${{ env.APP_NAME }}:${{ env.CUSTOM_TAG }}
331+
build-args: ${{ inputs.build_args }}
324332

325333
- name: Update Slack
326334
uses: pbs/gha-public-workflows/.github/actions/slack-message@main

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
FROM alpine:latest
2+
ARG TESTING_BUILD_ARG1
3+
ARG TESTING_BUILD_ARG2
24
RUN apk update && \
35
apk add vim
6+
RUN echo "Testing build args: TESTING_BUILD_ARG1=${TESTING_BUILD_ARG1}, TESTING_BUILD_ARG2=${TESTING_BUILD_ARG2}" > /build_args.txt
47
CMD ["which", "vim"]

0 commit comments

Comments
 (0)