Skip to content

Commit dd4307b

Browse files
authored
Merge pull request #10 from yiliuTo/add-dockerfile-and-workflows
add dockerfile and workflow yaml
2 parents 1d2df40 + acd8fe2 commit dd4307b

File tree

2 files changed

+171
-0
lines changed

2 files changed

+171
-0
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# This workflow will clone and build another Java project with Maven, and build and push Docker images to the GitHubs container registry
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
3+
# https://docs.github.com/actions/use-cases-and-examples/publishing-packages/publishing-docker-images
4+
5+
name: Publish Petclinic images
6+
7+
on:
8+
workflow_dispatch:
9+
10+
defaults:
11+
run:
12+
shell: bash
13+
working-directory: spring-petclinic-microservices
14+
15+
env:
16+
REGISTRY: ghcr.io
17+
IMAGE_PREFIX: ${{ github.repository_owner }}
18+
CUSTOMERS_SERVICE: spring-petclinic-customers-service
19+
VETS_SERVICE: spring-petclinic-vets-service
20+
VISITS_SERVICE: spring-petclinic-visits-service
21+
API_GATEWAY: spring-petclinic-api-gateway
22+
23+
jobs:
24+
build-and-push-image:
25+
runs-on: ubuntu-latest
26+
permissions:
27+
contents: read
28+
packages: write
29+
attestations: write
30+
id-token: write
31+
steps:
32+
- uses: actions/checkout@v4
33+
- name: Set up JDK 17
34+
uses: actions/setup-java@v4
35+
with:
36+
java-version: '17'
37+
distribution: 'temurin'
38+
cache: maven
39+
- name: Clone source repo
40+
# Refer to https://github.com/actions/checkout/issues/24#issuecomment-1234831235 to check out another repository
41+
run: |
42+
git config --global url.https://github.com/.insteadOf git://github.com/
43+
git clone https://github.com/spring-petclinic/spring-petclinic-microservices.git
44+
- name: Build with Maven
45+
run: |
46+
cd spring-petclinic-microservices
47+
mvn -B clean package --file pom.xml -DskipTests
48+
- name: Log in to the Container registry
49+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
50+
with:
51+
registry: ${{ env.REGISTRY }}
52+
username: ${{ github.actor }}
53+
password: ${{ secrets.GITHUB_TOKEN }}
54+
- name: Extract metadata (tags, labels) for customers-service
55+
id: meta-customers
56+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
57+
with:
58+
images: |
59+
${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/${{ env.CUSTOMERS_SERVICE }}
60+
- name: Build and push customers-service image
61+
id: push-customers
62+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
63+
with:
64+
context: spring-petclinic-microservices/
65+
file: spring-petclinic-microservices/docker/Dockerfile
66+
push: true
67+
tags: ${{ steps.meta-customers.outputs.tags }}
68+
build-args: ARTIFACT_NAME=${{ env.CUSTOMERS_SERVICE }}
69+
- name: Generate artifact attestation for customers-service
70+
id: attest-customers
71+
uses: actions/attest-build-provenance@v1
72+
with:
73+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/${{ env.CUSTOMERS_SERVICE }}
74+
subject-digest: ${{ steps.push-customers.outputs.digest }}
75+
push-to-registry: true
76+
- name: Extract metadata (tags, labels) for vets-service
77+
id: meta-vets
78+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
79+
with:
80+
images: |
81+
${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/${{ env.VETS_SERVICE }}
82+
- name: Build and push vets-service image
83+
id: push-vets
84+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
85+
with:
86+
context: spring-petclinic-microservices/
87+
file: spring-petclinic-microservices/docker/Dockerfile
88+
push: true
89+
tags: ${{ steps.meta-vets.outputs.tags }}
90+
build-args: ARTIFACT_NAME=${{ env.VETS_SERVICE }}
91+
- name: Generate artifact attestation for vets-service
92+
id: attest-vets
93+
uses: actions/attest-build-provenance@v1
94+
with:
95+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/${{ env.VETS_SERVICE }}
96+
subject-digest: ${{ steps.push-vets.outputs.digest }}
97+
push-to-registry: true
98+
- name: Extract metadata (tags, labels) for visits-service
99+
id: meta-visits
100+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
101+
with:
102+
images: |
103+
${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/${{ env.VISITS_SERVICE }}
104+
- name: Build and push visits-service image
105+
id: push-visits
106+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
107+
with:
108+
context: spring-petclinic-microservices/
109+
file: spring-petclinic-microservices/docker/Dockerfile
110+
push: true
111+
tags: ${{ steps.meta-visits.outputs.tags }}
112+
build-args: ARTIFACT_NAME=${{ env.VISITS_SERVICE }}
113+
- name: Generate artifact attestation for visits-service
114+
id: attest-visits
115+
uses: actions/attest-build-provenance@v1
116+
with:
117+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/${{ env.VISITS_SERVICE }}
118+
subject-digest: ${{ steps.push-visits.outputs.digest }}
119+
push-to-registry: true
120+
- name: Extract metadata (tags, labels) for api-gateway
121+
id: meta-api
122+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
123+
with:
124+
images: |
125+
${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/${{ env.API_GATEWAY }}
126+
- name: Build and push api-gateway image
127+
id: push-api
128+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
129+
with:
130+
context: spring-petclinic-microservices/
131+
file: spring-petclinic-microservices/docker/Dockerfile
132+
push: true
133+
tags: ${{ steps.meta-api.outputs.tags }}
134+
build-args: |
135+
ARTIFACT_NAME=${{ env.API_GATEWAY }}
136+
EXPOSED_PORT=8080
137+
- name: Generate artifact attestation for api-gateway
138+
id: attest-api
139+
uses: actions/attest-build-provenance@v1
140+
with:
141+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/${{ env.API_GATEWAY }}
142+
subject-digest: ${{ steps.push-api.outputs.digest }}
143+
push-to-registry: true
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM eclipse-temurin:17 as builder
2+
WORKDIR application
3+
ARG ARTIFACT_NAME
4+
COPY ../spring-petclinic-microservices/${ARTIFACT_NAME}/target/${ARTIFACT_NAME}-*.jar application.jar
5+
RUN java -Djarmode=layertools -jar application.jar extract
6+
7+
8+
FROM eclipse-temurin:17
9+
WORKDIR application
10+
11+
ARG EXPOSED_PORT
12+
RUN if [ -n "${EXPOSED_PORT}" ]; then \
13+
echo "EXPOSE ${EXPOSED_PORT}" >> Dockerfile; \
14+
fi
15+
16+
COPY --from=builder application/dependencies/ ./
17+
18+
# fix for https://stackoverflow.com/questions/51115856/docker-failed-to-export-image-failed-to-create-image-failed-to-get-layer
19+
# (only last copy caused issue)
20+
# this seems to be triggered by using btrfs:
21+
# https://github.com/moby/moby/issues/36573
22+
RUN true
23+
COPY --from=builder application/spring-boot-loader/ ./
24+
RUN true
25+
COPY --from=builder application/snapshot-dependencies/ ./
26+
RUN true
27+
COPY --from=builder application/application/ ./
28+
ENTRYPOINT ["java", "org.springframework.boot.loader.launch.JarLauncher"]

0 commit comments

Comments
 (0)