Quantcast
Channel: Active questions tagged amazon-ec2 - Stack Overflow
Viewing all articles
Browse latest Browse all 29544

EC2 connected to ECS/ECR not updating with new docker image [duplicate]

$
0
0

I have a docker yaml using github workflows, it pushes up a docker image to the ECR, and then the yaml file automatically updates my ECS service to use that docker image. I am certain that the ECS is being updated correctly because when I push to main on github, I see the old service scale down and the new instance scale up. However, the EC2 which runs my web application, doesn't seem to get updated, it continues to use the old docker image and thus old code, how can I make it so it uses the latest image from the ECS service when I push to main?

When I go and manually reboot the ec2 instance, the new code from main is there but I have to manually reboot which obviously causes downtime, & I don't want to have to manually reboot it. My EC2 instance is running an NPM and vite web application.

Here is my .yaml file for my github workflow

name: Deploy to AWS ECRon:  push:    branches:      - main jobs:  build-and-push:    runs-on: ubuntu-latest    steps:    - name: Checkout code      uses: actions/checkout@v2    - name: Get Git commit hash      id: git_hash      run: echo "::set-output name=hash::$(git rev-parse --short HEAD)"    - name: Configure AWS credentials      uses: aws-actions/configure-aws-credentials@v1      with:        aws-access-key-id: ${{ secrets.AWS_KEY_ID }}        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}        aws-region: us-east-2    - name: Login to Amazon ECR      uses: aws-actions/amazon-ecr-login@v2    - name: Build, tag, and push image to Amazon ECR      run: |        docker build -t dummy/repo:latest .        docker tag dummy/repo:latest ###.dkr.ecr.us-east-2.amazonaws.com/dummy/repo:latest        docker push ###.dkr.ecr.us-east-2.amazonaws.com/dummy/repo:latest    - name: Update ECS service      env:        AWS_REGION: us-east-2        CLUSTER_NAME: frontend        SERVICE_NAME: dummy/repo      run: |        aws ecs update-service --cluster $CLUSTER_NAME --service $SERVICE_NAME --force-new-deployment --region $AWS_REGION

Here is the task definition JSON used by the cluster service

{"family": "aguacero-frontend","containerDefinitions": [        {"name": "aguacero-frontend","image": "###.dkr.ecr.us-east-2.amazonaws.com/dummy/repo:latest","cpu": 1024,"memory": 512,"memoryReservation": 512,"portMappings": [                {"name": "aguacero-frontend-4173-tcp","containerPort": 4173,"hostPort": 4173,"protocol": "tcp","appProtocol": "http"                }            ],"essential": true,"environment": [                {"name": "VITE_HOST_URL","value": "http://0.0.0.0:8081"                }            ],"mountPoints": [],"volumesFrom": [],"logConfiguration": {"logDriver": "awslogs","options": {"awslogs-group": "/ecs/aguacero-frontend","awslogs-create-group": "true","awslogs-region": "us-east-2","awslogs-stream-prefix": "ecs"                }            },"systemControls": []        }    ],"taskRoleArn": "arn:aws:iam::###:role/ecsTaskExecutionRole","executionRoleArn": "arn:aws:iam::###:role/ecsTaskExecutionRole","networkMode": "awsvpc","requiresCompatibilities": ["EC2"    ],"cpu": "1024","memory": "512","runtimePlatform": {"cpuArchitecture": "X86_64","operatingSystemFamily": "LINUX"    }}

Pushing to github to build the docker image on the ECR works, as well as the refreshing and updating of the ECS service to use the latest tag from the ECR, but those changes aren't propagated to the EC2 instance that the ECS service is connected to.


Viewing all articles
Browse latest Browse all 29544

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>