Skip to content

Commit 0fd325c

Browse files
committed
feat: separate dockerhub push steps
1 parent 55faa94 commit 0fd325c

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

.github/workflows/maven-and-docker-build.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ name: Maven and Docker Build
22

33
on:
44
workflow_call:
5+
inputs:
6+
docker:
7+
type: boolean
8+
default: true
59

610
jobs:
711
build:
@@ -41,6 +45,7 @@ jobs:
4145
-Dsonar.projectKey=soat-tech-challenge_$REPO_NAME
4246
4347
- name: Build Dockerfile (no push)
48+
if: ${{ inputs.docker == true || inputs.docker == 'true' }}
4449
uses: docker/build-push-action@v5
4550
with:
4651
context: .

.github/workflows/maven-bump-push-dockerhub.yml

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,24 @@ name: Maven Build
44
on:
55
workflow_call:
66
inputs:
7+
docker:
8+
type: boolean
9+
default: true
710
dockerhub_username:
811
type: string
9-
required: true
1012
image_name:
1113
type: string
12-
required: true
1314

1415
jobs:
1516
build:
1617
name: Maven Build
1718
runs-on: ubuntu-latest
1819
environment:
19-
name: Docker Hub
20-
url: https://hub.docker.com/layers/${{ inputs.image_name }}/${{ steps.bump.outputs.tag }}/images/${{ steps.docker_build_push.outputs.digest }}
20+
name: Build # To isolate BUMP_PAT
21+
url: ${{ steps.upload.outputs.artifact-url }}
22+
outputs:
23+
artifact_name: app-${{ steps.bump.outputs.tag }}
24+
new_tag: ${{ steps.bump.outputs.tag }}
2125

2226
steps:
2327
- name: Checkout
@@ -33,6 +37,13 @@ jobs:
3337
distribution: "liberica"
3438
cache: "maven"
3539

40+
- name: Cache SonarQube packages
41+
uses: actions/cache@v3
42+
with:
43+
path: ~/.sonar/cache
44+
key: ${{ runner.os }}-sonar
45+
restore-keys: ${{ runner.os }}-sonar
46+
3647
- name: Run Tests
3748
run: mvn test -B -P prod "-Dstyle.color=always"
3849

@@ -54,6 +65,33 @@ jobs:
5465
-Dsonar.organization=soat-tech-challenge \
5566
-Dsonar.projectKey=soat-tech-challenge_$REPO_NAME
5667
68+
- name: Upload Artifact
69+
id: upload
70+
uses: actions/upload-artifact@v4
71+
with:
72+
name: app-${{ steps.bump.outputs.tag }}
73+
path: target/app.jar
74+
if-no-files-found: error
75+
76+
docker:
77+
name: Docker Build and Push
78+
if: ${{ inputs.docker == true || inputs.docker == 'true' }}
79+
needs: build
80+
runs-on: ubuntu-latest
81+
environment:
82+
name: Docker Hub
83+
url: https://hub.docker.com/layers/${{ inputs.image_name }}/${{ needs.build.outputs.new_tag }}/images/${{ steps.docker_build_push.outputs.digest }}
84+
85+
steps:
86+
- name: Checkout
87+
uses: actions/checkout@v3
88+
89+
- name: Download Artifact
90+
uses: actions/download-artifact@v4
91+
with:
92+
name: ${{ needs.build.outputs.artifact_name }}
93+
path: target/app.jar
94+
5795
- name: Login to Docker Hub
5896
uses: docker/login-action@v3
5997
with:
@@ -66,4 +104,4 @@ jobs:
66104
with:
67105
context: .
68106
push: true
69-
tags: ${{ inputs.image_name }}:${{ steps.bump.outputs.tag }},${{ inputs.image_name }}:latest
107+
tags: ${{ inputs.image_name }}:${{ needs.build.outputs.new_tag }},${{ inputs.image_name }}:latest

0 commit comments

Comments
 (0)