Skip to content

Commit 385da64

Browse files
committed
plugins: add Dockerfile for building images
Add a generic dockerfile for building container images of the reference plugins. The build command creates statically linked binaries and the resulting images are minimal, based on scratch base image. Signed-off-by: Markus Lehtonen <markus.lehtonen@intel.com>
1 parent fcd3e39 commit 385da64

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

plugins/Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright The containerd Authors.
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
ARG GO_VERSION=1.24
16+
17+
FROM golang:${GO_VERSION}-bullseye AS builder
18+
19+
ARG PLUGIN
20+
21+
WORKDIR /go/src
22+
23+
# Cache dependencies in a separate layer
24+
COPY go.mod go.sum .
25+
RUN --mount=type=cache,target=/go/pkg/mod/ go mod download
26+
27+
# Build
28+
COPY . .
29+
30+
RUN --mount=type=cache,target=/go/pkg/mod/ \
31+
make /go/src/build/bin/${PLUGIN} \
32+
GO_BUILD="CGO_ENABLED=0 go build -ldflags '-extldflags=-static'"
33+
34+
# Construct final image
35+
FROM scratch
36+
37+
COPY --from=builder /go/src/build/bin/ /bin/
38+
39+
ENTRYPOINT ["/bin/${PLUGIN}"]

0 commit comments

Comments
 (0)