-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (59 loc) · 1.92 KB
/
cicd.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
name: CI/CD
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install .
- name: Run tests
run: |
export PYTHONPATH=$PYTHONPATH:$(pwd)
pytest tests/test_stock_prediction_api.py
build-and-push:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build the Docker image
run: docker build . --file Dockerfile --tag stock-prediction-api:$(date +%s)
- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push
#uses: docker/build-push-action@v6
#with:
# push: true
# tags: ${{ secrets.DOCKERHUB_USERNAME }}/stock-prediction-api:latest
run: |
IMAGE_ID=$(docker images -q stock-prediction-api:$(date +%s))
docker --tag $IMAGE_ID ${{ secrets.DOCKERHUB_USERNAME }}/stock-prediction-api:latest
docker push ${{ secrets.DOCKERHUB_USERNAME }}/stock-prediction-api:latest
deploy:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Deploy to server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
docker pull ${{ secrets.DOCKER_USERNAME }}/stock-prediction-api:latest
docker stop stock-prediction-api || true
docker rm stock-prediction-api || true
docker run -d --name stock-prediction-api -p 8000:8000 ${{ secrets.DOCKER_USERNAME }}/stock-prediction-api:latest