Skip to content

Commit

Permalink
Feat: (github actions) create deploy.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
anandashin authored Jan 1, 2025
1 parent 260874f commit d03c1c4
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: deploy to EC2 using docker

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
types: [closed] # PR이 닫힐 때(머지 포함)


env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
DOCKER_REPO: ${{ secrets.DOCKER_REPO }}
AWS_HOST: ${{ secrets.AWS_HOST }}
AWS_SSH_KEY: ${{ secrets.AWS_SSH_KEY }}
AWS_USER: ${{ secrets.AWS_USER }}
AWS_SSH_PORT: ${{ secrets.AWS_SSH_PORT }}


jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3 # 레포에 있는 코드를 actions 작업환경으로 가져오기

- name: Login to Docker Hub
run: |
docker login -u ${{ env.DOCKER_HUB_USERNAME }} -p ${{ env.DOCKER_HUB_ACCESS_TOKEN }}
- name: Build and push Docker image
run: |
docker build . -t ${{ env.DOCKER_REPO }}:latest
docker push ${{ env.DOCKER_REPO }}:latest
deploy:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3

- name: EC2 Docker Deploy
uses: appleboy/[email protected]
with:
host: ${{ env.AWS_HOST }}
username: ${{ env.AWS_USER }}
key: ${{ env.AWS_SSH_KEY }}
port: ${{ env.AWS_SSH_PORT }}
script: |
cd watchapedia/
sudo docker compose down
sudo docker compose pull
sudo docker compose up -d

0 comments on commit d03c1c4

Please sign in to comment.