Resolved bugs in Dockerfile #13
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 Pipeline | |
on: push | |
jobs: | |
test-and-package: | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout code | |
uses: actions/checkout@v3 | |
- name: setup python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.10' | |
- name: Cache pip dependencies | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: install dependencies | |
run: | | |
pip install -r requirements.txt | |
- name: run pipeline | |
env: | |
DAGSHUB_PAT: ${{ secrets.DAGSHUB_PAT }} | |
run: | | |
dvc repro | |
- name: Run model tests | |
env: | |
DAGSHUB_PAT: ${{ secrets.DAGSHUB_PAT }} | |
run: | | |
python -m unittest tests/test_model.py | |
- name: Promote model to production | |
if: success() | |
env: | |
DAGSHUB_PAT: ${{ secrets.DAGSHUB_PAT }} | |
run: python scripts/promote_model.py | |
- name: Run Flask app tests | |
if: success() | |
env: | |
DAGSHUB_PAT: ${{ secrets.DAGSHUB_PAT }} | |
run: python -m unittest tests/test_flask_app.py | |
- name: Login to AWS ECR | |
run: | | |
aws configure set aws_access_key_id ${{secrets.AWS_ACCESS_KEY_ID }} | |
aws configure set aws_secret_access_key ${{secrets.AWS_SECRET_ACCESS_KEY }} | |
aws ecr get-login-password --region eu-north-1 | docker login --username AWS --password-stdin 843369994444.dkr.ecr.eu-north-1.amazonaws.com | |
- name: Build Docker Image | |
run: | | |
docker build -t text-classification . | |
- name: Tag Docker Image | |
run: | | |
docker tag text-classification:latest 843369994444.dkr.ecr.eu-north-1.amazonaws.com/text-classification:latest | |
- name: Push Docker Image to AWS ECR | |
run: | | |
docker push 843369994444.dkr.ecr.eu-north-1.amazonaws.com/text-classification:latest | |
Deploy-to-EC2: | |
runs-on: ubuntu-latest | |
needs: test-and-package | |
steps: | |
- name: Deploy to EC2 | |
uses: appleboy/ssh-action@v0.1.5 | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USER }} | |
key: ${{ secrets.EC2_SSH_KEY }} | |
script: | | |
aws configure set aws_access_key_id ${{secrets.AWS_ACCESS_KEY_ID }} | |
aws configure set aws_secret_access_key ${{secrets.AWS_SECRET_ACCESS_KEY }} | |
aws configure set default.region eu-north-1 | |
aws ecr get-login-password --region eu-north-1 | docker login --username AWS --password-stdin 843369994444.dkr.ecr.eu-north-1.amazonaws.com | |
docker pull 843369994444.dkr.ecr.eu-north-1.amazonaws.com/text-classification:latest | |
docker stop text-classification || true | |
docker rm text-classification || true | |
docker run -d -p 80:5000 -e DAGSHUB_PAT=${{ secrets.DAGSHUB_PAT }} --name text-classification 843369994444.dkr.ecr.eu-north-1.amazonaws.com/text-classification:latest |