Skip to content

Commit a5f933d

Browse files
committed
chore: update container images
- Updates the default container images to pass the `GO_VERSION` as a build argument. - Adds a minimal Alpine-based image that can be used as runner image requested by the community. Signed-off-by: Ryan Johnson <[email protected]>
1 parent a77f020 commit a5f933d

File tree

6 files changed

+198
-127
lines changed

6 files changed

+198
-127
lines changed

.goreleaser.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
version: 2
33
project_name: govmomi
44

5+
env:
6+
- GO_VERSION=1.24
7+
- ALPINE_VERSION=3.21
8+
59
builds:
610
- id: govc
711
no_main_check: true
@@ -111,6 +115,30 @@ dockers:
111115
- "--label=org.opencontainers.image.version={{.Version}}"
112116
- "--label=org.opencontainers.image.url=https://github.com/vmware/govmomi"
113117
- "--platform=linux/amd64"
118+
- "--build-arg=GO_VERSION={{.Env.GO_VERSION}}"
119+
120+
- image_templates:
121+
- "vmware/govc:{{ .Tag }}-runner"
122+
- "vmware/govc:alpine-{{ .Tag }}-runner"
123+
- "vmware/govc:{{ .ShortCommit }}-runner"
124+
- "vmware/govc:alpine-{{ .ShortCommit }}-runner"
125+
- "vmware/govc:latest-runner"
126+
- "vmware/govc:alpine-latest-runner"
127+
dockerfile: Dockerfile.govc.runner
128+
ids:
129+
- govc
130+
extra_files:
131+
- scripts/runner/entrypoint.sh
132+
build_flag_templates:
133+
- "--pull"
134+
- "--label=org.opencontainers.image.created={{.Date}}"
135+
- "--label=org.opencontainers.image.title={{.ProjectName}}"
136+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
137+
- "--label=org.opencontainers.image.version={{.Version}}"
138+
- "--label=org.opencontainers.image.url=https://github.com/vmware/govmomi"
139+
- "--platform=linux/amd64"
140+
- "--build-arg=ALPINE_VERSION={{.Env.ALPINE_VERSION}}"
141+
114142
- image_templates:
115143
- "vmware/vcsim:{{ .Tag }}"
116144
- "vmware/vcsim:{{ .ShortCommit }}"
@@ -126,3 +154,4 @@ dockers:
126154
- "--label=org.opencontainers.image.version={{.Version}}"
127155
- "--label=org.opencontainers.image.url=https://github.com/vmware/govmomi"
128156
- "--platform=linux/amd64"
157+
- "--build-arg=GO_VERSION={{.Env.GO_VERSION}}"

Dockerfile.govc

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
# Create a builder container
2-
# Reference: https://hub.docker.com/_/golang/tags
3-
# Note: Official Docker images for Go use Debian.
1+
# © Broadcom. All Rights Reserved.
2+
# The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# --- Builder Stage ---
6+
# Uses the official Go Docker image for the build.
7+
48
ARG GO_VERSION
5-
FROM golang:1.23.0 AS build
9+
FROM golang:${GO_VERSION} AS build
610
WORKDIR /go/src/app
711

8-
# Create appuser to isolate potential vulnerabilities
9-
# Reference: https://stackoverflow.com/a/55757473/12429735
1012
ENV USER=appuser
1113
ENV UID=10001
1214
RUN adduser \
@@ -17,31 +19,23 @@ RUN adduser \
1719
--uid "${UID}" \
1820
"${USER}"
1921

20-
# Create a new tmp directory so no bad actors can manipulate it
2122
RUN mkdir /temporary-tmp-directory && chmod 777 /temporary-tmp-directory
2223

23-
###############################################################################
24-
# Final stage
24+
# --- Final Stage ---
25+
2526
FROM scratch
2627

27-
# Allow container to use latest TLS certificates
2828
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
2929

30-
# Copy over appuser to run as non-root
3130
COPY --from=build /etc/passwd /etc/passwd
3231
COPY --from=build /etc/group /etc/group
3332

34-
# Copy over the /tmp directory for golang/os.TmpDir
3533
COPY --chown=appuser --from=build /temporary-tmp-directory /tmp
3634

37-
# Copy application from external build
3835
COPY govc /govc
3936

40-
# Run all commands as non-root
4137
USER appuser:appuser
4238

43-
# session cache, etc
4439
ENV GOVMOMI_HOME=/tmp
4540

46-
# Set CMD to application with container defaults
4741
CMD ["/govc"]

Dockerfile.govc.runner

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# © Broadcom. All Rights Reserved.
2+
# The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
ARG ALPINE_VERSION
6+
FROM alpine:${ALPINE_VERSION}
7+
8+
ENV USER=appuser
9+
ENV UID=10001
10+
11+
RUN adduser \
12+
--disabled-password \
13+
--gecos "" \
14+
--shell "/sbin/nologin" \
15+
--no-create-home \
16+
--uid "${UID}" \
17+
"${USER}" && \
18+
mkdir -p /home/${USER} /tmp && \
19+
chown -R "${USER}:${USER}" /home/${USER} /tmp && \
20+
apk --no-cache add --no-check-certificate ca-certificates && \
21+
update-ca-certificates && \
22+
rm -rf /var/cache/apk/*
23+
24+
COPY govc /usr/local/bin/govc
25+
RUN chmod +x /usr/local/bin/govc
26+
27+
COPY scripts/runner/entrypoint.sh /entrypoint.sh
28+
RUN chmod +x /entrypoint.sh
29+
30+
USER "${USER}"
31+
32+
ENV GOVMOMI_HOME=/tmp
33+
ENV PATH="$PATH:/usr/local/bin"
34+
35+
ENTRYPOINT ["/entrypoint.sh"]
36+
37+
WORKDIR /home/${USER}

Dockerfile.vcsim

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,42 @@
1-
# Create a builder container
2-
# Reference: https://hub.docker.com/_/golang/tags
3-
# Note: Official Docker images for Go use Debian.
1+
# © Broadcom. All Rights Reserved.
2+
# The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# --- Builder Stage ---
6+
# Uses the official Go Docker image to for the build.
7+
48
ARG GO_VERSION
5-
FROM golang:1.23.0 AS build
9+
FROM golang:${GO_VERSION} AS build
610
WORKDIR /go/src/app
711

8-
# Create appuser to isolate potential vulnerabilities
9-
# Reference: https://stackoverflow.com/a/55757473/12429735
1012
ENV USER=appuser
1113
ENV UID=10001
1214
RUN adduser \
1315
--disabled-password \
1416
--gecos "" \
15-
--home "/nonexistent" \
1617
--shell "/sbin/nologin" \
1718
--no-create-home \
1819
--uid "${UID}" \
1920
"${USER}"
2021

21-
# Create a new tmp directory so no bad actors can manipulate it
2222
RUN mkdir /temporary-tmp-directory && chmod 777 /temporary-tmp-directory
2323

24-
###############################################################################
25-
# Final stage
24+
# --- Final Stage ---
2625
FROM scratch
2726

28-
# Run all commands as non-root
2927
USER appuser:appuser
3028

31-
# Allow container to use latest TLS certificates
3229
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
3330

34-
# Copy over appuser to run as non-root
3531
COPY --from=build /etc/passwd /etc/passwd
3632
COPY --from=build /etc/group /etc/group
3733

38-
# Copy over the /tmp directory for golang/os.TmpDir
3934
COPY --chown=appuser --from=build /temporary-tmp-directory /tmp
4035

41-
# Expose application port
4236
EXPOSE 8989
4337

44-
# Copy application from external build
4538
COPY vcsim /vcsim
4639

47-
# Set entrypoint to application with container defaults
4840
ENTRYPOINT [ "/vcsim" ]
41+
4942
CMD ["-l", "0.0.0.0:8989"]

0 commit comments

Comments
 (0)