Skip to content

Commit fa1516e

Browse files
committed
build(container): restructure Dockerfile so SBOM is created by 'docker buildx' command
1 parent 35bbaa7 commit fa1516e

1 file changed

Lines changed: 11 additions & 26 deletions

File tree

Dockerfile

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
FROM alpine:latest AS start
1+
ARG BUILDKIT_SBOM_SCAN_STAGE=base
2+
3+
FROM alpine:latest AS base
24

35
ARG SBOM_PACKAGES="\
4-
linux-headers \
56
openssl-dev \
67
openssl-libs-static \
78
libcap-dev \
@@ -16,6 +17,10 @@ ARG SBOM_PACKAGES="\
1617
musl \
1718
musl-dev"
1819

20+
RUN apk add --no-cache \
21+
${SBOM_PACKAGES}
22+
23+
FROM base AS start
1924
RUN apk add --no-cache \
2025
build-base \
2126
curl \
@@ -26,8 +31,8 @@ RUN apk add --no-cache \
2631
automake \
2732
ed \
2833
bash \
29-
cppunit \
30-
${SBOM_PACKAGES}
34+
linux-headers \
35+
cppunit
3136

3237
ARG SQUID_VERSION=7.4
3338

@@ -157,7 +162,7 @@ RUN export PKG_CONFIG="pkg-config --static" && \
157162
--without-gssapi \
158163
--with-libcap && \
159164
make -j$(nproc) && \
160-
make install-strip DESTDIR=/app
165+
make install-strip DESTDIR=/app man8dir=
161166

162167
RUN echo "proxy:x:1000:1000:proxy,,,:/nonexistent:/bin/false" > /app/passwd && \
163168
echo "proxy:x:1000:" > /app/group
@@ -175,32 +180,12 @@ COPY squid-init.c /src/
175180
RUN gcc -no-pie -static -pipe -O2 -o /app/usr/sbin/squid-init squid-init.c \
176181
&& strip --strip-all --remove-section=.comment --remove-section=.note /app/usr/sbin/squid-init
177182

178-
# Create the 'Shadow Root'
179-
# We install ONLY the library packages here.
180-
# This creates a clean APK database at /sbom-root/lib/apk/db
181-
RUN mkdir -p /sbom-root && \
182-
apk add --root /sbom-root \
183-
--initdb \
184-
--no-script \
185-
--no-cache \
186-
--repositories-file /etc/apk/repositories \
187-
--keys-dir /etc/apk/keys \
188-
${SBOM_PACKAGES}
189-
190-
# Run Syft against the Shadow Root
191-
# We save the result to a known location.
192-
RUN curl -LsS "https://raw.githubusercontent.com/anchore/syft/main/install.sh" | sh -s -- -b /usr/local/bin \
193-
&& syft dir:/sbom-root \
194-
--output spdx-json=/app/sbom.spdx.json \
195-
--source-name "squid" \
196-
--source-version "${SQUID_VERSION}"
197-
198183
# --- Final Stage ---
199184
FROM scratch AS final
200185

201186
COPY --from=builder /app/ /
202187
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
203-
COPY --from=builder /app/sbom.spdx.json /sbom.spdx.json
188+
#COPY --from=builder /app/sbom.spdx.json /sbom.spdx.json
204189

205190
COPY --from=builder /app/passwd /etc/passwd
206191
COPY --from=builder /app/group /etc/group

0 commit comments

Comments
 (0)