update #18
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |