-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce images size #1636
Reduce images size #1636
Conversation
I really struggled with the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update kuzzle directory location in Docker image is a breaking change. Otherwise very nice job 👍
.ci/privatebuild/Dockerfile
Outdated
@@ -10,8 +10,8 @@ ARG SSH_KEY | |||
ENV GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=no" | |||
ENV NODE_ENV=production | |||
|
|||
WORKDIR /var/app | |||
COPY . /var/app | |||
WORKDIR /app |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change
bin/wait-elasticsearch
Outdated
} | ||
}; | ||
|
||
run(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run(); | |
if (require.main === module) { | |
run(); | |
} |
Else, will be called on require (i.e. from kuzzle-start)
&& ln -s /app/plugins/available/kuzzle-plugin-logger /app/plugins/enabled/kuzzle-plugin-logger \ | ||
# Install plugins dependencies | ||
&& for plugin in plugins/enabled/*; do cd "$plugin"; npm install --production; cd /app; done \ | ||
&& for plugin in plugins/available/*; do cd "$plugin"; npm install --production; cd /app; done \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&& for plugin in plugins/available/*; do cd "$plugin"; npm install --production; cd /app; done \ | |
&& for plugin in plugins/*/*; do npm install --production --prefix "$plugin"; done \ |
docker/scripts/everest-clean-node.sh
Outdated
|
||
# Minify JS & JSON | ||
# I wasn't able to find a portable way to do string comparison with if | ||
( echo $NODE_ENV | grep production ) || exit 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
( echo $NODE_ENV | grep production ) || exit 0 | |
[ "${NODE_ENV}" = "production" ] || exit 0 |
This is posix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used Shellcheck on scripts, there it is some of the easiest warning/error to correct 🙂
docker/build-docker-images.sh
Outdated
promise_run docker_build 'kuzzle' $TRAVIS_BRANCH 'kuzzle' | ||
promise_then docker_push 'kuzzle' $TRAVIS_BRANCH | ||
|
||
promise_run docker_build 'kuzzle' $TRAVIS_BRANCH-alpine 'kuzzle.alpine' | ||
promise_then docker_push 'kuzzle' $TRAVIS_BRANCH-alpine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
promise_run docker_build 'kuzzle' $TRAVIS_BRANCH 'kuzzle' | |
promise_then docker_push 'kuzzle' $TRAVIS_BRANCH | |
promise_run docker_build 'kuzzle' $TRAVIS_BRANCH-alpine 'kuzzle.alpine' | |
promise_then docker_push 'kuzzle' $TRAVIS_BRANCH-alpine | |
promise_run docker_build 'kuzzle' "$TRAVIS_BRANCH" 'kuzzle' | |
promise_then docker_push 'kuzzle' "$TRAVIS_BRANCH" | |
promise_run docker_build 'kuzzle' "$TRAVIS_BRANCH-alpine" 'kuzzle.alpine' | |
promise_then docker_push 'kuzzle' "$TRAVIS_BRANCH-alpine" |
docker/build-docker-images.sh
Outdated
promise_run docker_build 'plugin-dev' $TRAVIS_BRANCH 'plugin-dev' | ||
promise_then docker_push 'plugin-dev' $TRAVIS_BRANCH |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
promise_run docker_build 'plugin-dev' $TRAVIS_BRANCH 'plugin-dev' | |
promise_then docker_push 'plugin-dev' $TRAVIS_BRANCH | |
promise_run docker_build 'plugin-dev' "$TRAVIS_BRANCH" 'plugin-dev' | |
promise_then docker_push 'plugin-dev' "$TRAVIS_BRANCH" |
docker/build-docker-images.sh
Outdated
promise_then docker_push 'kuzzle' $TRAVIS_BRANCH | ||
|
||
promise_run docker_build 'kuzzle' $TRAVIS_BRANCH-alpine 'kuzzle.alpine' | ||
promise_then docker_push 'kuzzle' $TRAVIS_BRANCH-alpine | ||
|
||
elif [[ "$TRAVIS_BRANCH" == "master" ]] || [[ "$TRAVIS_BRANCH" == *"-stable" ]]; then | ||
RELEASE_TAG=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RELEASE_TAG=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') | |
RELEASE_TAG=$(grep version package.json | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[:space:]') |
docker/scripts/everest-clean-node.sh
Outdated
@@ -0,0 +1,22 @@ | |||
#!/bin/sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#!/bin/sh | |
#!/usr/bin/env sh |
I will wait for Kaaf before finishing this PR |
@benoitvidis About the compression, the decompression is very fast (~4-5s) and it allows to have only 19 mo transiting through the network instead of 94. It could be very useful for K8S environment where the pods have to download the new image before running for example. Also the way I copy Kuzzle still allows developers to add plugins in the I will leave the Image sizes:
|
Codecov Report
@@ Coverage Diff @@
## master #1636 +/- ##
=======================================
Coverage 93.52% 93.52%
=======================================
Files 113 113
Lines 7197 7197
=======================================
Hits 6731 6731
Misses 466 466 Continue to review full report at Codecov.
|
.ci/scripts/install-plugins.sh
Outdated
set -e | ||
set -x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set -e | |
set -x | |
set -ex |
.ci/scripts/run-test-arm.sh
Outdated
@@ -1,8 +1,7 @@ | |||
#!/bin/sh | |||
|
|||
set -e | |||
|
|||
elastic_host=${kuzzle_services__storageEngine__client__node:-http://elasticsearch:9200} | |||
set -x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set
arguments could be combined
.ci/scripts/run-test.sh
Outdated
@@ -1,57 +1,21 @@ | |||
#!/bin/sh | |||
|
|||
set -e | |||
|
|||
elastic_host=${kuzzle_services__storageEngine__client__node:-http://elasticsearch:9200} | |||
set -x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
docker/scripts/run-dev.sh
Outdated
|
||
set -e | ||
|
||
if [ ! -z "$WITHOUT_KUZZLE" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if [ ! -z "$WITHOUT_KUZZLE" ]; then | |
if [ -n "$WITHOUT_KUZZLE" ]; then |
docker/scripts/everest-extract.sh
Outdated
@@ -0,0 +1,34 @@ | |||
#!/bin/sh | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing set -e
?
Co-authored-by: Alexandre Bouthinon <[email protected]>
…zzle into reduce-production-image-size
@Aschen , I am still not sure about everest image.
These 2 points + the already discussed UX issues make me really dubious about this image. |
@benoitvidis I replaced the image by a Docker compress layers with Gzip which is not as efficient as Lzma, especially for binary files: The difference between compressed application layers is not that huge (13Mo gz vs 9.7 Mo lzma) so I agree that for subsequent download of the same image the gain won't be huge: I still think the compression is useful in a K8S environment because the pods has to download the image whenever they are spawned so it allows to save bandwidth, which is quite expensive in most of the cloud providers. But I understand your point of view and we need those smaller image so LGTM |
…zzle into reduce-production-image-size
Kudos, SonarCloud Quality Gate passed!
|
Reduce image size
Reduce Kuzzle images size:
kuzzleio/kuzzle:2
: from 563 Mo to 165 Mokuzzleio/plugin-dev:2
: from 968 Mo to 410 MoThis PR also includes 2 new tags:
kuzzleio/kuzzle:2-alpine
: 140 Mokuzzleio/kuzzle:2-scratch
: 94 MoI followed the tricks explained here: https://medium.com/trendyol-tech/how-we-reduce-node-docker-image-size-in-3-steps-ff2762b51d5a
Also I made few other changes for the production image:
.o
,.h
)lib
,config
,plugins
, etc).git
re2
andnode
binariesThe
scratch
image contains only Node.js (with libstdc++), musl and Kuzzle source code.Scripts
All docker related scripts are in
docker/scripts/
:entrypoint.sh
: the entrypointclean-node.sh
: remove every unnecessary file from a directory. IfNODE_ENV=production
then the JS and JSON files will be minifiedrun-dev.sh
: used by thecore-dev
image to run a core-developer stackrun-plugin.sh
: used byplugin-dev
to run an application composed of plugins (like we do now)run-prod.sh
: used by thekuzzle
images to run kuzzle in productionHow should this be manually tested?
Build the images and play the functional tests
Other changes
bin/wait-elasticsearch
script instead of curl