forked from localstack/localstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.s3
130 lines (103 loc) · 5.3 KB
/
Dockerfile.s3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# base: Stage which installs necessary runtime dependencies (OS packages, filesystem...)
FROM python:3.11.10-slim-bookworm@sha256:5501a4fe605abe24de87c2f3d6cf9fd760354416a0cad0296cf284fddcdca9e2 AS base
ARG TARGETARCH
# set workdir
RUN mkdir -p /opt/code/localstack
RUN mkdir /opt/code/localstack/localstack-core
WORKDIR /opt/code/localstack/
# Install runtime OS package dependencies
RUN --mount=type=cache,target=/var/cache/apt \
apt-get update && \
# Install dependencies to add additional repos
apt-get install -y --no-install-recommends \
# Runtime packages (groff-base is necessary for AWS CLI help)
ca-certificates curl make openssl
# TODO: add this if we need the DNS server: iputils-ping iproute2
SHELL [ "/bin/bash", "-c" ]
# create localstack user and filesystem hierarchy, perform some permission fixes
RUN chmod 777 . && \
useradd -ms /bin/bash localstack && \
mkdir -p /var/lib/localstack && \
chmod -R 777 /var/lib/localstack && \
mkdir -p /usr/lib/localstack && \
mkdir /tmp/localstack && \
chmod -R 777 /tmp/localstack && \
touch /tmp/localstack/.marker
# install the entrypoint script
ADD bin/docker-entrypoint.sh /usr/local/bin/
# add the shipped hosts file to prevent performance degredation in windows container mode on windows
# (where hosts file is not mounted) See https://github.com/localstack/localstack/issues/5178
ADD bin/hosts /etc/hosts
# expose default environment
# Set edge bind host so localstack can be reached by other containers
# set library path and default LocalStack hostname
ENV USER=localstack
ENV PYTHONUNBUFFERED=1
# builder: Stage which installs the dependencies of LocalStack Community
FROM base AS builder
ARG TARGETARCH
# Install build dependencies to base
RUN --mount=type=cache,target=/var/cache/apt \
apt-get update && \
# Install dependencies to add additional repos
apt-get install -y gcc
# upgrade python build tools
RUN --mount=type=cache,target=/root/.cache \
(python3 -m venv .venv && . .venv/bin/activate && pip3 install --upgrade pip wheel setuptools setuptools_scm build)
# add files necessary to install all dependencies
ADD Makefile pyproject.toml requirements-base-runtime.txt ./
# add the localstack start scripts (necessary for the installation of the runtime dependencies, i.e. `pip install -e .`)
ADD bin/localstack bin/localstack.bat bin/localstack-supervisor bin/
# Install dependencies for running the LocalStack base runtime (for S3)
RUN --mount=type=cache,target=/root/.cache \
. .venv/bin/activate && pip3 install -r requirements-base-runtime.txt
# delete the botocore specs for other services (>80mb)
# TODO: well now it's compressed and it's much lighter: 20mb maybe not worth it
RUN find .venv/lib/python3.11/site-packages/botocore/data/ -mindepth 1 -maxdepth 1 -type d -not -name s3 -exec rm -rf '{}' \;
# final stage: Builds upon base stage and copies resources from builder stages
FROM base
COPY --from=builder /opt/code/localstack/.venv /opt/code/localstack/.venv
# The build version is set in the docker-helper.sh script to be the output of setuptools_scm
ARG LOCALSTACK_BUILD_VERSION
# add project files necessary to install all dependencies
ADD Makefile pyproject.toml requirements-base-runtime.txt ./
# add the localstack start scripts (necessary for the installation of the runtime dependencies, i.e. `pip install -e .`)
ADD bin/localstack bin/localstack.bat bin/localstack-supervisor bin/
# add the code as late as possible
ADD localstack-core/ /opt/code/localstack/localstack-core
# Install LocalStack Community and generate the version file while doing so
RUN --mount=type=cache,target=/root/.cache \
. .venv/bin/activate && \
SETUPTOOLS_SCM_PRETEND_VERSION_FOR_LOCALSTACK_CORE=${LOCALSTACK_BUILD_VERSION} \
pip install -e .[base-runtime]
# Generate the plugin entrypoints
RUN SETUPTOOLS_SCM_PRETEND_VERSION_FOR_LOCALSTACK_CORE=${LOCALSTACK_BUILD_VERSION} \
make entrypoints
# link the python package installer virtual environments into the localstack venv
RUN echo /var/lib/localstack/lib/python-packages/lib/python3.11/site-packages > localstack-var-python-packages-venv.pth && \
mv localstack-var-python-packages-venv.pth .venv/lib/python*/site-packages/
RUN echo /usr/lib/localstack/python-packages/lib/python3.11/site-packages > localstack-static-python-packages-venv.pth && \
mv localstack-static-python-packages-venv.pth .venv/lib/python*/site-packages/
# expose edge service and debugpy
EXPOSE 4566 5678
HEALTHCHECK --interval=10s --start-period=15s --retries=5 --timeout=5s CMD .venv/bin/localstack status services --format=json
# default volume directory
VOLUME /var/lib/localstack
# mark the image version
RUN touch /usr/lib/localstack/.s3-version
LABEL authors="LocalStack Contributors"
LABEL maintainer="LocalStack Team ([email protected])"
LABEL description="LocalStack S3 Docker image"
# Add the build date and git hash at last (changes everytime)
ARG LOCALSTACK_BUILD_DATE
ARG LOCALSTACK_BUILD_GIT_HASH
ENV LOCALSTACK_BUILD_DATE=${LOCALSTACK_BUILD_DATE}
ENV LOCALSTACK_BUILD_GIT_HASH=${LOCALSTACK_BUILD_GIT_HASH}
ENV LOCALSTACK_BUILD_VERSION=${LOCALSTACK_BUILD_VERSION}
ENV EAGER_SERVICE_LOADING=1
ENV SERVICES=s3
ENV GATEWAY_SERVER=twisted
# TODO: do we need DNS for the S3 image?
ENV DNS_ADDRESS=false
# define command at startup
ENTRYPOINT ["docker-entrypoint.sh"]