+58
.github/workflows/docker-image.yml
+58
.github/workflows/docker-image.yml
···
···
1
+
name: Docker image
2
+
3
+
on:
4
+
workflow_dispatch:
5
+
push:
6
+
7
+
env:
8
+
REGISTRY: ghcr.io
9
+
IMAGE_NAME: ${{ github.repository }}
10
+
11
+
jobs:
12
+
build-and-push-image:
13
+
runs-on: ubuntu-latest
14
+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
15
+
permissions:
16
+
contents: read
17
+
packages: write
18
+
attestations: write
19
+
id-token: write
20
+
#
21
+
steps:
22
+
- name: Checkout repository
23
+
uses: actions/checkout@v4
24
+
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
25
+
- name: Log in to the Container registry
26
+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
27
+
with:
28
+
registry: ${{ env.REGISTRY }}
29
+
username: ${{ github.actor }}
30
+
password: ${{ secrets.GITHUB_TOKEN }}
31
+
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
32
+
- name: Extract metadata (tags, labels) for Docker
33
+
id: meta
34
+
uses: docker/metadata-action@v5
35
+
with:
36
+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
37
+
tags: |
38
+
type=sha
39
+
type=sha,format=long
40
+
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
41
+
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
42
+
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
43
+
- name: Build and push Docker image
44
+
id: push
45
+
uses: docker/build-push-action@v5
46
+
with:
47
+
context: .
48
+
push: true
49
+
tags: ${{ steps.meta.outputs.tags }}
50
+
labels: ${{ steps.meta.outputs.labels }}
51
+
52
+
# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)."
53
+
- name: Generate artifact attestation
54
+
uses: actions/attest-build-provenance@v1
55
+
with:
56
+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
57
+
subject-digest: ${{ steps.push.outputs.digest }}
58
+
push-to-registry: true
+25
Dockerfile
+25
Dockerfile
···
···
1
+
### Compile stage
2
+
FROM golang:1.25.1-bookworm AS build-env
3
+
4
+
ADD . /dockerbuild
5
+
WORKDIR /dockerbuild
6
+
7
+
RUN GIT_VERSION=$(git describe --tags --long --always) && \
8
+
go mod tidy && \
9
+
go build -o cocoon ./cmd/cocoon
10
+
11
+
### Run stage
12
+
FROM debian:bookworm-slim AS run
13
+
14
+
RUN apt-get update && apt-get install -y dumb-init runit
15
+
ENTRYPOINT ["dumb-init", "--"]
16
+
17
+
WORKDIR /
18
+
RUN mkdir -p data/cocoon
19
+
COPY --from=build-env /dockerbuild/cocoon /
20
+
21
+
CMD ["/cocoon"]
22
+
23
+
LABEL org.opencontainers.image.source=https://github.com/haileyok/cocoon
24
+
LABEL org.opencontainers.image.description="Cocoon ATProto PDS"
25
+
LABEL org.opencontainers.image.licenses=MIT