+54
.github/workflows/cdn.yml
+54
.github/workflows/cdn.yml
···
1
+
name: Build and Push CDN
2
+
3
+
on:
4
+
push:
5
+
workflow_dispatch:
6
+
7
+
env:
8
+
REGISTRY: ghcr.io
9
+
IMAGE_NAME: ${{ github.repository }}/cdn
10
+
11
+
jobs:
12
+
build-and-push:
13
+
runs-on: ubuntu-latest
14
+
permissions:
15
+
contents: read
16
+
packages: write
17
+
18
+
steps:
19
+
- name: Checkout repository
20
+
uses: actions/checkout@v4
21
+
22
+
- name: Log in to the Container registry
23
+
uses: docker/login-action@v3
24
+
with:
25
+
registry: ${{ env.REGISTRY }}
26
+
username: ${{ github.actor }}
27
+
password: ${{ secrets.GITHUB_TOKEN }}
28
+
29
+
- name: Extract metadata (tags, labels) for Docker
30
+
id: meta
31
+
uses: docker/metadata-action@v5
32
+
with:
33
+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
34
+
tags: |
35
+
type=ref,event=branch
36
+
type=ref,event=pr
37
+
type=semver,pattern={{version}}
38
+
type=semver,pattern={{major}}.{{minor}}
39
+
type=semver,pattern={{major}}
40
+
type=sha,prefix={{branch}}-
41
+
42
+
- name: Set up Docker Buildx
43
+
uses: docker/setup-buildx-action@v3
44
+
45
+
- name: Build and push Docker image
46
+
uses: docker/build-push-action@v5
47
+
with:
48
+
context: .
49
+
file: ./cmd/cdn/Dockerfile
50
+
push: true
51
+
tags: ${{ steps.meta.outputs.tags }}
52
+
labels: ${{ steps.meta.outputs.labels }}
53
+
cache-from: type=gha
54
+
cache-to: type=gha,mode=max
+25
cmd/cdn/Dockerfile
+25
cmd/cdn/Dockerfile
···
1
+
FROM golang:1.25-alpine AS builder
2
+
3
+
WORKDIR /app
4
+
5
+
# Copy go mod files
6
+
COPY go.mod go.sum ./
7
+
RUN go mod download
8
+
9
+
# Copy source code
10
+
COPY . .
11
+
12
+
# Build the binary
13
+
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o cdn ./cmd/cdn
14
+
15
+
FROM alpine:latest
16
+
17
+
RUN apk --no-cache add ca-certificates
18
+
19
+
WORKDIR /root/
20
+
21
+
# Copy binary from builder
22
+
COPY --from=builder /app/cdn .
23
+
24
+
# Run the binary
25
+
CMD ["./cdn"]