Skip to content

Commit ae06b53

Browse files
committed
feat: support build docker image
Signed-off-by: waaagh <[email protected]>
1 parent 7ee54ba commit ae06b53

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: publish docker image
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
# Publish when tagging
7+
tags: [ '*' ]
8+
9+
env:
10+
# Use docker.io for Docker Hub if empty
11+
REGISTRY: ghcr.io
12+
# github.repository as <account>/<repo>
13+
GH_IMAGE_NAME: ${{github.repository_owner}}/immich-go
14+
DH_IMAGE_NAME: ${{github.repository_owner}}/immich-go
15+
16+
jobs:
17+
build:
18+
19+
runs-on: ubuntu-latest
20+
permissions:
21+
packages: write
22+
# This is used to complete the identity challenge
23+
# with sigstore/fulcio when running outside of PRs.
24+
id-token: write
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
30+
# Install the cosign tool
31+
# https://github.com/sigstore/cosign-installer
32+
- name: Install cosign
33+
uses: sigstore/cosign-installer@main #v2.6.0
34+
-
35+
# Add support for more platforms with QEMU (optional)
36+
# https://github.com/docker/setup-qemu-action
37+
name: Set up QEMU
38+
uses: docker/setup-qemu-action@v3
39+
- name: Setup Docker buildx
40+
uses: docker/setup-buildx-action@v3
41+
-
42+
name: Login to Docker Hub
43+
uses: docker/login-action@v3
44+
with:
45+
username: ${{ secrets.DOCKERHUB_USERNAME }}
46+
password: ${{ secrets.DOCKERHUB_TOKEN }}
47+
# Login against a Docker registry
48+
- name: Log into registry ${{ env.REGISTRY }}
49+
uses: docker/login-action@v3
50+
with:
51+
registry: ${{ env.REGISTRY }}
52+
username: ${{ github.actor }}
53+
password: ${{ secrets.GITHUB_TOKEN }}
54+
55+
# Extract metadata (tags, labels) for Docker
56+
# https://github.com/docker/metadata-action
57+
- name: Extract Docker metadata
58+
id: meta
59+
uses: docker/metadata-action@v5
60+
with:
61+
images: ${{ env.REGISTRY }}/${{ env.GH_IMAGE_NAME }},${{ env.DH_IMAGE_NAME }}
62+
63+
# Build and push Docker image with Buildx (don't push on PR)
64+
# https://github.com/docker/build-push-action
65+
- name: Build and push Docker image
66+
id: build-and-push
67+
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56
68+
with:
69+
platforms: linux/amd64,linux/arm64
70+
push: true
71+
tags: ${{ steps.meta.outputs.tags }}
72+
labels: ${{ steps.meta.outputs.labels }}
73+
cache-from: type=gha
74+
cache-to: type=gha,mode=max
75+
76+
# Sign the resulting Docker image digest except on PRs.
77+
# This will only write to the public Rekor transparency log when the Docker
78+
# repository is public to avoid leaking data. If you would like to publish
79+
# transparency data even for private images, pass --force to cosign below.
80+
# https://github.com/sigstore/cosign
81+
- name: Sign the published Docker image
82+
env:
83+
COSIGN_EXPERIMENTAL: "true"
84+
# This step uses the identity token to provision an ephemeral certificate
85+
# against the sigstore community Fulcio instance.
86+
run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign -y {}@${{ steps.build-and-push.outputs.digest }}
87+

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM golang:1.21 as BUILDER
2+
3+
WORKDIR /go/src/app
4+
COPY . .
5+
RUN go mod download && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /go/bin/immich-go -ldflags="-s -w -extldflags=-static" main.go
6+
7+
FROM gcr.io/distroless/base-debian12
8+
9+
COPY --from=BUILDER /go/bin/immich-go /
10+
CMD ["/immich-go"]

0 commit comments

Comments
 (0)