Skip to content

Commit

Permalink
feat : 자동 배포 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
sangminee committed Nov 1, 2023
1 parent a77938a commit 296a2f9
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 140 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/gradle-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

# Workflow 이름
name: Spring Boot & Gradle CI/CD

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

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

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

# github secret 환경변수로 적어둔 APPLICATION_YML으로 application.yml파일을 생성합니다.
# 환경변수가 지나치게 많아짐을 방지하기 위해 APPLICATION_YML 변수를 만들었습니다.
- name: make application.yml
run: |
cd ./src/main/resources
touch ./application.yml
echo "${{ secrets.APPLICATION_YML }}" >> ./application.yml
shell: bash

# gradlew에 실행 권한을 부여합니다.
- name: Grant execute permisson for gradlew
run: chmod +x gradlew

# test는 CI 과정에서 수행되므로 여기서는 `-x`로 테스트를 생략했습니다.
# `--stacktrace`로 더 자세한 로그가 출력되게 해줍니다.
- name: Build with Gradle (without Test)
run: ./gradlew clean build -x test --stacktrace

# docker hub에 로그인하고 이미지를 빌드합니다. 이후에 push를 진행합니다.
# docker_username을 적지 않으면 push 시에 요청이 거부될 수 있습니다.
- name: Docker Hub build & push
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }} .
docker images
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}
# EC2에 접속하고 배포합니다.
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_KEY }}
port: ${{ secrets.EC2_SSH_PORT }}

script: |
sudo docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
sudo docker rm -f $(sudo docker ps -qa)
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}
sudo docker run -d -p 8081:8081 ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:latest
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839


# User-specific stuff
application.yml

# User-specific situff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
Expand Down
8 changes: 7 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules/UserService.iml

This file was deleted.

3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ dependencies {

//test
testImplementation 'org.springframework.boot:spring-boot-starter-test'

// Jasypt: DB 암호화
implementation 'com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.5'
}

dependencyManagement {
Expand Down
Binary file not shown.
Binary file modified build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
63 changes: 0 additions & 63 deletions src/main/resources/application-local.yml

This file was deleted.

59 changes: 0 additions & 59 deletions src/main/resources/application-prod.yml

This file was deleted.

0 comments on commit 296a2f9

Please sign in to comment.