Hello there!
You are talking about a lot of different AWS technologies there, so I am not really sure where you want to start from:
- ECR is to store your docker images
- ECS is to run your docker images
- EC2 is the computing service - do you want to use ECS backed by EC2 instead of Fargate?
Anyhow, I can suggest how to build the docker image for ECR. First, I suggest to use kaniko, makes a lot easier to manage the whole thing.
The .gitlab-ci.yml then can be something like this:
buildDocker:
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
stage: build
variables:
REGISTRY: xxx.dkr.ecr.us-east-2.amazonaws.com/quarkus-cognito
only:
- master
when: manual
script:
# see https://github.com/GoogleContainerTools/kaniko/issues/1227
- mkdir -p /kaniko/.docker
- echo "{\"credsStore\":\"ecr-login\"}" > /kaniko/.docker/config.json
- /kaniko/executor --cache=true --dockerfile Dockerfile --destination $REGISTRY:$CI_COMMIT_SHORT_SHA --destination $REGISTRY:latest
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.