Merge pull request #31 from dnd-side-project/feat/ddd #71
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
name: CD - Deploy to AWS by docker | |
on: | |
push: | |
branches: | |
- develop | |
- 'fix/**' | |
# 권한 설정 | |
permissions: | |
contents: read | |
jobs: | |
CD: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v1 | |
with: | |
java-version: 17 | |
# 환경 변수 설정 | |
- name: Set up Environment | |
run: echo "${{ secrets.ENV_PROPERTIES }}" > ./.env | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./gradlew | |
shell: bash | |
# 빌드 | |
- name: Build with Gradle | |
run: ./gradlew clean bootJar | |
#빌드 후 도커 허브로 push | |
- name: Docker Build & Push to Hub | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }} -f ./.docker/Dockerfile . | |
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }} | |
# 환경 변수 파일 서버로 전달하기(복사 후 붙여넣기) | |
- name: Send env file | |
uses: appleboy/scp-action@master | |
with: | |
username: ec2-user | |
host: ${{ secrets.EC2_HOST }} | |
key: ${{ secrets.EC2_PRIVATE_KEY }} | |
source: "./.env" | |
target: "/home/ec2-user" | |
# 도커 컴포즈 설정 파일 서버로 전달하기(복사 후 붙여넣기) | |
- name: Send docker-compose.yml | |
uses: appleboy/scp-action@master | |
with: | |
username: ec2-user | |
host: ${{ secrets.EC2_HOST }} | |
key: ${{ secrets.EC2_PRIVATE_KEY }} | |
port: 22 | |
source: "./.docker/docker-compose.yml" | |
target: "/home/ec2-user" | |
# deploy.sh 파일 서버로 전달하기(복사 후 붙여넣기) | |
- name: Send deploy.sh | |
uses: appleboy/scp-action@master | |
with: | |
username: ec2-user | |
host: ${{ secrets.EC2_HOST }} | |
key: ${{ secrets.EC2_PRIVATE_KEY }} | |
port: 22 | |
source: "./script/deploy.sh" | |
target: "/home/ec2-user" | |
# 도커 컴포즈 실행하기 | |
# 도커 허브에서 jar파일 및 pull후에 컴포즈 up | |
- name: Deploy to Dev | |
uses: appleboy/ssh-action@master | |
with: | |
username: ec2-user | |
host: ${{ secrets.EC2_HOST }} | |
key: ${{ secrets.EC2_PRIVATE_KEY }} | |
script: | | |
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }} | |
chmod 777 ./script/deploy.sh | |
./script/deploy.sh | |
docker image prune -f |