Skip to content

Commit 757437b

Browse files
add dockerfile and CI workflows
1 parent 57b5a73 commit 757437b

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
6+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
7+
8+
name: Java CI with Gradle
9+
10+
on:
11+
push:
12+
branches: [ "main", "release/*" ]
13+
pull_request:
14+
branches: [ "**" ]
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: read
21+
steps:
22+
- uses: actions/checkout@v4
23+
- name: Set up JDK 21
24+
uses: actions/setup-java@v4
25+
with:
26+
java-version: '21'
27+
distribution: 'temurin'
28+
29+
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
30+
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
31+
32+
- name: Setup Gradle
33+
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
34+
- name: Build with Gradle Wrapper
35+
run: ./gradlew build
36+
37+
# NOTE: The Gradle Wrapper is the default and recommended way to run Gradle (https://docs.gradle.org/current/userguide/gradle_wrapper.html).
38+
# If your project does not have the Gradle Wrapper configured, you can use the following configuration to run Gradle with a specified version.
39+
#
40+
# - name: Setup Gradle
41+
# uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
42+
# with:
43+
# gradle-version: '8.5'
44+
#
45+
# - name: Build with Gradle 8.5
46+
# run: gradle build
47+
48+
- name: Remove unused plain jar
49+
run: rm build/libs/*plain.jar
50+
- name: Upload build artifacts
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: Package
54+
path: build/libs
55+
56+
docker:
57+
runs-on: ubuntu-latest
58+
needs: build
59+
steps:
60+
- name: Checkout
61+
uses: actions/checkout@v4
62+
- name: Download artifact
63+
uses: actions/download-artifact@v4
64+
with:
65+
name: Package
66+
path: build/libs
67+
- name: Set up QEMU
68+
uses: docker/setup-qemu-action@v3
69+
- name: Set up Docker Buildx
70+
uses: docker/setup-buildx-action@v3
71+
- name: Login to Docker Hub
72+
uses: docker/login-action@v3
73+
with:
74+
username: ${{ secrets.DOCKERHUB_USERNAME }}
75+
password: ${{ secrets.DOCKERHUB_TOKEN }}
76+
- name: Build and push
77+
uses: docker/build-push-action@v6
78+
with:
79+
context: .
80+
push: true
81+
platforms: linux/amd64, linux/arm64
82+
tags: xcodeassociated/spring-mvc-jpa-template:latest
83+
84+
dependency-submission:
85+
runs-on: ubuntu-latest
86+
permissions:
87+
contents: write
88+
steps:
89+
- uses: actions/checkout@v4
90+
- name: Set up JDK 21
91+
uses: actions/setup-java@v4
92+
with:
93+
java-version: '21'
94+
distribution: 'temurin'
95+
96+
# Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies.
97+
# See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md
98+
- name: Generate and submit dependency graph
99+
uses: gradle/actions/dependency-submission@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM eclipse-temurin:21-jre
2+
LABEL authors="xcodeassociated"
3+
4+
COPY ./build/libs/*.jar ./app.jar
5+
6+
EXPOSE 8082
7+
8+
ENTRYPOINT exec java $JAVA_OPTS -jar -Dspring.profiles.active=docker ./app.jar
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
spring.main.allow-bean-definition-overriding=false

0 commit comments

Comments
 (0)