From 940282aa24f90f316a730bdd7273f8676553ef4e Mon Sep 17 00:00:00 2001 From: Sakalya Date: Sun, 9 Jun 2024 22:29:53 +0530 Subject: [PATCH] Added dockerfile and cicd yaml --- .github/workflows/.gitkeep | 0 .github/workflows/main.yaml | 98 +++++++++++++++++++ Dockerfile | 9 ++ .../pipeline/stage_04_model_evaluation.py | 2 +- 4 files changed, 108 insertions(+), 1 deletion(-) delete mode 100644 .github/workflows/.gitkeep create mode 100644 .github/workflows/main.yaml create mode 100644 Dockerfile diff --git a/.github/workflows/.gitkeep b/.github/workflows/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..b9426e3 --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,98 @@ +name: workflow + +on: + push: + branches: + - main + paths-ignore: + - 'README.md' + +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 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e464191 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.8-slim-buster + +RUN apt update -y && apt install awscli -y +WORKDIR /app + +COPY . /app +RUN pip install -r requirements.txt + +CMD ["python3", "app.py"] \ No newline at end of file diff --git a/src/cnnClassifier/pipeline/stage_04_model_evaluation.py b/src/cnnClassifier/pipeline/stage_04_model_evaluation.py index 23324b7..ad13481 100644 --- a/src/cnnClassifier/pipeline/stage_04_model_evaluation.py +++ b/src/cnnClassifier/pipeline/stage_04_model_evaluation.py @@ -13,7 +13,7 @@ def main(self): eval_config = config.get_evaluation_config() evaluation = Evaluation(eval_config) evaluation.evaluation() - evaluation.log_into_mlflow() + # evaluation.log_into_mlflow() if __name__ == '__main__':