0

I am completely new to DevOps. I have coded a few Django apps and I have been able to put them in production using Docker with nginx and uwsgi.

The structure is

-app/
--manage.py
-proxy/
--Dockerfile
-scripts/
-docker-compose-deploy.yml
-Dockerfile

Mainly I followed this tutorial. What I am trying to do is to set a sort of pipeline that for every time my GitHub repo is pushed, my code is updated in AWS.

I am using GitHub Actions for this purpose and I managed to see my image updated to ECR using this yaml file under .github/workflows:

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

name: Django Project 'app' CI on ECR

jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest

    steps:
    - name: Checkout
      uses: actions/checkout@v2

    - 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: eu-west-3 

    - 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: appecr
        IMAGE_TAG: latest
      run: |
        # Build a docker container and push it to ECR 
        docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
        echo "Pushing image to ECR..."
        docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
        echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"

What I don't know is 2 things: 1- is this correct considering that for doing it manually I do git pull in my EC2 instance and then
docker-compose -f docker-compose-deploy.yml build app
docker-compose -f docker-compose-deploy.yml up --no-deps -d app

2- how can I connect my ecr updates to my ec2 instance?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.