Skip to content

Commit

Permalink
Merge pull request #2 from Leets-Official/feat/#1/CI/CD-구성
Browse files Browse the repository at this point in the history
[feat] #1 CI/CD 구성
  • Loading branch information
ehs208 authored Sep 23, 2024
2 parents 65dd047 + fb27ddc commit 1bc78c2
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 56 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# github repository actions 페이지에 나타날 이름
name: CI/CD using github actions & docker

# event trigger
# develop 브랜치에 push가 되었을 때 실행
on:
push:
branches: [ "develop" ]

permissions:
contents: read

jobs:
CI-CD:
runs-on: ubuntu-latest
steps:

# JDK setting - github actions에서 사용할 JDK 설정 (프로젝트나 AWS의 java 버전과 달라도 무방)
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

# gradle caching - 빌드 시간 향상
- 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-
# 환경별 yml 파일 생성(1) - application.yml
- name: make application.yml
if: |
contains(github.ref, 'develop')
run: |
mkdir ./src/main/resources # resources 폴더 생성
cd ./src/main/resources # resources 폴더로 이동
touch ./application.yml # application.yml 생성
echo "${{ secrets.YML }}" > ./application.yml # github actions에서 설정한 값을 application.yml 파일에 쓰기
shell: bash

# 환경별 yml 파일 생성(2) - dev
- name: make application-dev.yml
if: contains(github.ref, 'develop')
run: |
cd ./src/main/resources
touch ./application-dev.yml
echo "${{ secrets.YML_DEV }}" > ./application-dev.yml
shell: bash

# gradle build
- name: Build with Gradle
run: ./gradlew build -x test

# docker build & push to develop
- name: Docker build & push to dev
if: contains(github.ref, 'develop')
run: |
docker login ghcr.io -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t ${{ secrets.DOCKER_USERNAME }}/xcellent-be .
docker push ${{ secrets.DOCKER_USERNAME }}/xcellent-be
## deploy to develop
- name: Deploy to dev
uses: appleboy/ssh-action@master
id: deploy-dev
if: contains(github.ref, 'develop')
with:
host: ${{ secrets.HOST }} # EC2 퍼블릭 IPv4 DNS
username: ${{ secrets.USERNAME }} # ec-user
port: 22
key: ${{ secrets.PRIVATE_KEY }}
script: |
sudo docker ps
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/xcellent-be
sudo docker run -d -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/xcellent-be
sudo docker image prune -f
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ build/
!**/src/main/**/build/
!**/src/test/**/build/

application.yaml
application-dev.yaml
application-local.yaml


### STS ###
.apt_generated
.classpath
Expand Down
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# open jdk 17 버전의 환경을 구성
FROM openjdk:17-alpine

# build가 되는 시점에 JAR_FILE이라는 변수 명에 build/libs/*.jar 선언
# build/libs - gradle로 빌드했을 때 jar 파일이 생성되는 경로
ARG JAR_FILE=build/libs/*.jar

# JAR_FILE을 app.jar로 복사
COPY ${JAR_FILE} app.jar

# 운영 및 개발에서 사용되는 환경 설정을 분리
ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=dev", "/app.jar"]
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ plugins {
id 'org.asciidoctor.jvm.convert' version '3.3.2'
}

jar { // plain 파일 생성 방지
enabled = false
}


group = 'com.leets'
version = '0.0.1-SNAPSHOT'

Expand Down
24 changes: 0 additions & 24 deletions src/main/resources/application-dev.yaml

This file was deleted.

24 changes: 0 additions & 24 deletions src/main/resources/application-local.yaml

This file was deleted.

8 changes: 0 additions & 8 deletions src/main/resources/application.yaml

This file was deleted.

0 comments on commit 1bc78c2

Please sign in to comment.