CircleCI-Public / aws-ecr-orb

CircleCI orb for interacting with Amazon's Elastic Container Registry (ECR)
https://circleci.com/orbs/registry/orb/circleci/aws-ecr
MIT License
80 stars 142 forks source link

extra-build-args seems broken in 8.2.1 #269

Closed swiknaba closed 1 year ago

swiknaba commented 1 year ago

Orb version

8.2.1

What happened

See issue https://github.com/CircleCI-Public/aws-ecr-orb/issues/182 Which supposedly was fixed in https://github.com/CircleCI-Public/aws-ecr-orb/pull/254 released under version 8.2.1

I just upgraded from 7.3.0 to 8.2.1, and I still experience the same bug, namely:

docker buildx build -f backend/Dockerfile -t  commit-123 --progress plain --push --build-arg GIT_SHA=123 --build-arg SOME_ENV_VAR=abc-123 .

ERROR: "docker buildx build" requires exactly 1 argument.
See 'docker buildx build --help'.

Usage:  docker buildx build [OPTIONS] PATH | URL | -

My config file:

version: 2.1
parameters:
  project-name:
     type: string
     default: "my-project"

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

commands:
  backend-docker:
    docker:
      - image: cimg/base:current
    steps:
      - checkout
      - setup_remote_docker:
          docker_layer_caching: true
      - attach_workspace:
          at: .
      - aws-cli/install
      - aws-ecr/build-image:
          repo: << pipeline.parameters.project-name >>
          tag: 'commit-${CIRCLE_SHA1},latest-${CIRCLE_BRANCH//\//-}'
          extra-build-args: '--build-arg GIT_SHA=${CIRCLE_SHA1} --build-arg SOME_ENV_VAR=$SOME_ENV_VAR'
          path: backend
      - aws-ecr/ecr-login
      - aws-ecr/push-image:
          repo: << pipeline.parameters.project-name >>
          tag: 'commit-${CIRCLE_SHA1},latest-${CIRCLE_BRANCH//\//-}'

workflows:
  version: 2
    test:
      jobs:
        - backend-docker

Variations tried:

extra-build-args: '--build-arg GIT_SHA="${CIRCLE_SHA1}" --build-arg SOME_ENV_VAR="${SOME_ENV_VAR}"'
extra-build-args: '--build-arg GIT_SHA=$CIRCLE_SHA1 --build-arg SOME_ENV_VAR=$SOME_ENV_VAR'

Expected behavior

extra-build-args should work to pass --build-arg parameters like 7.3.0 did, allowing to pass multiple build args.

VladaPetrovic commented 1 year ago

Check if you have an environment variable value with spaces in it. For example SOME_ENV_VAR='abc qwert'

We had the same issue and we fixed it by removing the spaces from the environment variable.

Like @swiknaba stated this was working just fine in version 7.3.0.

Here is the output if anyone wants to submit the fix.

+ docker --context builder buildx build -f ./Dockerfile --platform linux/amd64,linux/arm64 --progress plain --push --build-arg DEBUG=true --build-arg 'SOME_ENV_VAR=abc' 'qwert'  .
error: "docker buildx build" requires exactly 1 argument.

and the config file is

version: 2.1

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

jobs:
  build:
    executor: aws-ecr/default
    steps:
      - aws-ecr/build-and-push-image:
          repo: ${CIRCLE_PROJECT_REPONAME,,}
          tag: ${CIRCLE_TAG}
          platform: linux/amd64,linux/arm64
          extra-build-args: --build-arg DEBUG=true --build-arg SOME_ENV_VAR=${SOME_ENV_VAR}
...
swiknaba commented 1 year ago

@VladaPetrovic, thanks for your reply. I've double checked, and we have no spaces in any ENV VAR 🥲

rwojnarowski commented 1 year ago

I can confirm same issue for our project. Multiple extra-build-args result in an error in 8.2.1. Working fine on 7.3.0.

ERROR: "docker buildx build" requires exactly 1 argument.

my config:

extra-build-args: '--build-arg FIRST_ENV="$FIRST_ENV" --build-arg SECOND_ENV="$SECOND_ENV"'