Skip to content

Commit

Permalink
Initial import 🌱
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Hutter <[email protected]>
  • Loading branch information
mhutter committed May 19, 2023
0 parents commit 154f16d
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/container.yaml
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 }}
5 changes: 5 additions & 0 deletions Dockerfile
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"]
26 changes: 26 additions & 0 deletions README.md
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!).
7 changes: 7 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": [
"config:base",
":assignee(mhutter)",
":automergeMinor"
]
}

0 comments on commit 154f16d

Please sign in to comment.