Skip to content

Commit 9a5ff39

Browse files
committed
create reusable workflow for docker build
1 parent 941358d commit 9a5ff39

File tree

6 files changed

+126
-166
lines changed

6 files changed

+126
-166
lines changed

.github/workflows/branch-deploy.yml

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ name: "Infra: Feature Testing: Init env"
22

33
on:
44
workflow_dispatch:
5-
65
pull_request:
76
types: ['labeled']
87

@@ -19,61 +18,42 @@ jobs:
1918
with:
2019
ref: ${{ github.event.pull_request.head.sha }}
2120
token: ${{ github.token }}
21+
2222
- name: get branch name
2323
id: extract_branch
2424
run: |
2525
tag='pr${{ github.event.pull_request.number }}'
2626
echo "tag=${tag}" >> $GITHUB_OUTPUT
27-
env:
28-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
2928
- name: Set up JDK
3029
uses: actions/setup-java@v4
3130
with:
3231
java-version: '17'
3332
distribution: 'zulu'
3433
cache: 'maven'
34+
3535
- name: Build
3636
id: build
3737
run: |
3838
./mvnw -B -ntp versions:set -DnewVersion=$GITHUB_SHA
3939
./mvnw -B -V -ntp clean package -Pprod -DskipTests
4040
export VERSION=$(./mvnw -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
4141
echo "version=${VERSION}" >> $GITHUB_OUTPUT
42-
- name: Set up QEMU
43-
uses: docker/setup-qemu-action@v3
44-
- name: Set up Docker Buildx
45-
id: buildx
46-
uses: docker/setup-buildx-action@v3
47-
- name: Cache Docker layers
48-
uses: actions/cache@v4
49-
with:
50-
path: /tmp/.buildx-cache
51-
key: ${{ runner.os }}-buildx-${{ github.sha }}
52-
restore-keys: |
53-
${{ runner.os }}-buildx-
54-
- name: Configure AWS credentials for Kafka-UI account
55-
uses: aws-actions/configure-aws-credentials@v4
42+
43+
- name: Build and Push Docker Image
44+
uses: ./.github/workflows/build-docker
5645
with:
46+
tag: ${{ steps.extract_branch.outputs.tag }}
47+
version: ${{ steps.build.outputs.version }}
5748
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
5849
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
5950
aws-region: eu-central-1
60-
- name: Login to Amazon ECR
61-
id: login-ecr
62-
uses: aws-actions/amazon-ecr-login@v2
63-
- name: Build and push
64-
id: docker_build_and_push
65-
uses: docker/build-push-action@v5
66-
with:
67-
builder: ${{ steps.buildx.outputs.name }}
68-
context: api
69-
push: true
70-
tags: 297478128798.dkr.ecr.eu-central-1.amazonaws.com/kafka-ui:${{ steps.extract_branch.outputs.tag }}
71-
build-args: |
72-
JAR_FILE=api-${{ steps.build.outputs.version }}.jar
73-
cache-from: type=local,src=/tmp/.buildx-cache
74-
cache-to: type=local,dest=/tmp/.buildx-cache
51+
repository: 297478128798.dkr.ecr.eu-central-1.amazonaws.com/kafka-ui
52+
build-context: api
53+
7554
outputs:
7655
tag: ${{ steps.extract_branch.outputs.tag }}
56+
7757
make-branch-env:
7858
needs: build
7959
runs-on: ubuntu-latest
@@ -89,7 +69,7 @@ jobs:
8969
git config --global user.email "[email protected]"
9070
git config --global user.name "infra-tech"
9171
git add ../kafka-ui-from-branch/
92-
git commit -m "added env:${{ needs.build.outputs.deploy }}" && git push || true
72+
git commit -m "added env:${{ needs.build.outputs.tag }}" && git push || true
9373
9474
- name: update status check for private deployment
9575
if: ${{ github.event.label.name == 'status/feature_testing' }}
@@ -98,7 +78,7 @@ jobs:
9878
authToken: ${{secrets.GITHUB_TOKEN}}
9979
context: "Click Details button to open custom deployment page"
10080
state: "success"
101-
sha: ${{ github.event.pull_request.head.sha || github.sha }}
81+
sha: ${{ github.event.pull_request.head.sha || github.sha }}
10282
target_url: "http://${{ needs.build.outputs.tag }}.internal.ui.kafbat.dev"
10383

10484
- name: update status check for public deployment
@@ -108,5 +88,5 @@ jobs:
10888
authToken: ${{secrets.GITHUB_TOKEN}}
10989
context: "Click Details button to open custom deployment page"
11090
state: "success"
111-
sha: ${{ github.event.pull_request.head.sha || github.sha }}
91+
sha: ${{ github.event.pull_request.head.sha || github.sha }}
11292
target_url: "http://${{ needs.build.outputs.tag }}.internal.ui.kafbat.dev"

.github/workflows/build-docker.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: 'Docker Build and Push'
2+
description: 'Build Docker image and push to ECR'
3+
4+
inputs:
5+
tag:
6+
description: 'Tag from branch name or PR number'
7+
required: true
8+
version:
9+
description: 'Version for the Docker image'
10+
required: true
11+
aws-access-key-id:
12+
description: 'AWS Access Key ID'
13+
required: true
14+
secret: true
15+
aws-secret-access-key:
16+
description: 'AWS Secret Access Key'
17+
required: true
18+
secret: true
19+
20+
runs:
21+
using: "composite"
22+
steps:
23+
- name: Set up QEMU
24+
uses: docker/setup-qemu-action@v3
25+
26+
- name: Set up Docker Buildx
27+
id: buildx
28+
uses: docker/setup-buildx-action@v3
29+
30+
- name: Cache Docker layers
31+
uses: actions/cache@v4
32+
with:
33+
path: /tmp/.buildx-cache
34+
key: ${{ runner.os }}-buildx-${{ github.sha }}
35+
restore-keys: |
36+
${{ runner.os }}-buildx-
37+
38+
- name: Configure AWS credentials for Kafka-UI account
39+
uses: aws-actions/configure-aws-credentials@v4
40+
with:
41+
aws-access-key-id: ${{ inputs.aws-access-key-id }}
42+
aws-secret-access-key: ${{ inputs.aws-secret-access-key }}
43+
aws-region: us-east-1
44+
45+
- name: Login to Amazon ECR
46+
id: login-ecr
47+
uses: aws-actions/amazon-ecr-login@v2
48+
with:
49+
registry-type: 'public'
50+
51+
- name: Build and push Docker image
52+
id: docker_build_and_push
53+
uses: docker/build-push-action@v5
54+
with:
55+
builder: ${{ steps.buildx.outputs.name }}
56+
context: api
57+
tags: public.ecr.aws/kafbat/kafka-ui-custom-build:${{ inputs.tag }}
58+
build-args: |
59+
JAR_FILE=api-${{ inputs.version }}.jar
60+
cache-from: type=local,src=/tmp/.buildx-cache
61+
cache-to: type=local,dest=/tmp/.buildx-cache

.github/workflows/build-public-image.yml

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,59 +17,34 @@ jobs:
1717
with:
1818
ref: ${{ github.event.pull_request.head.sha }}
1919
token: ${{ github.token }}
20+
2021
- name: get branch name
2122
id: extract_branch
2223
run: |
2324
tag='${{ github.event.pull_request.number }}'
2425
echo "tag=${tag}" >> $GITHUB_OUTPUT
26+
2527
- name: Set up JDK
2628
uses: actions/setup-java@v4
2729
with:
2830
java-version: '17'
2931
distribution: 'zulu'
3032
cache: 'maven'
33+
3134
- name: Build
3235
id: build
3336
run: |
3437
./mvnw -B -ntp versions:set -DnewVersion=$GITHUB_SHA
3538
./mvnw -B -V -ntp clean package -Pprod -DskipTests
3639
export VERSION=$(./mvnw -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
3740
echo "version=${VERSION}" >> $GITHUB_OUTPUT
38-
- name: Set up QEMU
39-
uses: docker/setup-qemu-action@v3
40-
- name: Set up Docker Buildx
41-
id: buildx
42-
uses: docker/setup-buildx-action@v3
43-
- name: Cache Docker layers
44-
uses: actions/cache@v4
45-
with:
46-
path: /tmp/.buildx-cache
47-
key: ${{ runner.os }}-buildx-${{ github.sha }}
48-
restore-keys: |
49-
${{ runner.os }}-buildx-
50-
- name: Configure AWS credentials for Kafka-UI account
51-
uses: aws-actions/configure-aws-credentials@v4
52-
with:
53-
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
54-
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
55-
aws-region: us-east-1
56-
- name: Login to Amazon ECR
57-
id: login-ecr
58-
uses: aws-actions/amazon-ecr-login@v2
59-
with:
60-
registry-type: 'public'
61-
- name: Build and push
62-
id: docker_build_and_push
63-
uses: docker/build-push-action@v5
41+
42+
- name: Build and Test Docker Image
43+
uses: ./.github/workflows/build-docker
6444
with:
65-
builder: ${{ steps.buildx.outputs.name }}
66-
context: api
67-
push: true
68-
tags: public.ecr.aws/kafbat/kafka-ui-custom-build:${{ steps.extract_branch.outputs.tag }}
69-
build-args: |
70-
JAR_FILE=api-${{ steps.build.outputs.version }}.jar
71-
cache-from: type=local,src=/tmp/.buildx-cache
72-
cache-to: type=local,dest=/tmp/.buildx-cache
45+
tag: ${{ steps.extract_branch.outputs.tag }}
46+
version: ${{ steps.build.outputs.version }}
47+
7348
- name: make comment with private deployment link
7449
uses: peter-evans/create-or-update-comment@v4
7550
with:

.github/workflows/cve_checks.yml

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: "Infra: CVE checks"
2+
23
on:
34
workflow_dispatch:
45
schedule:
@@ -17,6 +18,12 @@ jobs:
1718
with:
1819
token: ${{ github.token }}
1920

21+
- name: get branch name
22+
id: extract_branch
23+
run: |
24+
tag='build-${{ github.sha }}'
25+
echo "tag=${tag}" >> $GITHUB_OUTPUT
26+
2027
- name: Set up JDK
2128
uses: actions/setup-java@v4
2229
with:
@@ -32,34 +39,16 @@ jobs:
3239
export VERSION=$(./mvnw -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
3340
echo "version=${VERSION}" >> $GITHUB_OUTPUT
3441
35-
- name: Set up QEMU
36-
uses: docker/setup-qemu-action@v3
37-
38-
- name: Set up Docker Buildx
39-
uses: docker/setup-buildx-action@v3
40-
41-
- name: Cache Docker layers
42-
uses: actions/cache@v4
43-
with:
44-
path: /tmp/.buildx-cache
45-
key: ${{ runner.os }}-buildx-${{ github.sha }}
46-
restore-keys: |
47-
${{ runner.os }}-buildx-
48-
49-
- name: Build docker image
50-
uses: docker/build-push-action@v5
42+
- name: Build Docker Image
43+
uses: ./.github/workflows/build-docker
5144
with:
52-
builder: ${{ steps.buildx.outputs.name }}
53-
context: api
54-
platforms: linux/amd64
55-
push: false
56-
load: true
57-
tags: |
58-
ghcr.io/kafbat/kafka-ui:${{ steps.build.outputs.version }}
59-
build-args: |
60-
JAR_FILE=api-${{ steps.build.outputs.version }}.jar
61-
cache-from: type=local,src=/tmp/.buildx-cache
62-
cache-to: type=local,dest=/tmp/.buildx-cache
45+
tag: ${{ steps.extract_branch.outputs.tag }}
46+
version: ${{ steps.build.outputs.version }}
47+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
48+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
49+
aws-region: eu-central-1
50+
repository: ghcr.io/kafbat/kafka-ui
51+
build-context: api
6352

6453
- name: Run CVE checks
6554
uses: aquasecurity/[email protected]

.github/workflows/main.yml

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: "Main: Build & deploy"
2+
23
on:
34
workflow_dispatch:
4-
55
push:
66
branches: [ "main" ]
77

@@ -37,21 +37,16 @@ jobs:
3737
export VERSION=$(./mvnw -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
3838
echo "version=${VERSION}" >> $GITHUB_OUTPUT
3939
40-
# docker images
41-
42-
- name: Set up QEMU
43-
uses: docker/setup-qemu-action@v3
44-
45-
- name: Set up Docker Buildx
46-
uses: docker/setup-buildx-action@v3
47-
48-
- name: Cache Docker layers
49-
uses: actions/cache@v4
40+
- name: Build & Push Docker Image
41+
uses: ./.github/workflows/build-docker
5042
with:
51-
path: /tmp/.buildx-cache
52-
key: ${{ runner.os }}-buildx-${{ github.sha }}
53-
restore-keys: |
54-
${{ runner.os }}-buildx-
43+
tag: ${{ steps.build.outputs.version }}
44+
version: ${{ steps.build.outputs.version }}
45+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
46+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
47+
aws-region: eu-central-1
48+
repository: ghcr.io/kafbat/kafka-ui
49+
build-context: api
5550

5651
- name: Login to GitHub Container Registry
5752
uses: docker/login-action@v3
@@ -60,19 +55,7 @@ jobs:
6055
username: ${{ github.actor }}
6156
password: ${{ secrets.GITHUB_TOKEN }}
6257

63-
- name: Build & push docker image
64-
id: docker_build_and_push
65-
uses: docker/build-push-action@v5
66-
with:
67-
builder: ${{ steps.buildx.outputs.name }}
68-
context: api
69-
platforms: linux/amd64,linux/arm64
70-
provenance: false
71-
push: true
72-
tags: |
73-
ghcr.io/kafbat/kafka-ui:${{ steps.build.outputs.version }}
74-
ghcr.io/kafbat/kafka-ui:main
75-
build-args: |
76-
JAR_FILE=api-${{ steps.build.outputs.version }}.jar
77-
cache-from: type=local,src=/tmp/.buildx-cache
78-
cache-to: type=local,dest=/tmp/.buildx-cache
58+
- name: Push additional tag for main branch
59+
run: |
60+
docker tag ghcr.io/kafbat/kafka-ui:${{ steps.build.outputs.version }} ghcr.io/kafbat/kafka-ui:main
61+
docker push ghcr.io/kafbat/kafka-ui:main

0 commit comments

Comments
 (0)