Skip to content

Commit 25aa3d2

Browse files
authored
Merge pull request #20 from tippfehlr/github-ci-docker-build
ci: automatically build & push docker image to ghcr.io
2 parents 5539795 + 56118c8 commit 25aa3d2

3 files changed

Lines changed: 132 additions & 4 deletions

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Docker build & push to ghcr.io
2+
3+
# This workflow uses actions that are not certified by GitHub.
4+
# They are provided by a third-party and are governed by
5+
# separate terms of service, privacy policy, and support
6+
# documentation.
7+
8+
on:
9+
push:
10+
branches: ["main"]
11+
# Publish semver tags as releases.
12+
tags: ["v*.*.*"]
13+
pull_request:
14+
branches: ["main"]
15+
16+
env:
17+
# Use docker.io for Docker Hub if empty
18+
REGISTRY: ghcr.io
19+
# github.repository as <account>/<repo>
20+
IMAGE_NAME: ${{ github.repository }}
21+
22+
jobs:
23+
build:
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: read
27+
packages: write
28+
# This is used to complete the identity challenge
29+
# with sigstore/fulcio when running outside of PRs.
30+
id-token: write
31+
32+
steps:
33+
- name: Checkout repository
34+
uses: actions/checkout@v4
35+
36+
# Install the cosign tool except on PR
37+
# https://github.com/sigstore/cosign-installer
38+
- name: Install cosign
39+
if: github.event_name != 'pull_request'
40+
uses: sigstore/cosign-installer@v3
41+
42+
# Set up BuildKit Docker container builder to be able to build
43+
# multi-platform images and export cache
44+
# https://github.com/docker/setup-buildx-action
45+
- name: Set up Docker Buildx
46+
uses: docker/setup-buildx-action@v3
47+
48+
# Login against a Docker registry except on PR
49+
# https://github.com/docker/login-action
50+
- name: Log into registry ${{ env.REGISTRY }}
51+
if: github.event_name != 'pull_request'
52+
uses: docker/login-action@v3
53+
with:
54+
registry: ${{ env.REGISTRY }}
55+
username: ${{ github.actor }}
56+
password: ${{ secrets.GITHUB_TOKEN }}
57+
58+
# Extract metadata (tags, labels) for Docker
59+
# https://github.com/docker/metadata-action
60+
- name: Extract Docker metadata
61+
id: meta
62+
uses: docker/metadata-action@v5
63+
with:
64+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
65+
tags: |
66+
type=ref,event=branch
67+
type=ref,event=pr
68+
type=semver,pattern={{version}}
69+
type=semver,pattern={{major}}.{{minor}}
70+
71+
# Build and push Docker image with Buildx (don't push on PR)
72+
# https://github.com/docker/build-push-action
73+
- name: Build and push Docker image
74+
id: build-and-push
75+
uses: docker/build-push-action@v5
76+
with:
77+
context: .
78+
push: ${{ github.event_name != 'pull_request' }}
79+
tags: ${{ steps.meta.outputs.tags }}
80+
labels: ${{ steps.meta.outputs.labels }}
81+
cache-from: type=gha
82+
cache-to: type=gha,mode=max
83+
84+
# Sign the resulting Docker image digest except on PRs.
85+
# This will only write to the public Rekor transparency log when the Docker
86+
# repository is public to avoid leaking data. If you would like to publish
87+
# transparency data even for private images, pass --force to cosign below.
88+
# https://github.com/sigstore/cosign
89+
- name: Sign the published Docker image
90+
if: ${{ github.event_name != 'pull_request' }}
91+
env:
92+
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
93+
TAGS: ${{ steps.meta.outputs.tags }}
94+
DIGEST: ${{ steps.build-and-push.outputs.digest }}
95+
# This step uses the identity token to provision an ephemeral certificate
96+
# against the sigstore community Fulcio instance.
97+
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.21.4 AS Build
1+
FROM golang AS Build
22
WORKDIR /app
33
COPY go.mod go.sum ./
44
RUN go mod download
@@ -7,12 +7,13 @@ COPY cmd ./cmd
77
COPY pkg ./pkg
88
RUN CGO_ENABLED=0 GOOS=linux go build -o /gpodder2go
99

10-
FROM alpine:3.18.4
10+
FROM alpine
1111
RUN mkdir /data
1212
WORKDIR /data
1313
COPY entrypoint.sh /entrypoint.sh
14-
RUN chmod +x /data
14+
RUN chmod +x /data /entrypoint.sh
1515
COPY --from=Build /gpodder2go /gpodder2go
16+
1617
EXPOSE 3005
1718
VOLUME /data
18-
CMD ["/entrypoint.sh"]
19+
ENTRYPOINT ["/entrypoint.sh"]

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,36 @@ Add with:
8888

8989
### Docker
9090

91+
```sh
92+
$ docker run -d \
93+
--name gpodder2go \
94+
-p 3005:3005 \
95+
-v <data_directory>:/data \
96+
oxtyped/gpodder2go:latest
97+
```
98+
99+
With docker compose:
100+
101+
```yaml
102+
version: '3'
103+
services:
104+
gpodder2go:
105+
image: oxtyped/gpodder2go:latest
106+
ports:
107+
- 3005:3005
108+
volumes:
109+
- ./gpodder2go:/data
110+
restart: unless-stopped
111+
```
112+
113+
To configure the server run
114+
115+
```sh
116+
$ docker exec --it gpodder2go /gpodder2go ...
117+
```
118+
119+
#### Build docker image from source
120+
91121
Build with:
92122

93123
```

0 commit comments

Comments
 (0)