Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] Github Actions Gradle, Docker Build 캐싱 #127

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .github/workflows/backend-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: backend-pull-request

on:
pull_request:
branches: [ "main", "develop" ]
branches: [ "main", "develop", "feature/#121" ]
paths:
- 'server/**'

Expand All @@ -18,14 +18,24 @@ jobs:
- name: CheckOut
uses: actions/checkout@v4

- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
uses: gradle/gradle-build-action@v2

- name: Test with Gradle Wrapper
run: ./gradlew clean build
Expand Down
23 changes: 17 additions & 6 deletions .github/workflows/backend-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: backend-push

on:
push:
branches: [ "main", "develop" ]
branches: [ "main", "develop", "feature/#121" ]
paths:
- 'server/**'

Expand All @@ -25,17 +25,27 @@ jobs:
token: ${{secrets.CONFIG_SUBMODULE_TOKEN}}
submodules: true

- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
uses: gradle/gradle-build-action@v2

- name: Test with Gradle Wrapper
run: ./gradlew test
run: ./gradlew clean build

- name: Login to Docker Hub
uses: docker/login-action@v3
Expand All @@ -48,8 +58,9 @@ jobs:

- name: Build and push
run: |
docker buildx build --platform linux/arm64 -t \
${{ secrets.DOCKER_USERNAME }}/haengdong-backend-dev --push .
docker buildx build --platform linux/arm64 --cache-from=type=registry,ref=${{ secrets.DOCKER_USERNAME }}/haengdong-backend-dev:cache \
--cache-to=type=registry,ref=${{ secrets.DOCKER_USERNAME }}/haengdong-backend-dev:cache,mode=max \
-t ${{ secrets.DOCKER_USERNAME }}/haengdong-backend-dev --push .

deploy:
needs: build
Expand All @@ -68,4 +79,4 @@ jobs:
run: sudo docker pull ${{ secrets.DOCKER_USERNAME }}/haengdong-backend-dev

- name: Docker run
run: sudo docker run -d -p 80:8080 --name haengdong-backend-dev haengdong/haengdong-backend-dev
run: sudo docker run -d -p 8080:8080 --name haengdong-backend-dev haengdong/haengdong-backend-dev
10 changes: 1 addition & 9 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
FROM gradle:7.6.1-jdk17 AS build

WORKDIR /app

COPY . /app

RUN gradle clean build -x test

FROM openjdk:17-jdk-slim

WORKDIR /app

COPY --from=build /app/build/libs/*.jar /app/haengdong-0.0.1-SNAPSHOT.jar
COPY /build/libs/*.jar /app/haengdong-0.0.1-SNAPSHOT.jar

EXPOSE 8080
ENTRYPOINT ["java"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ public class HaengdongApplication {
public static void main(String[] args) {
SpringApplication.run(HaengdongApplication.class, args);
}

}
Loading