🔧 Settings: [#24] CI / CD 구축
This commit is contained in:
52
.github/workflows/workflow.yml
vendored
Normal file
52
.github/workflows/workflow.yml
vendored
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
name: CI/CD Pipeline
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- dev
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
# 코드 체크아웃
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
# 더 나은 도커 빌드 환경 세팅
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v1
|
||||||
|
|
||||||
|
# DockerHub 로그인
|
||||||
|
- name: Login to DockerHub
|
||||||
|
uses: docker/login-action@v1
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
|
||||||
|
|
||||||
|
- name: Build and push Docker image
|
||||||
|
uses: docker/build-push-action@v2
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: Dockerfile
|
||||||
|
push: true
|
||||||
|
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO }}:latest
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: build
|
||||||
|
|
||||||
|
steps:
|
||||||
|
# AWS 배포
|
||||||
|
- name: SSH to EC2 and deploy
|
||||||
|
uses: appleboy/ssh-action@v0.1.3
|
||||||
|
with:
|
||||||
|
host: ${{ secrets.EC2_HOST }}
|
||||||
|
username: ${{ secrets.EC2_USER }}
|
||||||
|
key: ${{ secrets.EC2_SSH_KEY }}
|
||||||
|
script: |
|
||||||
|
docker compose stop ${{ secrets.DOCKER_HUB_REPO }}
|
||||||
|
docker compose rm ${{ secrets.DOCKER_HUB_REPO }}
|
||||||
|
docker rmi ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO }}:latest
|
||||||
|
docker compose up -d
|
||||||
Reference in New Issue
Block a user