Repository navigation
Add workflow to publish the Docker image on releases #193
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
AARUSHGAUR
wants to merge
6
commits into
google:copybara_push
Choose a base branch
from
AARUSHGAUR:docker-publish-on-release
base: copybara_push
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6c19674
Add workflow to publish the Docker image on releases
AARUSHGAUR a0ec5dc
Move Docker guidance into the setup guide
AARUSHGAUR 6215f28
Document Docker publish workflow configuration
AARUSHGAUR ae54d40
Merge upstream copybara_push into docker-publish-on-release
AARUSHGAUR e74eacb
Format README contributor note
AARUSHGAUR d3a3007
Clarify published image usage and build platform
AARUSHGAUR File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| # Publish the sbsim container image when a GitHub release is published. | ||
| # | ||
| # Required configuration | ||
| # ---------------------- | ||
| # No repository secrets are required for the GitHub Container Registry (GHCR) | ||
| # publish. The workflow authenticates with the automatically provided | ||
| # `GITHUB_TOKEN` and the `packages: write` permission declared below. | ||
| # | ||
| # Repository administrators should verify that Actions can create packages and | ||
| # that the published package is visible to end users. New packages are private | ||
| # by default; set `ghcr.io/google/sbsim` to public under the package settings if | ||
| # anonymous pulls should be allowed. See: | ||
| # - https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry | ||
| # - https://docs.github.com/en/packages/learn-github-packages/configuring-a-packages-access-control-and-visibility | ||
| # | ||
| # Optional Docker Hub publishing | ||
| # ------------------------------ | ||
| # To also publish `<username>/sbsim` to Docker Hub, configure both repository | ||
| # secrets under Settings > Secrets and variables > Actions > Secrets: | ||
| # - DOCKER_HUB_USERNAME: Docker Hub username that owns the target repository. | ||
| # - DOCKER_HUB_PASSWORD: Docker Hub access token (not the account password) | ||
| # with permission to push to the target repository. | ||
| # If either secret is unset, the Docker Hub steps are skipped and only GHCR is | ||
| # published. See: | ||
| # - https://docs.docker.com/security/for-developers/access-tokens/ | ||
| # - https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions | ||
| # | ||
| # Workflow environment variables | ||
| # ------------------------------ | ||
| # - REGISTRY: registry host for the required GHCR publish (`ghcr.io`). | ||
| # - IMAGE_NAME: image path within the registry (`github.repository`, which is | ||
| # `google/sbsim` for this repository). | ||
| # - DOCKER_HUB_USERNAME and DOCKER_HUB_PASSWORD: optional secrets mapped to | ||
| # environment variables so the Docker Hub steps can be skipped when they are | ||
| # not configured. Values are masked by GitHub Actions and are never printed. | ||
| # | ||
| # Image tags | ||
| # ---------- | ||
| # - Release published: `latest`, the release tag, and, for semantic version | ||
| # tags such as `v1.2.3`, `1.2.3` and `1.2`. Non-semver release tags (for | ||
| # example `pre-sync-20250521`) still publish the release tag and `latest`. | ||
| # - Manual workflow run: the optional `tag` input, or `sha-<short sha>` when no | ||
| # tag is provided. | ||
| # | ||
| # This workflow only reads repository contents and writes packages. It does not | ||
| # modify releases or any other repository state. | ||
| name: Docker Publish | ||
|
|
||
| on: | ||
| release: | ||
| types: | ||
| - published | ||
| workflow_dispatch: | ||
| inputs: | ||
| tag: | ||
| description: 'Tag for the published image (defaults to sha-<short sha>)' | ||
| required: false | ||
| type: string | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| docker-publish: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| packages: write | ||
| env: | ||
| REGISTRY: ghcr.io | ||
| IMAGE_NAME: ${{ github.repository }} | ||
| DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
| DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1 | ||
|
|
||
| - name: Log in to the GitHub Container Registry | ||
| uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0 | ||
| with: | ||
| registry: ${{ env.REGISTRY }} | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Extract metadata | ||
| id: meta | ||
| uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0 | ||
| with: | ||
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
| tags: | | ||
| type=ref,event=tag,enable=${{ github.event_name == 'release' }} | ||
| type=semver,pattern={{version}} | ||
| type=semver,pattern={{major}}.{{minor}} | ||
| type=raw,value=${{ inputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' && inputs.tag != '' }} | ||
| type=sha,format=short,enable=${{ github.event_name == 'workflow_dispatch' && inputs.tag == '' }} | ||
|
|
||
| - name: Build and push to the GitHub Container Registry | ||
| uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 | ||
| with: | ||
| context: . | ||
| platforms: linux/amd64 | ||
| push: true | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| labels: ${{ steps.meta.outputs.labels }} | ||
| cache-from: type=gha,scope=ghcr | ||
| cache-to: type=gha,mode=max,scope=ghcr | ||
|
|
||
| - name: Log in to Docker Hub | ||
| if: ${{ env.DOCKER_HUB_USERNAME != '' && env.DOCKER_HUB_PASSWORD != '' }} | ||
| uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0 | ||
| with: | ||
| username: ${{ env.DOCKER_HUB_USERNAME }} | ||
| password: ${{ env.DOCKER_HUB_PASSWORD }} | ||
|
|
||
| - name: Extract Docker Hub metadata | ||
| id: meta-dockerhub | ||
| if: ${{ env.DOCKER_HUB_USERNAME != '' && env.DOCKER_HUB_PASSWORD != '' }} | ||
| uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0 | ||
| with: | ||
| images: ${{ env.DOCKER_HUB_USERNAME }}/sbsim | ||
| tags: | | ||
| type=ref,event=tag,enable=${{ github.event_name == 'release' }} | ||
| type=semver,pattern={{version}} | ||
| type=semver,pattern={{major}}.{{minor}} | ||
| type=raw,value=${{ inputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' && inputs.tag != '' }} | ||
| type=sha,format=short,enable=${{ github.event_name == 'workflow_dispatch' && inputs.tag == '' }} | ||
|
|
||
| - name: Build and push to Docker Hub | ||
| if: ${{ env.DOCKER_HUB_USERNAME != '' && env.DOCKER_HUB_PASSWORD != '' }} | ||
| uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 | ||
| with: | ||
| context: . | ||
| platforms: linux/amd64 | ||
| push: true | ||
| tags: ${{ steps.meta-dockerhub.outputs.tags }} | ||
| labels: ${{ steps.meta-dockerhub.outputs.labels }} | ||
| cache-from: type=gha,scope=dockerhub | ||
| cache-to: type=gha,mode=max,scope=dockerhub | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,14 +54,20 @@ instructions linked below. | |
| The [Setup Guide](docs/setup.md) provides all the information you need to run | ||
| the code locally. | ||
|
|
||
| ## Docker | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we please move this content into docs/setup/docker. We can re-organize that file to have two top level sections: build from docker registry (implemented in this PR), and build yourself locally (current content) |
||
|
|
||
| The [Docker Setup Guide](docs/setup/docker.md) explains how to run the image | ||
| published to the GitHub Container Registry or build the image locally. | ||
|
|
||
| ## Contributing | ||
|
|
||
| The [Contributor's Guide](docs/contributing.md) provides more information on how | ||
| to contribute to this repository. | ||
|
|
||
| We appreciate contributions and interest from the community! Please note that our | ||
| team maintains this repository alongside active internal Google project commitments, | ||
| so pull request reviews may take anywhere from a few days to a couple of weeks. | ||
| We review PRs as maintainer bandwidth allows. Thank you for your patience and support! | ||
| We appreciate contributions and interest from the community! Please note that | ||
| our team maintains this repository alongside active internal Google project | ||
| commitments, so pull request reviews may take anywhere from a few days to a | ||
| couple of weeks. We review PRs as maintainer bandwidth allows. Thank you for | ||
| your patience and support! | ||
|
|
||
| ## [License](LICENSE) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's please add some instructions in the docs related to this workflow, or comments at the top of this file, to instruct administrators about what repo secrets and env vars are required by this workflow, and how an admin could set them up, including links to how to docker registry, as applicable.