forked from spring-projects/spring-petclinic
-
Notifications
You must be signed in to change notification settings - Fork 37
89 lines (78 loc) · 2.86 KB
/
docker-build.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: Docker Build
on: [ pull_request, push, workflow_dispatch ]
env:
APP_NAME: petclinic
APP_PORT: 8080
jobs:
#####################################################################################################################
## The compile job compiles the application into a jar, and uploads it as an artifact for the next job to use.
compile:
name: Compile
runs-on: ubuntu-20.04
outputs:
jarname: ${{ steps.get-jarname.outputs.jarname }}
commit_sha: ${{ steps.commit-data.outputs.short_sha }}
env:
TARGET_DIR: target/
MVN_REPO_DIR: ~/.m2/repository
steps:
- uses: actions/checkout@v2
- name: Setup Java
uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 11
cache: maven
- run: java -version
- run: mvn -ntp -B package
# Store the output jar into the env for reuse below.
# It will contain, eg. "spring-petclinic-2.3.0.BUILD-SNAPSHOT.jar"
- name: Get jar filename
id: get-jarname
run: |
export JAR_NAME="$(basename $(ls target/*.jar))"
echo "Petclinic jar is $JAR_NAME"
echo "::set-output name=jarname::$JAR_NAME"
echo "JAR_NAME=$JAR_NAME" >> $GITHUB_ENV
# Upload the jar for future jobs to use.
- uses: actions/upload-artifact@v2
with:
name: ${{ env.JAR_NAME }}
path: ${{ env.TARGET_DIR }}/${{ env.JAR_NAME }}
if-no-files-found: error
# Use the commit short-sha as the suffix of the app_name
- name: Get commit short-sha
id: commit-data
uses: redhat-actions/common/commit-data@v1
#####################################################################################################################
## The build and push image job builds the container image with the petclinic jar in it,
## and pushes it to an image registry.
## It outputs the image tag and image URL for the next step to use when deploying to the OpenShift cluster.
build-push-image:
name: Docker Build
runs-on: ubuntu-20.04
needs: compile
env:
JAR_NAME: ${{ needs.compile.outputs.jarname }}
IMAGE_TAGS: latest ${{ needs.compile.outputs.commit_sha }}
steps:
- uses: actions/checkout@v2
# Download the jar artifact from the compile step
- uses: actions/download-artifact@v2
with:
name: ${{ env.JAR_NAME }}
# The dockerfile expects the jar to be under target/
- name: Fake target/ dir
run: |
mkdir target/
mv -v ${{ env.JAR_NAME }} target/
# Use buildah to build the application image with the jar inside.
- name: Build Image
uses: redhat-actions/buildah-build@v2
with:
image: ${{ env.APP_NAME }}
tags: ${{ env.IMAGE_TAGS }}
dockerfiles: |
./Dockerfile
build-args:
jar_name=${{ env.JAR_NAME }}