Merge pull request #28 from Leets-Official/fix/#27/게시글-좋아요-댓글-좋아요-res… #19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
# 환경별 yml 파일 생성(3) - jwt | |
- name: make application-jwt.yml | |
if: contains(github.ref, 'develop') | |
run: | | |
cd ./src/main/resources | |
touch ./application-jwt.yml | |
echo "${{ secrets.YML_JWT }}" > ./application-jwt.yml | |
shell: bash | |
# 환경별 yml 파일 생성(4) - mail | |
- name: make application-mail.yml | |
if: contains(github.ref, 'develop') | |
run: | | |
cd ./src/main/resources | |
touch ./application-jwt.yml | |
echo "${{ secrets.YML_MAIL }}" > ./application-mail.yml | |
shell: bash | |
# 환경별 yml 파일 생성(5) - oauth | |
- name: make application-oauth.yml | |
if: contains(github.ref, 'develop') | |
run: | | |
cd ./src/main/resources | |
touch ./application-oauth.yml | |
echo "${{ secrets.YML_OAUTH }}" > ./application-oauth.yml | |
shell: bash | |
# 환경별 yml 파일 생성(6) - bucket | |
- name: make application-bucket.yml | |
if: contains(github.ref, 'develop') | |
run: | | |
cd ./src/main/resources | |
touch ./application-bucket.yml | |
echo "${{ secrets.YML_BUCKET }}" > ./application-bucket.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 -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: | | |
# 기존 컨테이너 중지 및 제거 | |
if [ "$(sudo docker ps -q)" ]; then | |
sudo docker stop $(sudo docker ps -q) # 실행 중인 모든 컨테이너 중지 | |
sudo docker rm $(sudo docker ps -aq) # 중지된 모든 컨테이너 삭제 | |
fi | |
sudo docker ps | |
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/xcellent-be | |
sudo docker run -d -p 8080:8080 -e TZ=Asia/Seoul ${{ secrets.DOCKER_USERNAME }}/xcellent-be | |
sudo docker image prune -f |