Skip to content

Commit 67c1718

Browse files
authored
Merge pull request #24 from temporalio/dockerfile-improve
Optimize Docker builds: Add .dockerignore, improve caching, and enhance Dockerfile structure
2 parents d034b92 + fb32358 commit 67c1718

3 files changed

Lines changed: 57 additions & 20 deletions

File tree

.dockerignore

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,40 @@
1-
.github
1+
# Build artifacts
2+
runner
3+
worker
4+
5+
# Version control
26
.git
7+
.gitignore
8+
9+
# CI/CD
10+
.github
11+
.gitlab-ci.yml
12+
13+
# Documentation
14+
*.md
15+
README*
16+
docs/
17+
18+
# Tests
19+
*_test.go
20+
**/*_test.go
21+
22+
# Development
23+
.env
24+
.env.*
25+
*.log
26+
27+
# IDE
28+
.vscode/
29+
.idea/
30+
*.swp
31+
*.swo
32+
.DS_Store
33+
34+
# Kubernetes/Deployment
335
charts/
436
deployment.yaml
5-
runner
6-
worker
37+
kubernetes/
38+
39+
# Project-specific
40+
Makefile
Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,44 @@
11
name: Docker
2-
32
on:
43
push:
5-
branches: [ "main" ]
4+
branches: ["main"]
65
# Publish semver tags as releases.
7-
tags: [ 'v*.*.*' ]
6+
tags: ['v*.*.*']
87
pull_request:
9-
branches: [ "main" ]
10-
8+
branches: ["main"]
119
env:
1210
REGISTRY: ghcr.io
1311
IMAGE_NAME: ${{ github.repository }}
14-
1512
jobs:
1613
build-and-push-image:
1714
runs-on: ubuntu-latest
1815
permissions:
1916
contents: read
2017
packages: write
21-
2218
steps:
2319
- name: Checkout repository
2420
uses: actions/checkout@v3
25-
26-
- name: Setup Docker buildx
27-
uses: docker/setup-buildx-action@v2.4.1
28-
21+
- name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v3
2923
- name: Log into registry ${{ env.REGISTRY }}
3024
if: github.event_name != 'pull_request'
3125
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
3226
with:
3327
registry: ${{ env.REGISTRY }}
3428
username: ${{ github.actor }}
3529
password: ${{ secrets.GITHUB_TOKEN }}
36-
3730
- name: Extract metadata (tags, labels) for Docker
3831
id: meta
3932
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
4033
with:
4134
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
42-
4335
- name: Build and push Docker image
44-
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
36+
uses: docker/build-push-action@v6
4537
with:
4638
context: .
4739
platforms: linux/amd64,linux/arm64
4840
push: ${{ github.event_name != 'pull_request' }}
4941
tags: ${{ steps.meta.outputs.tags }}
5042
labels: ${{ steps.meta.outputs.labels }}
43+
cache-from: type=gha
44+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1+
# Build stage
12
FROM golang:1.23 AS builder
23

34
WORKDIR /usr/src/worker
45

6+
# Copy dependency manifests
57
COPY go.mod go.sum ./
6-
RUN go mod download && go mod verify
78

9+
# Install dependencies
10+
RUN --mount=type=cache,target=/go/pkg/mod go mod download && go mod verify
11+
12+
# Copy source code
813
COPY . .
9-
RUN CGO_ENABLED=0 go build -v -o /usr/local/bin/worker ./cmd/worker
10-
RUN CGO_ENABLED=0 go build -v -o /usr/local/bin/runner ./cmd/runner
1114

15+
# Build binaries
16+
RUN CGO_ENABLED=0 go build -v -o /usr/local/bin/worker ./cmd/worker && \
17+
CGO_ENABLED=0 go build -v -o /usr/local/bin/runner ./cmd/runner
18+
19+
# Runtime stage
1220
FROM scratch
1321

22+
# Copy binaries from builder
1423
COPY --from=builder /usr/local/bin/worker /usr/local/bin/worker
1524
COPY --from=builder /usr/local/bin/runner /usr/local/bin/runner
1625

0 commit comments

Comments
 (0)