Skip to content

Commit

Permalink
chore: ci / cd 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
iampingu99 committed Jul 15, 2024
1 parent 5543166 commit f72b59c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Java CI with Gradle

on:
push:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
# 1. checkout
- uses: actions/checkout@v3

# 2. Java 17 설정
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

# 3. properties 설정
- name: Set up application.yml
run: |
mkdir -p src/main/resources
echo "${{ secrets.APPLICATION }}" > src/main/resources/application.yml
# 4. gradlew build
- name: Build with Gradle
uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0
with:
arguments: build

# 5. Docker 이미지 빌드
- name: docker image build
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/project-backend .

# 6. DockerHub 로그인
- name: docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

# 7. Docker Hub 이미지 푸시
- name: docker Hub push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/project-backend

# 8. EC2 pull
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
script: |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/holing-was
docker run -d -p 8080:8080 ${{ secrets.DOCKERHUB_USERNAME }}/holing-was
2 changes: 0 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Java CI with Gradle

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

Expand Down
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM openjdk:17-alpine

CMD ["java","-jar","/build/libs/holing-0.0.1-SNAPSHOT.jar"]

COPY ./build/libs/holing-0.0.1-SNAPSHOT.jar /build/libs/holing-0.0.1-SNAPSHOT.jar

0 comments on commit f72b59c

Please sign in to comment.