Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add support to secret env #110

Merged
merged 1 commit into from
Jun 6, 2023
Merged

✨ Add support to secret env #110

merged 1 commit into from
Jun 6, 2023

Conversation

vinicius73
Copy link
Contributor

Allow to use environment variables as secret during docker build.


Eventually we need pass some environment variables to docker build to allow interactions with dynamic sources like AWS.

Those environment variables are avaible after some previous github actions steps, like configure-aws-credentials

I use the docker/build-push-action action in a very strict environment, is encapsulated by other actions who I don't have access directly.

This change (and another change in build-push-action) will unlock this limitation and solve the problem.

docker build --progress plain \
    --secret id=AWS_ACCESS_KEY_ID,env="AWS_ACCESS_KEY_ID" \
    --secret id=AWS_SECRET_ACCESS_KEY,env="AWS_SECRET_ACCESS_KEY" \
    --secret id=AWS_SESSION_TOKEN,env="AWS_SESSION_TOKEN" \
    -t image:tag

@crazy-max
Copy link
Member

and another change in build-push-action

I was wondering what we were going to do in docker/build-push-action. Perhaps you were thinking of a new secret-envs input? Thanks for your contrib btw!

@vinicius73
Copy link
Contributor Author

Yes @crazy-max, a new input option must be created.

Copy link
Member

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks

@crazy-max crazy-max merged commit 0b166c6 into docker:main Jun 6, 2023
15 checks passed
@vinicius73
Copy link
Contributor Author

Thanks @crazy-max.
Can you release a new version with this change?

@vinicius73 vinicius73 deleted the feature/add-support-to-secret-env branch June 7, 2023 03:05
@crazy-max
Copy link
Member

crazy-max commented Jun 7, 2023

@vinicius73 Updated the toolkit on build push action repo docker/build-push-action#875 if you're willing to contribute for the follow-up 🙏

@crazy-max
Copy link
Member

@vinicius73 I was wondering why you could not use the secrets input directly?

      -
        name: Build
        uses: docker/build-push-action@v4
        with:
          context: .
          secrets: |
            "AWS_ACCESS_KEY_ID=${{ env.AWS_ACCESS_KEY_ID }}"

@vinicius73
Copy link
Contributor Author

Hi @crazy-max, unfortunately I don't have direct access to the action.
It's under a external action whon I import in my workflow.

I am only able to pass some arguments to this workflow, and inside that it will call docker build action with my arguments.

Inside my dockerfile I must use the aws credentials, that credentials are loaded in runtime in a previous step.

Because of that I can't pass a environment variable as secret argument.
The variable will be passed to the imported workflow, before the docker build step.
At this point, the variable don't exist yet.

@crazy-max
Copy link
Member

Then how do you set secrets when calling this reusable workflow?

@vinicius73
Copy link
Contributor Author

The AWS creadentials are dinamic and generated with https://github.com/aws-actions/configure-aws-credentials

@crazy-max
Copy link
Member

Sure but it still needs to be specified in our action that you want to use envs as secrets. Can you post your workflow please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants