ECR, Docker, Tagging

I’ve been tasked (lucky me) with converting our Jenkins jobs over to Circleci. I’m very inexperienced with this, as I’m not a devops engineer, so I’m probably off on some of my fundamentals. Everything is going extremely well, but I’m getting hung-up on tagging my docker image as it moves through the workflow.

So far the image builds, is tagged correctly, and pushed to ECR. Things were working 100% until I messed with fragment caching. Once I turned that off I haven’t been able to get things working again. The problem is one of two problems:

1 - docker tag adding a new image to ecr, when I expect it just to add a tag.
or
2- docker tag complaining the image does not exist, even though it does.

This behavior persists even though I removed fragment caching from my config.yml, included below. I’m thinking I’m doing some basic thing incorrectly, and just missing it. Anyone have any ideas?

version: 2.1

orbs:
  aws-ecr: circleci/aws-ecr@7.0.0

container_config: &container_config
    machine:
      image: ubuntu-2004:202107-01
      # docker_layer_caching: true
      
jobs:
  #  Builds the Delivery image and pushes to ecr 
  build-delivery-stage:
    <<: *container_config

    steps:
      # Check's out core
      - checkout

      # Sets common files up for docker
      - run:
          name: "Copy Common into ./delivery"
          command: cp -r common delivery 

      # Builds, tags, pushes the image
      - aws-ecr/build-and-push-image:
          path: ./delivery
          no-output-timeout: 20m
          repo: delivery-circleci
          tag: "staging-candidate,${CIRCLE_SHA1}"


  # Updates image tags for deploy
  tag-images-for-deploy:
    <<: *container_config

    steps:
      - aws-ecr/ecr-login

      - run:
          name: "Update Delivery tags"
          command: |
              docker tag ${AWS_ECR_ACCOUNT_URL}/${IMAGE}:staging-candidate ${AWS_ECR_ACCOUNT_URL}/${IMAGE}:latest-stage
              docker push ${AWS_ECR_ACCOUNT_URL}/${IMAGE}:latest-stage

  # Sends Notifications requesting context deploy approval
  request-approval:
    <<: *container_config

    steps:
      - run: echo "Slack notify deploy is ready...."

  # Holds environment deploy until approved
  hold:
    <<: *container_config

    steps:
      - run: echo "Hold the staging until I say so..."

  #  Deploy the staging....
  deploy-staging:
    <<: *container_config

    steps:
      - run: echo "kubctl update delivery-stage deployment..."
      - run: echo "kubctl update integrate-stage deployment..."
      - run: echo "kubctl update gte-stage deployment..."
      - run: echo "kubctl update management-backend-stage deployment..."
      - run: echo "kubctl update management-frontend-stage deployment..."


workflows:
  #  Builds and pushes all core apps
  build-and-push-staging:
    jobs:
      - build-delivery-stage:
        filters:
          branches:
            only: develop
      - request-approval:
          name: request-approval-staging
          requires:
            - build-delivery-stage
      - hold:
          name: hold-staging
          context: 
            - core-staging
          type: approval
          requires:
            - request-approval-staging
      - tag-images-for-deploy:
          name: add-latest-stage-tags
          context: 
            - core-staging
          requires:
            - hold-staging
      - deploy-staging:
          context: 
            - core-staging
          requires:
            - hold-staging
            - add-latest-stage-tags
1 Like

I think I’ve solved my own problem, needed to perform a docker pull prior to docker tag, like so:

     - run:
          name: "Update Delivery tags"
          command: |
              docker pull ${AWS_ECR_ACCOUNT_URL}/${IMAGE}:staging-candidate
              docker tag ${AWS_ECR_ACCOUNT_URL}/${IMAGE}:staging-candidate ${AWS_ECR_ACCOUNT_URL}/${IMAGE}:latest-stage
              docker push ${AWS_ECR_ACCOUNT_URL}/${IMAGE}:latest-stage

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.