Skip to content

Commit

Permalink
deployment code
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinKalema committed May 10, 2024
1 parent 67ba0e9 commit d0c8e6f
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 68 deletions.
Empty file removed .github/workflows/.gitkeep
Empty file.
96 changes: 96 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# This workflow triggers on every push to the main branch, excluding changes to the README.md file
name: workflow
on:
push:
branches:
- main
paths-ignore:
- 'README.md'
# Grants permissions to read repository contents and write identity tokens
permissions:
id-token: write
contents: read

jobs:
integration:
name: Continuous Integration
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Lint code
run: echo "Linting repository"

- name: Run unit tests
run: echo "Running unit tests"

build-and-push-ecr-image:
name: Continuous Delivery
needs: integration
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Install Utilities
run: |
sudo apt-get update
sudo apt-get install -y jq unzip
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
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: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY_NAME }}
IMAGE_TAG: latest
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
Continuous-Deployment:
needs: build-and-push-ecr-image
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
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: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Pull latest images
run: |
docker pull ${{secrets.AWS_ECR_LOGIN_URI}}/${{ secrets.ECR_REPOSITORY_NAME }}:latest
# - name: Stop and remove container if running
# run: |
# docker ps -q --filter "name=cnncls" | grep -q . && docker stop cnncls && docker rm -fv cnncls

- name: Run Docker Image to serve users
run: |
docker run -d -p 8080:8080 --name=cnncls -e 'AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}' -e 'AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}' -e 'AWS_REGION=${{ secrets.AWS_REGION }}' ${{secrets.AWS_ECR_LOGIN_URI}}/${{ secrets.ECR_REPOSITORY_NAME }}:latest
- name: Clean previous images and containers
run: |
docker system prune -f
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ pytest test/test_file_name.py

## AWS CI/CD Deployment with Github Actions

<img src="static/deployment.png"/>

- Login to the AWS console
- Create an IAM user for deployment
- The user should have EC2 & ECR access. The deployment steps are mentioned below,
Expand Down
2 changes: 1 addition & 1 deletion config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ prepare_base_model:

training:
root_dir: artifacts/training
trained_model_path: artifacts/training/model.h5
trained_model_path: model/model.h5

model_evaluation:
mlflow_tracking_uri: https://dagshub.com/kalema3502/MIIA-Pothole-Image-classification.mlflow
Expand Down
67 changes: 0 additions & 67 deletions flask.py

This file was deleted.

Binary file added static/deployment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d0c8e6f

Please sign in to comment.