0
votes

I am working with Azure DevOps build and release pipelines to deploy a containerised .NET Core application. Previously, the image repo has been Docker Hub and the deployment system has been an on-premise Kubernetes cluster. However, now we are shifting to AWS, and we're looking at using ECR and EKS.

In my current pipelines, the build pipeline builds and pushes the container image to Docker Hub, and the release pipeline uses the DockerHub image artifact as its source, which all works nicely.

However, while there is an ECR build step in the Azure marketplace, I can't see a way of setting up ECR as an artifact source. Has anyone been able to solve this? Or should I just package up the DLLs and JSON settings as a build artifact, and then have a Dockerfile that takes those files and builds the image at the start of the release step (so I still am deploying a single image and then promoting to different environments)?

1

1 Answers

0
votes

You don't have to specify actually any artifact here. What you actually should do is build Docker image and then push it to ECR. Later on deployment stages you just need to reuse that image. Here is a good tutorial how to push image to ECR:

trigger:
  branches:
    include:
    - master

pool:
  vmImage: 'ubuntu-latest'

variables:
  - group: dev
  - name: DOCKER_REPOSITORY
    value: $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/$(DOCKER_REPOSITORY_NAME)

steps:
- script: |
    aws ecr get-login-password --region $(AWS_REGION) | docker login --username AWS --password-stdin $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com
  displayName: 'Login to AWS'
  env:
    AWS_ACCESS_KEY_ID: $(AWS_ACCESS_KEY_ID)
    AWS_SECRET_ACCESS_KEY: $(AWS_SECRET_ACCESS_KEY)

- task: Docker@2
  displayName: Build docker image
  inputs:
    repository: $(DOCKER_REPOSITORY)
    command: buildAndPush
    Dockerfile: Dockerfile
    tags: |
      latest