Skip to content

Commit

Permalink
build: reduce container image size
Browse files Browse the repository at this point in the history
- Remove Go source files
- Install only the Dart executable
  • Loading branch information
ferrarimarco committed May 9, 2024
1 parent e0c8376 commit 979de36
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -112,6 +112,10 @@ jobs:
run: |
docker load <"/tmp/${{ env.CONTAINER_IMAGE_OUTPUT_IMAGE_NAME }}.tar"
- name: Print environment info
run: |
make info
- name: Test Local Action (debug log)
uses: ./
env:
Expand Down
30 changes: 28 additions & 2 deletions Dockerfile
Expand Up @@ -353,9 +353,35 @@ COPY --from=clj-kondo /bin/clj-kondo /usr/bin/
####################
# Install dart-sdk #
####################
# These COPY directives may be compacted after --parents is supported
ENV DART_SDK /usr/lib/dart
COPY --from=dart "${DART_SDK}" "${DART_SDK}"
RUN chmod 755 "${DART_SDK}" && chmod 755 "${DART_SDK}/bin"
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
24 changes: 15 additions & 9 deletions Makefile
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,27 @@ 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 "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 979de36

Please sign in to comment.