Skip to content

Inject default values to container image name to avoid CI failure in from-fork PRs #108

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

Merged
merged 4 commits into from
Apr 14, 2025

Conversation

Oded-B
Copy link
Collaborator

@Oded-B Oded-B commented Apr 11, 2025

Description

Workflows run from forks don't have access to env.* variables so they fail the container build stage with:

ERROR: invalid tag "/:pr-106": invalid reference format

This pr will inject commercetools/telefonistka values for those cases while still supporting forks overriding their image names.

Type of Change

  • Bug Fix
  • New Feature
  • Breaking Change
  • Refactor
  • Documentation
  • Other (please describe)

Checklist

  • I have read the contributing guidelines
  • Existing issues have been referenced (where applicable)
  • I have verified this change is not present in other open pull requests
  • Functionality is documented
  • All code style checks pass
  • New code contribution is covered by automated tests
  • All new and existing tests pass

@Oded-B Oded-B changed the title Test Injecting default values to image name Inject default values to container image name to avoid failure in from-fork PRs Apr 11, 2025
@Oded-B Oded-B marked this pull request as ready for review April 11, 2025 15:08
@Oded-B Oded-B requested a review from a team as a code owner April 11, 2025 15:09
@Oded-B Oded-B mentioned this pull request Apr 11, 2025
13 tasks
@Oded-B Oded-B changed the title Inject default values to container image name to avoid failure in from-fork PRs Inject default values to container image name to avoid CI failure in from-fork PRs Apr 11, 2025
Copy link
Contributor

@hnnsgstfssn hnnsgstfssn left a comment

Choose a reason for hiding this comment

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

I was trying to figure this out, but wasn't really able to find exactly why it was happening.

I'm not sure we should inject commercetools/telefonistka as a default value - seems like it shouldn't be necessary to me, but again I also cannot point to why 🤷

Since we've pinned to commits of docker/build-push-action, docker/metadata-action and docker/login-action, I thought an upgrade could potentially resolve it, but also not sure. I think we should still upgrade the versions to @v6, @v5 and @v3 respectively either way but let's do separately.

@@ -75,7 +75,7 @@ jobs:
uses: docker/metadata-action@906ecf0fc0a80f9110f79d9e6c04b1080f4a2621
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
${{ env.REGISTRY != '' && env.REGISTRY || 'ghcr.io' }}/${{ env.IMAGE_NAME != '' && env.IMAGE_NAME || 'commercetools/telefonistka'}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you know why we need to inject commercetools/telefonistka as a fallback value hardcoded here?

Could we just check if the value is set and skip or something if it is not?

I don't understand why our check would fail, regardless of values on other forks - we have the value set!

Copy link
Collaborator Author

@Oded-B Oded-B Apr 12, 2025

Choose a reason for hiding this comment

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

Maybe GH doesn't provide these env variables to GH workflows generated from a fork as security mechanism? so people couldn't sniff your secrets by manipulating CI/CD config and opening a PR?
There's already a mechanism to that which requires maintainer approval for workflows coming from new contributors, and these keys are not secrets, just plain "variables", but maybe it's a "defence in depth" kind of thing 🤷

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Written right here on the top of the Variable page in GH UI :)
image

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that I understand, but I don't understand why it's running in the context of the fork when the PR is opened in this repository 😕

Choose a reason for hiding this comment

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

Since these are not sensitive values, may I suggest defining them directly in the workflow instead at the top level?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you mean just hardcode the value to

images: |
  ghcr.io/ommercetools/telefonistka

?
I'm ok with that.
The initial thought behind this was to allow forks to override these values so they can build images in their own repos without maintaining different CI/CD configurations. I'm not if anyone cares about that.
@hnnsgstfssn ?

Copy link
Contributor

Choose a reason for hiding this comment

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

defining them directly in the workflow instead at the top level

I'm also on board with that.

I'm not if anyone cares about that.

I think we focus on what's needed in the context of this repository - I still don't understand why there are complications with forks 🤷 let's leave this discussion and we'll see if it comes up again.

Choose a reason for hiding this comment

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

Perhaps you can just enforce ghcr.io and instead of using the image name you use the github context github.repository which translates to <org>/<repo-name>. That way forks can still create these and have pushed to their own org automatically.

@Oded-B
Copy link
Collaborator Author

Oded-B commented Apr 14, 2025

Since we've pinned to commits of docker/build-push-action, docker/metadata-action and docker/login-action, I thought an upgrade could potentially resolve it, but also not sure. I think we should still upgrade the versions to @v6, @v5 and @v3 respectively either way but let's do separately.

I agree that we should review our usage of docker/build-push-action, docker/metadata-action and docker/login-action, since we ditched Docker registery some of it might not be needed.

I want to unblock #106 and #105, are you ok with the proposed solution?

@hnnsgstfssn
Copy link
Contributor

Since we've pinned to commits of docker/build-push-action, docker/metadata-action and docker/login-action, I thought an upgrade could potentially resolve it, but also not sure. I think we should still upgrade the versions to @v6, @v5 and @v3 respectively either way but let's do separately.

I agree that we should review our usage of docker/build-push-action, docker/metadata-action and docker/login-action, since we ditched Docker registery some of it might not be needed.

I want to unblock #106 and #105, are you ok with the proposed solution?

Sure let's go ahead and we'll address anything else that comes up after.

@Oded-B Oded-B merged commit ed88337 into commercetools:main Apr 14, 2025
5 checks passed
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.

3 participants