Skip to content

Commit bae78a0

Browse files
authored
re-arrange Dockerfile commands to decrease image size and increase number of cache hits (localstack#4955)
1 parent 82e1be1 commit bae78a0

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.git
12
.venv*
23
localstack/dashboard/web/node_modules/
34
localstack/infra/

Dockerfile

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@ ENV PYTHONUNBUFFERED=1
117117
ENV EDGE_BIND_HOST=0.0.0.0
118118
ENV LOCALSTACK_HOSTNAME=localhost
119119

120-
# Create the infra folder (will be populated later)
121-
RUN mkdir -p /opt/code/localstack/localstack/infra
122-
123120
RUN mkdir /root/.serverless; chmod -R 777 /root/.serverless
124121

125122
# add trusted CA certificates to the cert store
@@ -178,9 +175,6 @@ RUN make freeze > requirements-runtime.txt
178175
# remove localstack (added as a transitive dependency of localstack-ext)
179176
RUN (virtualenv .venv && source .venv/bin/activate && pip3 uninstall -y localstack)
180177

181-
# add the results of `make init` to the container. `make init` _needs_ to be executed before building this docker image.
182-
ADD localstack/infra/ localstack/infra/
183-
184178

185179

186180
# base-light: Stage which does not add additional dependencies (like elasticsearch)
@@ -251,16 +245,19 @@ RUN mkdir -p /.npm && \
251245
useradd -ms /bin/bash localstack && \
252246
ln -s `pwd` /tmp/localstack_install_dir
253247

248+
# Install the latest version of awslocal globally
249+
RUN pip3 install --upgrade awscli awscli-local requests
250+
254251
# Add the code in the last step
252+
# Also adds the results of `make init` to the container.
253+
# `make init` _needs_ to be executed before building this docker image (since the execution needs docker itself).
255254
ADD localstack/ localstack/
256255

257256
# Download some more dependencies (make init needs the LocalStack code)
258-
# FIXME the init python code should be independent and executed in the builder stage
257+
# FIXME the init python code should be independent (i.e. not depend on the localstack code), idempotent/reproducible,
258+
# modify only folders outside of the localstack package folder, and executed in the builder stage.
259259
RUN make init
260260

261-
# Install the latest version of awslocal globally
262-
RUN pip3 install --upgrade awscli awscli-local requests
263-
264261
# Install the latest version of localstack-ext and generate the plugin entrypoints
265262
RUN (virtualenv .venv && source .venv/bin/activate && \
266263
pip3 install --upgrade localstack-ext localstack-plugin-loader)

Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,20 @@ docker-image-stats: ## TODO remove when image size is acceptable
7070
docker image inspect $(IMAGE_NAME_FULL) --format='{{.Size}}'
7171
docker history $(IMAGE_NAME_FULL)
7272

73-
TAG ?= $(IMAGE_NAME_FULL) # By default we export the full image
74-
EXPORT_SUFFIX ?= # By default we use no suffix
73+
# By default we export the full image
74+
TAG ?= $(IMAGE_NAME_FULL)
75+
# By default we use no suffix
76+
EXPORT_SUFFIX ?=
7577
docker-save-image: ## Export the built Docker image
7678
docker save $(TAG) -o target/localstack-docker-image$(EXPORT_SUFFIX)-$(PLATFORM).tar
7779

7880
docker-save-image-light:
7981
make EXPORT_SUFFIX="-light" TAG=$(IMAGE_NAME_LIGHT) docker-save-image
8082

81-
TAG ?= $(IMAGE_NAME_FULL) # By default we build the full image
82-
DOCKER_BUILD_FLAGS ?= "--load" # By default we load the result to the docker daemon
83+
# By default we export the full image
84+
TAG ?= $(IMAGE_NAME_FULL)
85+
# By default we load the result to the docker daemon
86+
DOCKER_BUILD_FLAGS ?= "--load"
8387
docker-build: ## Build Docker image
8488
# prepare
8589
test -e 'localstack/infra/stepfunctions/StepFunctionsLocal.jar' || make init

0 commit comments

Comments
 (0)