Skip to content

Commit

Permalink
build: reduce container image size
Browse files Browse the repository at this point in the history
Install only executables and needed libraries
  • Loading branch information
ferrarimarco committed Jun 13, 2024
1 parent 5b5d2f7 commit fa38374
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 19 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ jobs:
echo "Action file contents:"
cat action.yml
- name: Print environment info
run: |
make info
- name: Test Local Action (debug log)
uses: ./
env:
Expand Down
63 changes: 53 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ FROM powershell as powershell-installer
# when copying PowerShell stuff in the main image
RUN echo "${PS_INSTALL_FOLDER}" > /tmp/PS_INSTALL_FOLDER

FROM rust:1.78.0-alpine3.19 as rust

RUN apk add --no-cache \
rust-clippy \
rustfmt

FROM python:3.12.3-alpine3.19 as base_image

LABEL com.github.actions.name="Super-Linter" \
Expand Down Expand Up @@ -360,8 +366,35 @@ COPY --from=clj-kondo /bin/clj-kondo /usr/bin/
# Install dart-sdk #
####################
ENV DART_SDK /usr/lib/dart
COPY --from=dart "${DART_SDK}" "${DART_SDK}"
RUN chmod 755 "${DART_SDK}" && chmod 755 "${DART_SDK}/bin"
# These COPY directives may be compacted after --parents is supported
COPY --from=dart --chmod=0755 \
"${DART_SDK}/version" \
"${DART_SDK}"/
COPY --from=dart --chmod=0755 \
"${DART_SDK}/bin/dart" \
"${DART_SDK}/bin/dart.sym" \
"${DART_SDK}/bin"/
COPY --from=dart --chmod=0755 \
"${DART_SDK}/bin/snapshots/analysis_server.dart.snapshot" \
"${DART_SDK}/bin/snapshots/dartdev.dart.snapshot" \
"${DART_SDK}/bin/snapshots/frontend_server_aot.dart.snapshot" \
"${DART_SDK}/bin/snapshots"/
COPY --from=dart --chmod=0755 \
"${DART_SDK}/lib/_internal" \
"${DART_SDK}/lib/_internal"
COPY --from=dart --chmod=0755 \
"${DART_SDK}/lib/async" \
"${DART_SDK}/lib/async"
COPY --from=dart --chmod=0755 \
"${DART_SDK}/lib/convert" \
"${DART_SDK}/lib/convert"
COPY --from=dart --chmod=0755 \
"${DART_SDK}/lib/core" \
"${DART_SDK}/lib/core"
COPY --from=dart --chmod=0755 \
"${DART_SDK}/lib/io" \
"${DART_SDK}/lib/io"


########################
# Install clang-format #
Expand Down Expand Up @@ -454,14 +487,6 @@ ARG TARGETARCH
ENV ARM_TTK_PSD1="/usr/lib/microsoft/arm-ttk/arm-ttk.psd1"
ENV PATH="${PATH}:/var/cache/dotnet/tools:/usr/share/dotnet"

# Install super-linter runtime dependencies
RUN apk add --no-cache \
rust-clippy \
rustfmt

COPY scripts/clippy.sh /usr/bin/clippy
RUN chmod +x /usr/bin/clippy

#########################
# Install dotenv-linter #
#########################
Expand Down Expand Up @@ -495,6 +520,24 @@ RUN PS_INSTALL_FOLDER="$(cat /tmp/PS_INSTALL_FOLDER)" \
COPY scripts/install-arm-ttk.sh /
RUN --mount=type=secret,id=GITHUB_TOKEN /install-arm-ttk.sh && rm -rf /install-arm-ttk.sh

# Install Rust linters
COPY --from=rust \
/usr/bin/cargo \
/usr/bin/cargo-clippy \
/usr/bin/clippy-driver \
/usr/bin/cargo-fmt \
/usr/bin/rustc \
/usr/bin/rustfmt \
/usr/bin/
COPY --from=rust \
/usr/lib/libLLVM-17.so \
/usr/lib/librustc_driver-56e2d9f25bcc525c.so \
/usr/lib/libscudo.so \
/usr/lib/libstd-01072ff1a54ef56b.so \
/usr/lib/

COPY --chmod=0755 scripts/clippy.sh /usr/bin/clippy

# Run to build version file and validate image again because we installed more linters
ENV IMAGE="standard"
COPY scripts/linterVersions.sh /
Expand Down
26 changes: 17 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ ifeq ($(INTERACTIVE), 1)
DOCKER_FLAGS += -t
endif

.PHONY: info
info: ## Gather information about the runtime environment
echo "whoami: $$(whoami)"; \
echo "pwd: $$(pwd)"; \
echo "ls -ahl: $$(ls -ahl)"; \
docker images; \
docker ps

.PHONY: help
help: ## Show help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
Expand Down Expand Up @@ -79,13 +71,29 @@ endif

DEV_CONTAINER_URL := "super-linter/dev-container:latest"


ifeq ($(GITHUB_HEAD_REF),)
RELEASE_PLEASE_TARGET_BRANCH := "$(shell git branch --show-current)"
else
RELEASE_PLEASE_TARGET_BRANCH := "${GITHUB_HEAD_REF}"
endif

.PHONY: info
info: ## Gather information about the runtime environment
echo "whoami: $$(whoami)"; \
echo "pwd: $$(pwd)"; \
echo "IMAGE:" $(IMAGE) \
echo "SUPER_LINTER_TEST_CONTAINER_URL:" $(SUPER_LINTER_TEST_CONTAINER_URL) \
echo "ls -ahl: $$(ls -ahl)"; \
docker images; \
docker ps; \
echo "Container image layers size:"; \
docker history \
--human \
--no-trunc \
--format "{{.Size}} {{.CreatedSince}} {{.CreatedBy}}" \
$(SUPER_LINTER_TEST_CONTAINER_URL) \
| sort --human

.PHONY: check-github-token
check-github-token:
@if [ ! -f "${GITHUB_TOKEN_PATH}" ]; then echo "Cannot find the file to load the GitHub access token: $(GITHUB_TOKEN_PATH). Create a readable file there, and populate it with a GitHub personal access token."; exit 1; fi
Expand Down

0 comments on commit fa38374

Please sign in to comment.