Skip to content

Commit

Permalink
chore: dev-aws-CI-CD.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Ogu1208 authored Aug 31, 2024
1 parent 66eee59 commit 1dc45b9
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions .github/workflows/dev-aws-CI-CD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: dev - CI/CD to Amazon ECS

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

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3

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

- 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: Grant Execute Permission For Gradlew
run: chmod +x gradlew

- name: Build With Gradle
run: ./gradlew build -x test

## build Test
- name: 테스트 코드 실행
run: ./gradlew --info test

- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
if: ${{ always() }}
with:
files: build/test-results/**/*.xml

- name: Publish Test Report
uses: mikepenz/action-junit-report@v3
if: success() || failure() # always run even if the previous step fails
with:
report_paths: '**/build/test-results/test/TEST-*.xml'

deploy:
name: Deploy
runs-on: ubuntu-latest

steps:
# 도커 컴포즈 설정 파일 서버로 전달하기(복사 후 붙여넣기)
- name: Send docker-compose.yml
uses: appleboy/scp-action@master
with:
username: ec2-user
host: ${{ secrets.AWS_DEV_HOSTNAME }}
key: ${{ secrets.AWS_DEV_PRIVATE_KEY }}
source: "./docker-compose.yml"
target: "/home/ubuntu/"

## nginx 설정 파일 서버로 전달하기(복사 후 붙여넣기)
- name: Send nginx.conf
uses: appleboy/scp-action@master
with:
username: ec2-user
host: ${{ secrets.AWS_DEV_HOSTNAME }}
key: ${{ secrets.AWS_DEV_PRIVATE_KEY }}
source: "./nginx/nginx.conf"
target: "/home/ubuntu/"

## springboot 도커 이미지 빌드 후 도커허브에 push하기
- name: Docker build & Push
env:
JASYPT_ENCRYPTOR_PASSWORD: ${{ secrets.JASYPT_ENCRYPTOR_PASSWORD }}
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t ${{ secrets.DOCKER_REPOSITORY }} . # 태그를 명시하지 않으면 :latest로 처리됨
docker push ${{ secrets.DOCKER_REPOSITORY }}
# 도커 허브에서 jar파일 및 pull후에 컴포즈 up
- name: Deploy to Dev
uses: appleboy/ssh-action@master
with:
username: ec2-user
host: ${{ secrets.AWS_DEV_HOSTNAME }}
key: ${{ secrets.AWS_DEV_PRIVATE_KEY }}
script: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:backend # 백엔드 태그 명시
sudo cp /home/ubuntu/nginx/nginx.conf /home/ubuntu/src/main/resources/backend-config/nginx/nginx.conf # 위치 확인 필요
docker-compose down
docker rmi $(docker images -q)
docker-compose up -d

0 comments on commit 1dc45b9

Please sign in to comment.