Skip to content

Commit

Permalink
Reduce image size (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
artnc authored Jun 10, 2024
1 parent 49b54cb commit 294f91b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
47 changes: 27 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
FROM alpine:3.18.4
FROM alpine:3.18.4 as entry
RUN apk add --no-cache npm && npm install -g [email protected] @types/[email protected]
COPY entry.ts .
RUN tsc \
--noUnusedLocals \
--noUnusedParameters \
--strict \
--typeRoots /usr/local/lib/node_modules/@types \
entry.ts \
&& chmod +x entry.js

FROM alpine:3.18.4
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
ENV PIP_NO_CACHE_DIR=1

# Dependencies
# Install all dependencies. As the last step of this RUN, we delete unused files
# found by running `apk add ncdu && ncdu` inside `make shell`
RUN apk add --no-cache --virtual .build-deps \
gcc \
musl-dev \
npm \
py3-pip \
python3-dev \
&& apk add --no-cache \
clang-extra-tools \
libxslt \
nodejs \
openjdk17-jre-headless \
py3-pip \
python3 \
&& pip3 install \
autoflake==1.7.8 \
Expand All @@ -28,11 +37,11 @@ RUN apk add --no-cache --virtual .build-deps \
&& chmod +x /usr/bin/black21 \
&& npm install -g \
@prettier/[email protected] \
@types/[email protected] \
[email protected] \
[email protected] \
[email protected] \
&& apk del .build-deps \
&& wget https://github.com/muttleyxd/clang-tools-static-binaries/releases/download/master-f7f02c1d/clang-format-17_linux-amd64 -O clang-format \
&& chmod +x clang-format \
&& wget https://github.com/google/google-java-format/releases/download/v1.18.1/google-java-format-1.18.1-all-deps.jar -O google-java-format \
&& wget https://search.maven.org/remotecontent?filepath=com/facebook/ktfmt/0.46/ktfmt-0.46-jar-with-dependencies.jar -O ktfmt \
&& wget https://github.com/mvdan/sh/releases/download/v3.7.0/shfmt_v3.7.0_linux_amd64 -O shfmt \
Expand All @@ -49,19 +58,17 @@ RUN apk add --no-cache --virtual .build-deps \
-r sonatype:snapshots --main org.scalafmt.cli.Cli \
--standalone \
-o scalafmt \
&& rm /bin/coursier

&& touch /emptyfile \
&& rm -rf \
/bin/coursier \
/black21-venv/lib/python3.11/site-packages/pip \
/black21-venv/lib/python3.11/site-packages/pkg_resources \
/black21-venv/lib/python3.11/site-packages/setuptools \
/root/.cache \
/root/.npm \
/usr/bin/lto-dump \
/var/cache
# https://stackoverflow.com/a/59485924
COPY --from=golang:1.22.3-alpine3.18 /usr/local/go/bin/gofmt /gofmt

# Local files
COPY . .
RUN tsc \
--noUnusedLocals \
--noUnusedParameters \
--strict \
--typeRoots /usr/local/lib/node_modules/@types \
entry.ts \
&& mv entry.js entry \
&& chmod +x entry \
&& touch /emptyfile
COPY --from=entry /entry.js /entry
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This repo currently contains a single [pre-commit](https://pre-commit.com/) hook
- [shfmt](https://github.com/mvdan/sh) v3.7.0 for Shell
- [xsltproc](http://www.xmlsoft.org/xslt/xsltproc.html) from libxslt v10138 for XML
- [terraform fmt](https://github.com/hashicorp/terraform) v1.6.3 for Terraform
- [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html) v16.0.6 for Protobuf
- [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html) v17.0.4 for Protobuf
- [SVGO](https://github.com/svg/svgo) v3.0.3 for SVG
- [Taplo](https://taplo.tamasfe.dev/) v0.8.1 for TOML
- Custom regex transformations (basically [sed](https://en.wikipedia.org/wiki/Sed)), for example:
Expand Down
2 changes: 1 addition & 1 deletion entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ const HOOKS: Record<HookName, LockableHook> = {
[HookName.ClangFormat]: createLockableHook({
action: sources =>
run(
"clang-format",
"/clang-format",
"-i", // Edit files in-place
"--style=Google",
...sources,
Expand Down

0 comments on commit 294f91b

Please sign in to comment.