build: reduce container image size

Install only executables and needed libraries
This commit is contained in:
Marco Ferrari 2024-05-09 12:40:06 +00:00
parent 256b22786d
commit 1905621d4e
3 changed files with 52 additions and 14 deletions

View file

@ -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:

View file

@ -363,8 +363,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 #
@ -457,13 +484,12 @@ 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
# Install Rust linters
RUN apk add --no-cache \
rust-clippy \
rustfmt
COPY scripts/clippy.sh /usr/bin/clippy
RUN chmod +x /usr/bin/clippy
COPY --chmod=0755 scripts/clippy.sh /usr/bin/clippy
#########################
# Install dotenv-linter #

View file

@ -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}'
@ -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