-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Manuel Hutter <[email protected]>
- Loading branch information
0 parents
commit 154f16d
Showing
4 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,47 @@ | ||
name: Build Container Image | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- master | ||
tags: | ||
- "v*" | ||
pull_request: {} | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
# Push image to GitHub Packages. | ||
container: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Log in to the Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Determine Tags & Labels based on Git ref | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" | ||
|
||
- name: Build & Push container image | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: . | ||
file: ./Dockerfile | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |
This file contains 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,5 @@ | ||
FROM quay.io/quay/busybox:latest | ||
|
||
RUN date > /build-date.txt | ||
|
||
CMD ["cat", "/build-date.txt"] |
This file contains 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,26 @@ | ||
# VSHN Container Build Example | ||
|
||
This repository aims to demonstrate how to build container images with GitHub Actions, and push them to the GitHub Container Registry (GHCR). | ||
|
||
## How it works | ||
|
||
The container build will be triggered when you | ||
|
||
* push a Git tag | ||
* push to the `main` branch | ||
* open a PR | ||
|
||
The workflow will determine the tags to use based on the event that triggered a workflow, see the [docker/metadata-action documentation](https://github.com/docker/metadata-action#basic) for a detailed explanation. TL;DR: | ||
|
||
* PR -> `pr-N` | ||
* Push to `main` -> `main` | ||
* Push to a tag -> `$TAG` (and also `latest` if the tag resembles a SemVer number) | ||
|
||
|
||
## Troubleshooting | ||
|
||
### "Permission denied" when trying to push a new image | ||
|
||
This can happen if a GitHub Package by the same name already exists, either because it has been pushed or created manually, or if the repository was deleted and recreatd. | ||
|
||
To fix this, go to the organization's "Packages" list (e.g. https://github.com/orgs/vshn/packages), and delete the conflicting package (if that's reasonable to do!). |
This file contains 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,7 @@ | ||
{ | ||
"extends": [ | ||
"config:base", | ||
":assignee(mhutter)", | ||
":automergeMinor" | ||
] | ||
} |