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 : ./mvnw -V -f ${{ inputs.module }} --no-transfer-progress spring-boot:build-image -DskipTests -Dspring-boot.build-image.imageName=ghcr.io/${{ github.repository }}:jvm_${GITHUB_SHA}
40+ - name : Login to GitHub Container Registry
41+ if : github.ref == inputs.target_ref
42+ uses : docker/login-action@v3
43+ with :
44+ registry : ghcr.io
45+ username : ${{ github.actor }}
46+ password : ${{ secrets.GITHUB_TOKEN }}
47+ - name : docker push
48+ if : github.ref == inputs.target_ref
49+ run : |
50+ docker push ghcr.io/${{ github.repository }}:jvm_${GITHUB_SHA}
51+ docker tag ghcr.io/${{ github.repository }}:jvm_${GITHUB_SHA} ghcr.io/${{ github.repository }}:jvm
52+ docker push ghcr.io/${{ github.repository }}:jvm
53+ - name : Generate digest
54+ if : github.ref == inputs.target_ref
55+ run : |
56+ cat <<EOF > ${{ inputs.image_file }}
57+ image: $(docker inspect --format='{{index .RepoDigests 0}}' ghcr.io/${{ github.repository }}:jvm_${GITHUB_SHA})
58+ git_revision: ${GITHUB_SHA}
59+ EOF
60+ - name : Upload artifact
61+ if : github.ref == inputs.target_ref
62+ uses : actions/upload-artifact@v4
63+ with :
64+ name : ${{ inputs.image_name }}
65+ path : ${{ inputs.image_file }}
0 commit comments