Feat/#53: 깃허브 액션으로 배포 자동화 구현하기 #6
Workflow file for this run
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: Deploy Workflow | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- '**' | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: docker image build | |
run: docker build -t ${{ secrets.DOCKER_REGISTRY }}/${{ secrets.DOCKER_IMAGE_NAME }} . | |
- name: docker hub login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PW }} | |
- name: docker hub publish | |
run: docker push ${{ secrets.DOCKER_REGISTRY }}/${{ secrets.DOCKER_IMAGE_NAME }} | |
- name: connect EC2 Instance | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.REMOTE_IP }} | |
username: ${{ secrets.REMOTE_USER }} | |
key: ${{ secrets.REMOTE_PRIVATE_KEY }} | |
script: | | |
docker stop $(docker ps -a -q) | |
docker rm $(docker ps -a -q) | |
docker pull ${{ secrets.DOCKER_REGISTRY }}/${{ secrets.DOCKER_IMAGE_NAME }} | |
docker run -d -p 8080:8080 --env-file ./sec/.env --name burimi-back ${{ secrets.DOCKER_REGISTRY }}/${{ secrets.DOCKER_IMAGE_NAME }} |