Skip to content

update

update #7

Workflow file for this run

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: |
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.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push to Docker Hub
run: |
IMAGE_ID=$(docker images -q stock-prediction-api:$(date +%s))
docker tag $IMAGE_ID ${{ secrets.DOCKER_USERNAME }}/stock-prediction-api:latest
docker push ${{ secrets.DOCKER_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