From 0b09e4ccf4c09585692d6acba9a82dfbb2708440 Mon Sep 17 00:00:00 2001 From: Jaz Date: Thu, 2 Oct 2025 16:05:21 -0700 Subject: [PATCH] Add docker build for cocoon and workflows --- .github/workflows/docker-image.yml | 58 ++++++++++++++++++++++++++++++ Dockerfile | 25 +++++++++++++ Makefile | 4 +++ 3 files changed, 87 insertions(+) create mode 100644 .github/workflows/docker-image.yml create mode 100644 Dockerfile diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..ef85970 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,58 @@ +name: Docker image + +on: + workflow_dispatch: + push: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + attestations: write + id-token: write + # + steps: + - name: Checkout repository + uses: actions/checkout@v4 + # 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. + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + # 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. + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=sha + type=sha,format=long + # 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. + # 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. + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. + - name: Build and push Docker image + id: push + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + # 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)." + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v1 + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..85c2883 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +### Compile stage +FROM golang:1.25.1-bookworm AS build-env + +ADD . /dockerbuild +WORKDIR /dockerbuild + +RUN GIT_VERSION=$(git describe --tags --long --always) && \ + go mod tidy && \ + go build -o cocoon ./cmd/cocoon + +### Run stage +FROM debian:bookworm-slim AS run + +RUN apt-get update && apt-get install -y dumb-init runit +ENTRYPOINT ["dumb-init", "--"] + +WORKDIR / +RUN mkdir -p data/cocoon +COPY --from=build-env /dockerbuild/cocoon / + +CMD ["/cocoon"] + +LABEL org.opencontainers.image.source=https://github.com/haileyok/cocoon +LABEL org.opencontainers.image.description="Cocoon ATProto PDS" +LABEL org.opencontainers.image.licenses=MIT \ No newline at end of file diff --git a/Makefile b/Makefile index 8bd91b1..f54582b 100644 --- a/Makefile +++ b/Makefile @@ -40,3 +40,7 @@ check: ## Compile everything, checking syntax (does not output binaries) .env: if [ ! -f ".env" ]; then cp example.dev.env .env; fi + +.PHONY: docker-build +docker-build: + docker build -t cocoon . \ No newline at end of file -- 2.51.2