Skip to content
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

Automatically build and publish container images to Github Container Repo #23

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: "Container image build"

on:
push:
branches: [ master ]
pull_request:

jobs:

image:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value={{date 'YYYY-MM-DDTHH-mm'}}
type=raw,value=latest

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.ref == 'refs/heads/master' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM docker.io/golang:bookworm AS builder

WORKDIR src

COPY *.go ./
COPY processors/ ./processors/

RUN go mod init gtfstidy
RUN go mod tidy
RUN go build .

FROM docker.io/debian:stable-slim

Choose a reason for hiding this comment

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

Let's add OCI annotations, to provide helpful machine-readable infos to a variety of tools.

Suggested change
FROM docker.io/debian:stable-slim
FROM docker.io/debian:stable-slim
LABEL org.opencontainers.image.title="oxygen-xml"
LABEL org.opencontainers.image.description="A tool for checking, sanitizing and minimizing GTFS feeds."
LABEL org.opencontainers.image.authors="Patrick Brosi <[email protected]>"
LABEL org.opencontainers.image.source="https://github.com/patrickbr/gtfstidy"

Copy link
Author

Choose a reason for hiding this comment

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

docker/metadata-action actually already adds most (all?) of these labels from the GitHub metadata.

Can you check the pfaedle image (which uses the same process) to see if you're missing something? https://github.com/ad-freiburg/pfaedle/pkgs/container/pfaedle

Choose a reason for hiding this comment

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

Thanks, I didn't know. Consider this thread irrelevant then.


COPY --from=builder /go/src/gtfstidy /usr/local/bin/gtfstidy

ENTRYPOINT ["/usr/local/bin/gtfstidy"]