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+ jobs :
21+ build :
22+ runs-on : ubuntu-latest
23+ permissions :
24+ contents : read
25+ packages : write
26+ steps :
27+ - uses : actions/checkout@v2
28+ - uses : graalvm/setup-graalvm@v1
29+ with :
30+ java-version : ' 21'
31+ distribution : graalvm
32+ cache : ' maven'
33+ - name : Set version
34+ run : |
35+ CURRENT_VERSION=$(./mvnw -f ${{ inputs.module }} help:evaluate -Dexpression=project.version -q -DforceStdout)
36+ NEW_VERSION=$(echo $CURRENT_VERSION | sed "s/-SNAPSHOT/.${GITHUB_SHA}/")
37+ ./mvnw -f ${{ inputs.module }} versions:set -DnewVersion=${NEW_VERSION} -DgenerateBackupPoms=false --no-transfer-progress
38+ - name : build image (Paketo Buildpack)
39+ run : |
40+ OS_ARCH=$(./mvnw -f ${{ inputs.module }} help:evaluate -Dexpression=os.arch -q -DforceStdout)
41+ ./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}
42+ - name : Login to GitHub Container Registry
43+ if : github.ref == inputs.target_ref
44+ uses : docker/login-action@v3
45+ with :
46+ registry : ghcr.io
47+ username : ${{ github.actor }}
48+ password : ${{ secrets.GITHUB_TOKEN }}
49+ - name : docker push
50+ if : github.ref == inputs.target_ref
51+ run : |
52+ OS_ARCH=$(./mvnw -f ${{ inputs.module }} help:evaluate -Dexpression=os.arch -q -DforceStdout)
53+ docker push ghcr.io/${{ github.repository }}/${{ inputs.module }}:jvm_${OS_ARCH}_${GITHUB_SHA}
54+ docker tag ghcr.io/${{ github.repository }}/${{ inputs.module }}:jvm_${OS_ARCH}_${GITHUB_SHA} ghcr.io/${{ github.repository }}/${{ inputs.module }}:jvm_${OS_ARCH}
55+ docker push ghcr.io/${{ github.repository }}/${{ inputs.module }}:jvm_${OS_ARCH}
56+ - name : Generate digest
57+ if : github.ref == inputs.target_ref
58+ run : |
59+ OS_ARCH=$(./mvnw -f ${{ inputs.module }} help:evaluate -Dexpression=os.arch -q -DforceStdout)
60+ cat <<EOF > ${{ inputs.image_file }}
61+ image: $(docker inspect --format='{{index .RepoDigests 0}}' ghcr.io/${{ github.repository }}/${{ inputs.module }}:jvm_${OS_ARCH}_${GITHUB_SHA})
62+ git_revision: ${GITHUB_SHA}
63+ EOF
64+ - name : Upload artifact
65+ if : github.ref == inputs.target_ref
66+ uses : actions/upload-artifact@v4
67+ with :
68+ name : ${{ inputs.image_name }}
69+ path : ${{ inputs.image_file }}
0 commit comments