Skip to content

Commit 0b82324

Browse files
authored
Merge pull request #48 from Team-StudyLog/develop
CICD 워크플로우 적용
2 parents f4a484d + 6418e23 commit 0b82324

2 files changed

Lines changed: 87 additions & 14 deletions

File tree

.github/workflows/CICD.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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: CICD
9+
10+
on:
11+
push:
12+
branches: [ "main" ]
13+
pull_request:
14+
branches: [ "main" ]
15+
16+
jobs:
17+
build:
18+
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
23+
steps:
24+
- uses: actions/checkout@v4
25+
- name: Set up JDK 17
26+
uses: actions/setup-java@v4
27+
with:
28+
java-version: '17'
29+
distribution: 'temurin'
30+
31+
- name: Setup Gradle
32+
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
33+
34+
- name: Grant execute permission for gradlew
35+
run: chmod +x gradlew
36+
37+
- name: Build with Gradle Wrapper
38+
run: ./gradlew build -x test
39+
40+
- name: Login to DockerHub
41+
uses: docker/login-action@v2
42+
with:
43+
username: ${{ secrets.DOCKERHUB_USERNAME }}
44+
password: ${{ secrets.DOCKERHUB_TOKEN }}
45+
46+
- name: Build Docker
47+
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/studylog_server .
48+
- name: Push Docker
49+
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/studylog_server:latest
50+
51+
dependency-submission:
52+
53+
runs-on: ubuntu-latest
54+
permissions:
55+
contents: write
56+
57+
steps:
58+
- uses: actions/checkout@v4
59+
- name: Set up JDK 17
60+
uses: actions/setup-java@v4
61+
with:
62+
java-version: '17'
63+
distribution: 'temurin'
64+
65+
- name: Generate and submit dependency graph
66+
uses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
67+
68+
deploy:
69+
needs: build
70+
runs-on: ubuntu-latest
71+
72+
steps:
73+
- name: Docker compose
74+
uses: appleboy/ssh-action@v0.1.6
75+
with:
76+
username: ubuntu
77+
host: ${{ secrets.EC2_HOST }}
78+
key: ${{ secrets.EC2_SSH_KEY }}
79+
port: 22
80+
timeout: 60s
81+
script: |
82+
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/studylog_server:latest
83+
sudo docker compose -f /home/ubuntu/project/compose.yml up -d

Dockerfile

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
# build
2-
FROM eclipse-temurin:17-jdk-alpine AS build
3-
WORKDIR /app
4-
COPY gradlew gradle/ build.gradle settings.gradle ./
5-
RUN chmod +x gradlew && ./gradlew --version
6-
COPY src src
7-
RUN ./gradlew bootJar --no-daemon
8-
9-
# run
10-
FROM eclipse-temurin:17-jre-alpine
11-
WORKDIR /app
12-
COPY --from=build /app/build/libs/*.jar app.jar
13-
EXPOSE 8080
14-
ENTRYPOINT ["java","-jar","/app/app.jar"]
1+
FROM openjdk:17-jdk
2+
ARG JAR_FILE=build/libs/*.jar
3+
COPY ${JAR_FILE} studylog.jar
4+
ENTRYPOINT ["java", "-Dspring.profiles.active=docker", "-jar", "studylog.jar"]

0 commit comments

Comments
 (0)