Amazon Elastic Container Registry (ECR)

You need one repository for each application that you will deploy, with the same name as the application. The following steps describe how to create a repository and publish an image to it:

  1. Create a private repository from Amazon Container Services (ECR) console new tab. Select the region you are working in. For example: 803424716218.dkr.ecr.eu-central-1.amazonaws.com/shopping-cart-service

  2. Authenticate Docker using the first part of the URI, for example:

    aws ecr get-login-password --region eu-central-1 | docker login \
       --username AWS \
       --password-stdin 803424716218.dkr.ecr.eu-central-1.amazonaws.com
  3. Build the Docker image and publish to ECR with the following (The build.sbt and project/plugins.sbt pom.xml contains build plugin settings for building a Docker image.):

    Java
    mvn -DskipTests \
        -Ddocker.registry=803424716218.dkr.ecr.eu-central-1.amazonaws.com \
          clean package docker:push
    Scala
    sbt -Ddocker.registry=803424716218.dkr.ecr.eu-central-1.amazonaws.com \
          docker:publish

The version number of the image is derived from the git commit. If you see error "Given Docker name 'shopping-cart-service:${git.commit.time}-${git.commit.id.abbrev}' is invalid" it is because the directory is not a git repository. You can enable git for the directory with the following commands.

git init
git add .
git commit -m "some descriptive commit message"

Alternatively the version can be specified with -Dversion.number=0.1-SNAPSHOT.

mvn -Dversion.number=0.1-SNAPSHOT -DskipTests -Ddocker.registry=803424716218.dkr.ecr.eu-central-1.amazonaws.com clean package docker:push

The version number of the image, as well as from the project itself, is derived from the git commit using sbt-dynver new tab. If your project is not being versioned with git, you will see a fixed version number (eg: HEAD-20210119-1515). You can enable git for the directory with the following commands.

git init
git add .
git commit -m "some descriptive commit message"

Alternatively you can add the version to your build.sbt file and maintain it manually.

version := "1.0.0"