-
Notifications
You must be signed in to change notification settings - Fork 0
72 lines (60 loc) · 1.95 KB
/
build-test-deploy.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
name: Build,Test and Deploy
on:
push:
branches: [ main ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
environment:
name: 'Production'
defaults:
run:
working-directory: .
steps:
- name: Checkout Source Code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.10'
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
build-docker-image:
needs: [ build ]
runs-on: ubuntu-latest
defaults:
run:
working-directory: .
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Build docker image
run: docker build -t ${{secrets.DOCKER_USERNAME}}/hyobot .
- name: Log into Docker and upload image
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin
docker push ${{secrets.DOCKER_USERNAME}}/hyobot
deploy:
needs: [ build, build-docker-image ]
environment:
name: 'Production'
runs-on: ubuntu-latest
steps:
- name: SSH into VPS, pull docker image and run the image
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.PROD_SSH_HOST }}
username: ${{ secrets.PROD_SSH_USER }}
password: ${{ secrets.VPS_PASSWORD }}
script: |
echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
docker stop HyoBot
docker rm HyoBot
docker pull ${{ secrets.DOCKER_USERNAME }}/hyobot:latest
docker run -d --restart=always --name HyoBot --env-file ${{ secrets.SECRET_PATH }} ${{ secrets.DOCKER_USERNAME }}/hyobot:latest