-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
176 lines (140 loc) · 4.58 KB
/
Dockerfile
File metadata and controls
176 lines (140 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# Multi-stage Dockerfile for scriptschnell
# Supports testing, linting, and cross-compiling for multiple architectures
# Build stages use Debian, runtime uses Alpine
# TinyGo dependency
FROM tinygo/tinygo:0.39.0 AS tinygo
# Base stage with Go (Debian) and common dependencies
FROM golang:1.26-bookworm AS base
WORKDIR /app
# Install git, ca-certificates, tzdata, and cross-compilation toolchains
RUN apt-get update && apt-get install -y \
git \
ca-certificates \
tzdata \
gcc \
g++ \
libc6-dev \
gcc-x86-64-linux-gnu \
gcc-aarch64-linux-gnu \
libc6-dev-amd64-cross \
libc6-dev-arm64-cross \
libx11-dev \
&& rm -rf /var/lib/apt/lists/* \
&& update-ca-certificates
COPY --from=tinygo /usr/local/tinygo /usr/local/tinygo
ENV PATH="/usr/local/tinygo/bin:${PATH}"
ENV GOPATH=/go
# Copy go mod files and download dependencies
COPY go.mod go.sum ./
RUN go mod download
# Linting stage (minimal)
FROM base AS lint
RUN go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest && \
go install github.com/a-h/templ/cmd/templ@latest
# Copy source code
COPY . .
# Generate templ templates before linting
RUN echo "Generating templ templates..." && \
templ generate
# Run linters with CGO enabled for tree-sitter
RUN echo "Running golangci-lint..." && \
CGO_ENABLED=1 golangci-lint run --timeout=5m
# Testing stage
FROM base AS test
# Install templ
RUN go install github.com/a-h/templ/cmd/templ@latest
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# Generate templ templates before testing
RUN echo "Generating templ templates..." && \
templ generate
# Run tests with CGO enabled for tree-sitter
ARG CI=1
RUN CGO_ENABLED=1 go test -short ./...
# Build stage for linux/amd64
FROM base AS build-amd64
# Install templ
RUN go install github.com/a-h/templ/cmd/templ@latest
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# Generate templ templates before building
RUN echo "Generating templ templates..." && \
templ generate
# Build for linux/amd64 with static linking
# TinyGo will be downloaded at runtime and cached in ~/.cache/scriptschnell/tinygo
# Use -p 1 to limit compilation parallelism and GOGC=50 to reduce memory usage
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 \
CC=x86_64-linux-gnu-gcc \
CXX=x86_64-linux-gnu-g++ \
GOGC=50 \
go build \
-p 1 \
-ldflags="-w -s -linkmode external -extldflags '-static'" \
-o scriptschnell-amd64 \
./cmd/scriptschnell
# Build stage for linux/arm64
FROM base AS build-arm64
# Install templ
RUN go install github.com/a-h/templ/cmd/templ@latest
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# Generate templ templates before building
RUN echo "Generating templ templates..." && \
templ generate
# Build for linux/arm64 with static linking
# TinyGo will be downloaded at runtime and cached in ~/.cache/scriptschnell/tinygo
# Use -p 1 to limit compilation parallelism and GOGC=50 to reduce memory usage
RUN CGO_ENABLED=1 GOOS=linux GOARCH=arm64 \
CC=aarch64-linux-gnu-gcc \
CXX=aarch64-linux-gnu-g++ \
GOGC=50 \
go build \
-p 1 \
-ldflags="-w -s -linkmode external -extldflags '-static'" \
-o scriptschnell-arm64 \
./cmd/scriptschnell
# Default build stage (amd64 for backward compatibility)
FROM build-amd64 AS build
# Build debug HTML tool (amd64)
FROM base AS build-debug
# Install templ
RUN go install github.com/a-h/templ/cmd/templ@latest
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# Generate templ templates before building
RUN echo "Generating templ templates..." && \
templ generate
# Build for linux/amd64
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 \
CC=x86_64-linux-gnu-gcc \
CXX=x86_64-linux-gnu-g++ \
go build \
-ldflags="-w -s -linkmode external -extldflags '-static'" \
-o debug_html \
./cmd/debug_html
# Development stage with all tools
FROM base AS development
RUN go install github.com/cosmtrek/air@latest && \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest && \
go install github.com/a-h/templ/cmd/templ@latest
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# Generate templ templates
RUN echo "Generating templ templates..." && \
templ generate
CMD ["air", "-c", ".air.toml"]
# Scratch-based final build (amd64)
FROM scratch AS final-build-amd64
COPY --from=build-amd64 /app/scriptschnell-amd64 /scriptschnell
ENTRYPOINT ["/scriptschnell"]
# Scratch-based final build (arm64)
FROM scratch AS final-build-arm64
COPY --from=build-arm64 /app/scriptschnell-arm64 /scriptschnell
ENTRYPOINT ["/scriptschnell"]
# Default scratch final build (amd64)
FROM final-build-amd64 AS final-build