Skip to content

Commit

Permalink
Merge pull request #30 from TUK-DP/chore/29
Browse files Browse the repository at this point in the history
[chore] hotfix workflow 작성
  • Loading branch information
Leewonchan14 authored Mar 5, 2024
2 parents a2dd9de + 31f6c75 commit 8ed59c4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ jobs:
sudo echo "${{ secrets.DOT_ENT }}" > .env
sudo docker rm -f ${{ secrets.REPOSITORY_NAME }} || true
sudo docker rmi -f ${{ secrets.DOCKER_USERNAME }}/${{ secrets.REPOSITORY_NAME }}:latest || true
sudo docker run -d --name ${{ secrets.REPOSITORY_NAME }} -p 8001:8000 --env-file .env ${{ secrets.DOCKER_USERNAME }}/${{ secrets.REPOSITORY_NAME }}:latest
sudo docker-compose up -d
50 changes: 50 additions & 0 deletions .github/workflows/hotfix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build And Deploy

on:
push:
branches:
- main

jobs:
hotfix:
# push 이벤트가 발생했을 때만 실행
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Docker login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Docker Build and Push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.REPOSITORY_NAME }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Deploy to EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ubuntu
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
sudo sh -c 'truncate -s 0 /var/lib/docker/containers/*/*-json.log'
cd ~/${{ secrets.REPOSITORY_NAME }}
sudo echo "${{ secrets.DOT_ENT }}" > .env
sudo docker rm -f ${{ secrets.REPOSITORY_NAME }} || true
sudo docker rmi -f ${{ secrets.DOCKER_USERNAME }}/${{ secrets.REPOSITORY_NAME }}:latest || true
sudo docker run -d --name ${{ secrets.REPOSITORY_NAME }} -p 8001:8000 --env-file .env ${{ secrets.DOCKER_USERNAME }}/${{ secrets.REPOSITORY_NAME }}:latest
sudo docker exec ${{ secrets.REPOSITORY_NAME }} python3 manage.py migrate

0 comments on commit 8ed59c4

Please sign in to comment.