1+ name : Build OCI Image (JVM)
2+ on :
3+ workflow_call :
4+ inputs :
5+ module :
6+ required : true
7+ type : string
8+ image_name :
9+ required : false
10+ type : string
11+ default : image
12+ image_file :
13+ required : false
14+ type : string
15+ default : image.yaml
16+ target_ref :
17+ required : false
18+ type : string
19+ default : ' refs/heads/main'
20+ runs_on :
21+ required : false
22+ type : string
23+ default : ubuntu-latest
24+ jobs :
25+ build :
26+ runs-on : ubuntu-latest
27+ permissions :
28+ contents : read
29+ packages : write
30+ steps :
31+ - uses : actions/checkout@v2
32+ - uses : graalvm/setup-graalvm@v1
33+ with :
34+ java-version : ' 21'
35+ distribution : graalvm
36+ cache : ' maven'
37+ - name : Set version
38+ run : |
39+ CURRENT_VERSION=$(./mvnw -f ${{ inputs.module }} help:evaluate -Dexpression=project.version -q -DforceStdout)
40+ NEW_VERSION=$(echo $CURRENT_VERSION | sed "s/-SNAPSHOT/.${GITHUB_SHA}/")
41+ ./mvnw -f ${{ inputs.module }} versions:set -DnewVersion=${NEW_VERSION} -DgenerateBackupPoms=false --no-transfer-progress
42+ - name : build image (Paketo Buildpack)
43+ run : |
44+ OS_ARCH=$(./mvnw -f ${{ inputs.module }} help:evaluate -Dexpression=os.arch -q -DforceStdout)
45+ ./mvnw -V -f ${{ inputs.module }} --no-transfer-progress spring-boot:build-image -DskipTests -Dspring-boot.build-image.imageName=ghcr.io/${{ github.repository }}/${{ inputs.module }}:jvm_${OS_ARCH}_${GITHUB_SHA}
46+ - name : Login to GitHub Container Registry
47+ if : github.ref == inputs.target_ref
48+ uses : docker/login-action@v3
49+ with :
50+ registry : ghcr.io
51+ username : ${{ github.actor }}
52+ password : ${{ secrets.GITHUB_TOKEN }}
53+ - name : docker push
54+ if : github.ref == inputs.target_ref
55+ run : |
56+ OS_ARCH=$(./mvnw -f ${{ inputs.module }} help:evaluate -Dexpression=os.arch -q -DforceStdout)
57+ docker push ghcr.io/${{ github.repository }}/${{ inputs.module }}:jvm_${OS_ARCH}_${GITHUB_SHA}
58+ docker tag ghcr.io/${{ github.repository }}/${{ inputs.module }}:jvm_${OS_ARCH}_${GITHUB_SHA} ghcr.io/${{ github.repository }}/${{ inputs.module }}:jvm_${OS_ARCH}
59+ docker push ghcr.io/${{ github.repository }}/${{ inputs.module }}:jvm_${OS_ARCH}
60+ - name : Generate digest
61+ if : github.ref == inputs.target_ref
62+ run : |
63+ OS_ARCH=$(./mvnw -f ${{ inputs.module }} help:evaluate -Dexpression=os.arch -q -DforceStdout)
64+ cat <<EOF > ${{ inputs.image_file }}
65+ image: $(docker inspect --format='{{index .RepoDigests 0}}' ghcr.io/${{ github.repository }}/${{ inputs.module }}:jvm_${OS_ARCH}_${GITHUB_SHA})
66+ git_revision: ${GITHUB_SHA}
67+ EOF
68+ - name : Upload artifact
69+ if : github.ref == inputs.target_ref
70+ uses : actions/upload-artifact@v4
71+ with :
72+ name : ${{ inputs.image_name }}
73+ path : ${{ inputs.image_file }}
0 commit comments