replace ecr with dockerhub - bugfixes #35
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
# .github/workflows/cicd.yml | |
# - push to ECR --- done | |
# - Run the container on EC2/ECS --- | |
name: cicd pipeline | |
on: | |
push: | |
branches: | |
- main | |
paths: # if any changes detected in below dir then runner'll trigger cicd pipeline | |
- ./src/** | |
- .github/** | |
- ./prod/** | |
- Dockerfile | |
- docker_requirements.txt | |
pull_request: | |
branches: | |
- main | |
jobs: | |
pull-latest-model: | |
name: pull latest prod model | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v2 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
- name: Install Utilities # install utilities required to fetch model from backend | |
run: | | |
python -m pip install --upgrade pip | |
if [ -f model_requirements.txt ]; then pip install -r model_requirements.txt; fi | |
- name: Pull Latest Model From Mlflow # below script will executed and fetch the prod model | |
run: | | |
python ./prod/mlflowdb.py ${{ secrets.TRACKING_URI }} | |
- name: Upload Model Artifact # save the artifacts so that we can utilise it in next stage | |
uses: actions/upload-artifact@v2 | |
with: | |
name: model | |
# in path give correct repository name as here "cicd-aws/cicd-aws" | |
path: | | |
/home/runner/work/cicd-aws/cicd-aws/model.joblib | |
/home/runner/work/cicd-aws/cicd-aws/model_details.json | |
- name: Print Current Directory # for debuging purpoer, u can remove it | |
run: ls /home/runner/work/cicd-aws/cicd-aws | |
build-nd-push-docker-image: | |
name: build & push img to dockerhub | |
needs: pull-latest-model # previous stage must be successfully completed (job dependency) | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Print Current Directory be-down # for debug purpose | |
run: ls /home/runner/work/cicd-aws/cicd-aws | |
- name: Download Model Artifacts # download the previously saved artifacts | |
uses: actions/download-artifact@v2 | |
with: | |
name: model | |
path: /home/runner/work/cicd-aws/cicd-aws | |
- name: Print Current Directory af-down # for debugging | |
run: ls /home/runner/work/cicd-aws/cicd-aws | |
# push img to docker hub | |
- name: Build Docker Image | |
run: | | |
docker build -t ${{ secrets.DOCKER_USERNAME }}/wineqcicdaws:latest . | |
- name: Log-in to Docker Hub | |
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
- name: Push Docker Img # push the previously built img to dockerhub | |
run: docker push ${{ secrets.DOCKER_USERNAME }}/wineqcicdaws:latest | |
continuous-deployment: | |
name: continuous deployment | |
runs-on: self-hosted | |
# runs-on: ubuntu-latest | |
needs: build-nd-push-docker-image | |
steps: | |
- name: pull latest image from docker hub | |
run: | | |
docker image pull ${{ secrets.DOCKER_USERNAME }}/wineqcicdaws:latest | |
- name: Print docker images # for debugging | |
run: docker images | |
- name: Delete Previous Container | |
run: | | |
docker rm -f awscicd || true | |
- name: Run Docker Image to Serve Users | |
run: | | |
docker run -d -p 8082:8000 -ti --name awscicd ${{ secrets.DOCKER_USERNAME }}/wineqcicdaws:latest |