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/README.md b/README.md index 78ad36a..3ae36cf 100644 --- a/README.md +++ b/README.md @@ -47,3 +47,95 @@ dvc dag ``` +### About MLflow & DVC +MLflow + +* Its Production Grade +* Trace all of your expriements +* Logging & taging your model + + +DVC + +* Its very lite weight for POC only +* lite weight expriements tracker +* It can perform Orchestration (Creating Pipelines) + + + +### AWS-CICD-Deployment-with-Github-Actions +##### 1. Login to AWS console. + +##### 2. Create IAM user for deployment +``` +#with specific access + +1. EC2 access : It is virtual machine + +2. ECR: Elastic Container registry to save your docker image in aws + + +#Description: About the deployment + +1. Build docker image of the source code + +2. Push your docker image to ECR + +3. Launch Your EC2 + +4. Pull Your image from ECR in EC2 + +5. Lauch your docker image in EC2 + +#Policy: + +1. AmazonEC2ContainerRegistryFullAccess + +2. AmazonEC2FullAccess + +``` + +##### 3. Create ECR repo to store/save docker image +``` +- Save the URI: 566373416292.dkr.ecr.us-east-1.amazonaws.com/chicken +``` + +##### 4. Create EC2 machine (Ubuntu) + +##### 5. Open EC2 and Install docker in EC2 Machine: +``` +#optinal + +sudo apt-get update -y + +sudo apt-get upgrade + +#required + +curl -fsSL https://get.docker.com -o get-docker.sh + +sudo sh get-docker.sh + +sudo usermod -aG docker ubuntu + +newgrp docker +``` + +##### 6. Configure EC2 as self-hosted runner: +``` +setting>actions>runner>new self hosted runner> choose os> then run command one by one +``` + + +##### 7. Setup github secrets: +``` +AWS_ACCESS_KEY_ID= + +AWS_SECRET_ACCESS_KEY= + +AWS_REGION = us-east-1 + +AWS_ECR_LOGIN_URI = demo>> 566373416292.dkr.ecr.ap-south-1.amazonaws.com + +ECR_REPOSITORY_NAME = simple-app +``` diff --git a/inputImage.jpg b/inputImage.jpg index f549eb9..292294d 100644 Binary files a/inputImage.jpg and b/inputImage.jpg differ