-
Notifications
You must be signed in to change notification settings - Fork 2
60 lines (48 loc) · 1.99 KB
/
deploy.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
name: Deploy to AWS EC2 using Docker
on:
push:
branches:
- main
env:
DOCKER_IMAGE_NAME: ${{ secrets.DOCKER_IMAGE_NAME }}
EC2_HOST: ${{ secrets.EC2_HOST }}
EC2_SSH_USER: ${{ secrets.EC2_SSH_USER }}
PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
jobs:
build-and-push-docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Create .env file
run: |
echo "VITE_BASE_URL=${{ secrets.VITE_BASE_URL }}" > .env
echo "VITE_RTC_SERVER=${{ secrets.VITE_RTC_SERVER }}" >> .env
echo "VITE_AUTH_BASE_URL=${{ secrets.VITE_AUTH_BASE_URL }}" >> .env
echo "VITE_KAKAO_CLIENT_ID=${{ secrets.VITE_KAKAO_CLIENT_ID }}" >> .env
echo "VITE_KAKAO_REDIRECT_URI=${{ secrets.VITE_KAKAO_REDIRECT_URI }}" >> .env
- name: Build the Docker image
run: docker build . --file Dockerfile --tag ${{ env.DOCKER_IMAGE_NAME }}:latest
- name: Login to Docker Hub using Access Token
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: Push the Docker image
run: docker push ${{ env.DOCKER_IMAGE_NAME }}:latest
deploy-to-ec2:
needs: build-and-push-docker
runs-on: ubuntu-latest
steps:
- name: Deploy to EC2
uses: appleboy/ssh-action@master
with:
host: ${{ env.EC2_HOST }}
username: ${{ env.EC2_SSH_USER }}
key: ${{ env.PRIVATE_KEY }}
script: |
CONTAINER_ID=$(sudo docker ps -aq --filter "name=kaboo-connection-container")
if [ ! -z "$CONTAINER_ID" ]; then
sudo docker stop $CONTAINER_ID || true
sudo docker rm -f $CONTAINER_ID || true
fi
sudo docker pull ${{ env.DOCKER_IMAGE_NAME }}:latest
sudo docker run --name kaboo-connection-container -d -p 80:80 -p 3000:3000 -e TZ=Asia/Seoul ${{ env.DOCKER_IMAGE_NAME }}:latest
sudo docker image prune -f