Skip to content

Changed GH action to publish images from the preview branch too #2153

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bmispelon
Copy link
Member

@bmispelon bmispelon commented Aug 7, 2025

I believe this is all that's needed in order to start publishing a preview tag to the docker registry used for deployment.

Here's some documentation about the strange {{is_default_branch}} condition: https://github.com/docker/metadata-action?tab=readme-ov-file#latest-tag.

I removed the flavor: latest=true to avoid tagging a preview image with latest.

Refs #1922

@bmispelon bmispelon marked this pull request as draft August 7, 2025 15:33
@bmispelon bmispelon force-pushed the preview-server-setup branch from 14fe895 to dabaaf7 Compare August 7, 2025 15:35
@bmispelon bmispelon marked this pull request as ready for review August 7, 2025 15:37
@ulgens
Copy link
Member

ulgens commented Aug 8, 2025

@bmispelon This is not a direct review for this PR, but I have a question:

How do we feel about making this configurable? We can add a workflow_dispatch trigger, and the person doing the deployment can select which branch they need to be dockerized. This could only need a couple of lines of change in the action (I need to check how it affects the deployment script but I don't expect a huge change), and I'm willing to help with that. Having a "branch" input in the workflow will remove the need to have a specific branch for preview/test deployments.

tags: |
# set latest tag for main branch only
type=raw,value=latest,enable={{is_default_branch}}
Copy link
Member

@ulgens ulgens Aug 8, 2025

Choose a reason for hiding this comment

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

Do we need to make this dynamic? I believe having a hardcoded "main" is safe enough.

Copy link
Member Author

Choose a reason for hiding this comment

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

I got the {{is_default_branch}} from the action's documentation: https://github.com/docker/metadata-action?tab=readme-ov-file#latest-tag. I do agree that having a hardcoded main is unlikely to cause issues so I'm happy to change that.

@bmispelon
Copy link
Member Author

How do we feel about making this configurable? We can add a workflow_dispatch trigger, [...]

That would work too I guess.

  • How would the configuration look like? A drop-down where I can pick a branch, or would I have to copy/paste the branch name manually?
  • Would this action publish a preview tag any time it's run, or would it tag with a commit id instead (which I'd then need to copy in order to tell the deploy script which tag to use)?
  • Having a dedicated preview branch has the advantage that it's easier to know what is actually deployed on the preview server
  • Similarly, a preview branch could serve as an integration branch for separate PRs, rather than having to create ad-hoc integration branch when we want to test multiple things at once.

My strategy with this proposal was to do the simplest thing that works. A preview branch is really close to the existing infrastructure and so will require minimal changes (both to this project's github actions and to the deploy playbooks). We can always iterate on it in the future (if we're to have an auto-deploy of some kind for example, then a workflow_trigger style of deployment could be great).

@bmispelon bmispelon mentioned this pull request Aug 8, 2025
@bmispelon
Copy link
Member Author

I've also created to do the same for Trac: django/code.djangoproject.com#270

Copy link
Member

@tobiasmcnulty tobiasmcnulty left a comment

Choose a reason for hiding this comment

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

Looks good to me! 🚢

@ulgens
Copy link
Member

ulgens commented Aug 9, 2025

How would the configuration look like? A drop-down where I can pick a branch, or would I have to copy/paste the branch name manually?

CleanShot 2025-08-09 at 15 17 45@2x

This screenshot is from a project that we use a workflow_dispatch trigger for the preview/test deployments. Branch dropdown is provided by Actions and you can add other dropdown or text input fields.

https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#onworkflow_dispatchinputs

Would this action publish a preview tag any time it's run, or would it tag with a commit id instead (which I'd then need to copy in order to tell the deploy script which tag to use)?

It depends. We can tag it as "preview" and instruct the deployment script to use the latest preview image, or tag it with the commit hash and copy the commit hash to the deployment script. However, in my ideal scenario, this trigger would also handle the triggering of deployment, eliminating the need to call the deployment script separately.

Having a dedicated preview branch has the advantage that it's easier to know what is actually deployed on the preview server

Logs of the workflow runs could provide this information if the deployment was integrated. I see the current implementation and the need, and this is the easier solution, but there is also room for improvement. Another common thing I do in the projects I work is creating an admin-only "version" endpoint that returns the current git ref (commit hash + branch/tag name).

Similarly, a preview branch could serve as an integration branch for separate PRs, rather than having to create ad-hoc integration branch when we want to test multiple things at once.

I don't want to trigger another "this was the case in past but we can/should do better" discussion, so I'll keep it short: It makes sense, but it feels like a workaround. I guess I have to agree with it as the short-term solution, but there is room for improvement.

My strategy with this proposal was to do the simplest thing that works ... We can always iterate on it in the future

💯

@ulgens ulgens self-requested a review August 9, 2025 12:32
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