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
81 stars 142 forks source link

extra-build-args not exporting variables in docker container #248

Closed matteomattei closed 1 year ago

matteomattei commented 2 years ago

Orb version

8.1.3

Reference

https://github.com/CircleCI-Public/aws-ecr-orb/issues/192

What happened

If I use extra-build-args option in the config.yml, it seems the variables are never passed to the created container.

In my CircleCI job I do the following:

version: 2.1

orbs:
  aws-ecr: circleci/aws-ecr@8.1.3
  node: circleci/node@5.0.2

workflows:
  development:
    jobs:
      - aws-ecr/build-and-push-image:
          filters:
            branches:
              ignore: /main|prod/
          context:
            - aws
          repo: $CIRCLE_PROJECT_REPONAME
          create-repo: true
          extra-build-args: "--build-arg AWS_ACCESS_KEY_ID --build-arg AWS_SECRET_ACCESS_KEY --build-arg HELLO=WORLD"
          tag: latest

In the aws context I have defined several variables including these:

AWS_ACCESS_KEY_ID
AWS_ACCOUNT_ID
AWS_ECR_REGISTRY_ID
AWS_REGION
AWS_SECRET_ACCESS_KEY
CLUSTER_TAG

This is the Dockerfile:

FROM node:18-alpine as base
WORKDIR /app

RUN env

# Install AWS-CLI
RUN apk add --no-cache aws-cli

# Copy and download dependencies
FROM base as with-source
COPY . .
RUN yarn setup
RUN yarn install --frozen-lockfile

FROM with-source as run
EXPOSE 4000
RUN yarn build
CMD yarn start

When running the CircleCI pipeline, the env is not what I would expected:

...
#7 [base 3/4] RUN env
#7 sha256:cc5f6cab448295b14b0234472c634c1845805ac574f2c6ff55a5ec4f4f1efe66
#7 0.085 NODE_VERSION=18.12.1
#7 0.085 YARN_VERSION=1.22.19
#7 0.085 SHLVL=1
#7 0.085 HOME=/root
#7 0.085 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
#7 0.085 PWD=/app
#7 DONE 0.1s
...

Expected behavior

I would expect the env output in the docker container would report also the variables I have defined in the extra-build-args. The first two should have been taken from the CircleCI context while the last one is static but any of them is present in the ENV inside the docker image.

brivu commented 1 year ago

Hey @matteomattei,

We actually have a fix for this merge in PR #245. I'm working on a few more fixes and will release the next version soon.

Thanks for reporting this!

Best, Brian