I’m trying to create a pipeline with either ECS or ECR, but currently not able to.
Using ECS
I’ve followed the instruction here https://docs.gitlab.com/ee/ci/cloud_deployment, I was able to build the docker image and push it on GitLab’s registry but in the build stage I got: The command '/bin/sh -c /bin/herokuish buildpack build' returned a non-zero code: 1
Using ECR
I’m attaching my script below, which is also the one I use in step 1 but slightly modified:
The problem with this approach is that aws cli is not properly configured. Here’s the error:
$ aws --version
/bin/sh: eval: line 118: aws: not found
ERROR: Job failed: exit code 127
Does somebody have a decent pipeline on how to deploy into Amazon EC2 from GitLab? I’m building a Java project, specifically using Quarkus framework.
This build and push your Docker image to ECR: you need to configure in the secret variables of the project AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. Kaniko will automatically login for you.
After you are able to push your Docker image to ECR we can talk about how to deploy it, but I need to understand if you want to use ECS or something else.
ECS backed by EC2 instead of Fargate?
-> Yes, this is what I’m trying to do. But since I’m not able to make it work I also tried the one in the documentation which uses GitLab’s image registry to update AWS ECS.
My goal is to deploy a Java app to an EC2 instance. My plan is to build a docker image in GitLab, push it on ECR, and trigger ECS to republish by fetching the updated Docker image from ECR and deploy it on EC2.
–
I am now able to successfully deploy to AWS ECR. I can deploy the ECR image when I stop the running ECS task first before I commit the project. Can you help me automate this process?
This works because we tagged the Docker image on ECR with CI_COMMIT_SHORT_SHA as tag. The script will create a new revision of the ECS task using as Docker image the image with tag CI_COMMIT_SHORT_SHA.
Of course this is only a basic example, let me know if you need any detail on how to create a proper deployment over ECS with a clear shutdown of the task and so on. But on the Gitlab side this should be everything.