Skip to content

Commit 2ef7d58

Browse files
chore: update package dependencies when building image (#2665)
* chore: update package dependencies when building image Install available updates alongside installation of packages to remove known vulnerabilities from images. Example for issues in plain alpine:3 image (v3.20): ```sh $ grype alpine:3 ✔ Vulnerability DB [updated] ✔ Loaded image alpine:3 ✔ Parsed image sha256:1d34ffeaf190be23d3de5a8de0a436676b758f48f ✔ Cataloged contents dac15f325cac528994a5efe78787cd03bdd796979bda52fd ├── ✔ Packages [14 packages] ├── ✔ File digests [77 files] ├── ✔ File metadata [77 locations] └── ✔ Executables [17 executables] ✔ Scanned for vulnerabilities [8 vulnerability matches] ├── by severity: 0 critical, 0 high, 6 medium, 0 low, 0 negligible (2 unknown) └── by status: 8 fixed, 0 not-fixed, 0 ignored NAME INSTALLED FIXED-IN TYPE VULNERABILITY SEVERITY busybox 1.36.1-r28 1.36.1-r29 apk CVE-2023-42365 Medium busybox 1.36.1-r28 1.36.1-r29 apk CVE-2023-42364 Medium busybox-binsh 1.36.1-r28 1.36.1-r29 apk CVE-2023-42365 Medium busybox-binsh 1.36.1-r28 1.36.1-r29 apk CVE-2023-42364 Medium libcrypto3 3.3.0-r2 3.3.0-r3 apk CVE-2024-4741 Unknown libssl3 3.3.0-r2 3.3.0-r3 apk CVE-2024-4741 Unknown ssl_client 1.36.1-r28 1.36.1-r29 apk CVE-2023-42365 Medium ssl_client 1.36.1-r28 1.36.1-r29 apk CVE-2023-42364 Medium ``` Issue would be solved by also upgrading installed packages: ```sh $ apk -U upgrade --no-cache fetch https://dl-cdn.alpinelinux.org/alpine/v3.20/main/x86_64/APKINDEX.tar.gz fetch https://dl-cdn.alpinelinux.org/alpine/v3.20/community/x86_64/APKINDEX.tar.gz (1/5) Upgrading busybox (1.36.1-r28 -> 1.36.1-r29) Executing busybox-1.36.1-r29.post-upgrade (2/5) Upgrading busybox-binsh (1.36.1-r28 -> 1.36.1-r29) (3/5) Upgrading libcrypto3 (3.3.0-r2 -> 3.3.1-r0) (4/5) Upgrading libssl3 (3.3.0-r2 -> 3.3.1-r0) (5/5) Upgrading ssl_client (1.36.1-r28 -> 1.36.1-r29) Executing busybox-1.36.1-r29.trigger OK: 8 MiB in 14 packages ``` Furthermore, this commit reduces accidental complexity from the Docker build process. Most notably, use pre-made official golang images for building postgres-operator. * Update docker/DebugDockerfile --------- Co-authored-by: Ida Novindasari <[email protected]>
1 parent 7c7aa96 commit 2ef7d58

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

docker/DebugDockerfile

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
FROM registry.opensource.zalan.do/library/alpine-3.15:latest
1+
FROM golang:1.22-alpine
22
LABEL maintainer="Team ACID @ Zalando <[email protected]>"
33

44
# We need root certificates to deal with teams api over https
5-
RUN apk --no-cache add ca-certificates go git musl-dev
5+
RUN apk -U add --no-cache ca-certificates delve
66

77
COPY build/* /
88

99
RUN addgroup -g 1000 pgo
1010
RUN adduser -D -u 1000 -G pgo -g 'Postgres Operator' pgo
1111

12-
RUN go get -d github.com/derekparker/delve/cmd/dlv
13-
RUN cp /root/go/bin/dlv /dlv
14-
RUN chown -R pgo:pgo /dlv
15-
1612
USER pgo:pgo
1713
RUN ls -l /
1814

docker/Dockerfile

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
ARG BASE_IMAGE=registry.opensource.zalan.do/library/alpine-3:latest
2+
FROM golang:1.22-alpine AS builder
23
ARG VERSION=latest
34

4-
FROM ubuntu:20.04 as builder
5-
6-
ARG VERSION
7-
85
COPY . /go/src/github.com/zalando/postgres-operator
96
WORKDIR /go/src/github.com/zalando/postgres-operator
107

11-
ENV OPERATOR_LDFLAGS="-X=main.version=${VERSION}"
12-
RUN bash docker/build_operator.sh
8+
RUN GO111MODULE=on go mod vendor \
9+
&& CGO_ENABLED=0 go build -o build/postgres-operator -v -ldflags "-X=main.version=${VERSION}" cmd/main.go
1310

1411
FROM ${BASE_IMAGE}
1512
LABEL maintainer="Team ACID @ Zalando <[email protected]>"
1613
LABEL org.opencontainers.image.source="https://github.com/zalando/postgres-operator"
1714

1815
# We need root certificates to deal with teams api over https
19-
RUN apk --no-cache add curl
20-
RUN apk --no-cache add ca-certificates
16+
RUN apk -U upgrade --no-cache \
17+
&& apk add --no-cache curl ca-certificates
2118

2219
COPY --from=builder /go/src/github.com/zalando/postgres-operator/build/* /
2320

0 commit comments

Comments
 (0)