-
Notifications
You must be signed in to change notification settings - Fork 0
57 lines (42 loc) · 1.57 KB
/
main.yml
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
name: CI
on:
push:
branches:
- main
jobs:
build_and_push:
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@v3
- name: Build container image
run: docker build --no-cache -t kotatsu111/yumetune:backend .
- name: Log in Docker Hub
run: docker login -u ${{ secrets.DOCKER_LOGIN }} -p ${{ secrets.DOCKER_PASSWORD }}
- name: Push image to Docker Hub
run: docker push kotatsu111/yumetune:backend
deploy:
runs-on: ubuntu-latest
if: github.event_name == 'push'
needs: build_and_push
steps:
- name: Deploy to VDS via SSH
uses: appleboy/[email protected]
with:
host: ${{ secrets.VDS_HOST }}
username: kotatsu
password: ${{ secrets.VDS_PASSWORD }}
port: 22
script: |
# Login to Docker Hub
sudo docker login -u ${{ secrets.DOCKER_LOGIN }} -p ${{ secrets.DOCKER_PASSWORD }}
# Stop running container
sudo docker stop yumetune-backend-cont
# Remove old container
sudo docker rm yumetune-backend-cont
# Remove old image
sudo docker rmi kotatsu111/yumetune:backend
# Pull from Docker Hub
sudo docker pull kotatsu111/yumetune:backend
# Run a new container from a new image
sudo docker run -d --name yumetune-backend-cont -p 8000:8000 -e POSTGRES_URL=${{ secrets.POSTGRES_URL }} -e AUTHJWT_SECRET_KEY=${{ secrets.AUTHJWT_SECRET_KEY }} kotatsu111/yumetune:backend