Skip to content

Commit 979b05b

Browse files
authored
build: include semgrep in final docker image (#1079)
add support for Semgrep in the final macaron docker build using multistage docker builds. Signed-off-by: Carl Flottmann <carl.flottmann@oracle.com>
1 parent d1a7bb9 commit 979b05b

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

.github/workflows/_build_docker.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2023 - 2024, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2023 - 2025, Oracle and/or its affiliates. All rights reserved.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.
33

44
# This is a reuseable workflow to build and test the Docker image. Note that this workflow does not
@@ -53,6 +53,10 @@ jobs:
5353
echo "Hash of package should be $ARTIFACT_HASH."
5454
echo "$ARTIFACT_HASH" | base64 --decode | sha256sum --strict --check --status || exit 1
5555
56+
# Login so the docker build has access to the internal dependencies image
57+
- name: Log in to GitHub Container Registry
58+
run: docker login ghcr.io --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }}
59+
5660
# Build the Docker image without pushing it.
5761
- name: Build the Docker image
5862
env:

.github/workflows/build_semgrep_wheel.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Copyright (c) 2025 - 2025, Oracle and/or its affiliates. All rights reserved.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.
33

4+
# This is a manually-triggered workflow to build the minimal macaron dependencies image that stores the built-from-source
5+
# Semgrep wheel file. Note that this workflow DOES push the built image.
6+
47
name: Build Semgrep Wheel Artifact
58

69
on: workflow_dispatch
@@ -48,6 +51,6 @@ jobs:
4851
cd wheels
4952
WHEEL=$(find . -type f -name 'semgrep-*manylinux*.whl')
5053
echo "FROM scratch
51-
COPY ${WHEEL} /semgrep_wheel.whl" >> Dockerfile.semgrep
54+
COPY ${WHEEL} /" >> Dockerfile.semgrep
5255
docker build -t ghcr.io/oracle/macaron-deps:latest -f Dockerfile.semgrep .
5356
docker push ghcr.io/oracle/macaron-deps:latest

docker/Dockerfile.final

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
# Copyright (c) 2022 - 2023, Oracle and/or its affiliates. All rights reserved.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.
33

4-
# This Dockerfile is for building the final production image. It's based on ghcr.io/oracle/macaron-base.
5-
# For the build, two files will be copied into the image:
4+
# This Dockerfile is for building the final production image. It's based on ghcr.io/oracle/macaron-base and ghcr.io/oracle/maracon-deps.
5+
# For the build, three files will be copied into the image:
66
# - Macaron wheel file (its path must be provided to the build argument WHEEL_PATH)
7+
# - Macaron dependency files, copied from the macaron-deps image.
78
# - user.sh for the entrypoint of the final image.
89
# For example, using Docker, we could build the image using:
910
# docker build --build-arg WHEEL_PATH=<path_to_wheel> -t ghcr.io/oracle/macaron -f docker/Dockerfile.final ./
1011
# Note that the local machine must login to ghcr.io so that Docker could pull the ghcr.io/oracle/macaron-base
1112
# image for this build.
1213

14+
FROM ghcr.io/oracle/macaron-deps:latest@sha256:99526baf6596c4c3f24e4caa2b59afaf7f7c26d633ad3113ca24ba43dfad3f0f as deps_stage
15+
1316
FROM ghcr.io/oracle/macaron-base:latest@sha256:79b3b8b03cb9b6a124c6450f4baa58f96f83ee9e37f572c88a97597b35c7bc51
1417

1518
ENV HOME="/home/macaron"
@@ -34,11 +37,17 @@ ARG WHEEL_PATH
3437
# the warning of not having correct ownership of /home/macaron is not raised.
3538
USER macaron:macaron
3639
COPY --chown=macaron:macaron $WHEEL_PATH $HOME/dist/
40+
# Currently, the only dependency stored in the minimal image is the wheel for Semgrep, which we copy here. Since the
41+
# Macaron project dependencies lists Semgrep as a python dependency, we uninstall it first before using our wheel here
42+
# to install a trusted built-from-source version.
43+
COPY --chown=macaron:macaron --from=deps_stage /semgrep-*manylinux*.whl $HOME/dist/
3744
RUN : \
3845
&& python3 -m venv $HOME/.venv \
3946
&& . .venv/bin/activate \
4047
&& pip install --no-compile --no-cache-dir --upgrade pip setuptools \
4148
&& find $HOME/dist -depth \( -type f \( -name "macaron-*.whl" \) \) -exec pip install --no-compile --no-cache-dir '{}' \; \
49+
&& pip uninstall semgrep \
50+
&& find $HOME/dist -depth \( -type f \( -name "semgrep-*.whl" \) \) -exec pip install --no-compile --no-cache-dir '{}' \; \
4251
&& rm -rf $HOME/dist \
4352
&& deactivate
4453

0 commit comments

Comments
 (0)