Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit 17b18d2

Browse files
authoredMar 12, 2024
Update Docker files to work better with our automation scripts and im… (#15)
* Update Docker files to work better with our automation scripts and improve caching. * Move the Args under the from, otherwise they don't do anything * Enable caching for apt & poetry downloads (>10x speedup) * Remove chowning of files and just check that the files are properly owned * Split Makefile into "local build" and "docker build" targets. Tweak the one shared one. * Resort Makefile target order to match Dockerfile. * Add checks in the Makefile for various errors and to be able to find the cache files. * Put a hacky repo name in the opensearch-rps Dockerfile.
1 parent e7a3ee4 commit 17b18d2

File tree

3 files changed

+48
-27
lines changed

3 files changed

+48
-27
lines changed
 

‎Dockerfile

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,43 @@
1+
# Repo name: arynai/remote-processor-service
12

3+
##########
4+
# Common: resolve dependencies
5+
FROM python:3.11 AS rps_common
26

7+
ARG RPS_PORT=2796
38
ARG POETRY_NO_INTERACTION=1
49
ARG POETRY_VIRTUALENVS_IN_PROJECT=1
5-
ARG POETRY_VIRTUALENVS_CREATE=1 \
10+
ARG POETRY_VIRTUALENVS_CREATE=1
611
ARG POETRY_CACHE_DIR=/tmp/poetry_cache
7-
ARG RPS_PORT=2796
8-
9-
##########
10-
# Common: resolve dependencies
11-
FROM python:3.11 AS rps_common
1212

1313
# Is there some way to keep this common layer common across all our services?
1414
# E.g. maybe we can have an image called 'aryn_service_base' or something
1515
# - setup aryn user and directory
1616
# - install commonly used software (poetry, maybe protoc)
1717
# And then we can just layer services on top?
18-
WORKDIR /aryn
18+
19+
WORKDIR /aryn/
1920
COPY ./Makefile ./
2021
RUN make aryn_user
21-
RUN make install_poetry
22+
RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
23+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
24+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
25+
make install_poetry
2226

2327
USER aryn
2428
WORKDIR /aryn/rps/
2529
COPY --chown=aryn:aryn ./poetry.lock ./pyproject.toml ./
26-
RUN make -f ../Makefile common_build
30+
RUN --mount=type=cache,id=cache_poetry_1000,target=/tmp/poetry_cache,uid=1000,gid=1000,sharing=locked \
31+
make -f ../Makefile common_build
2732

2833
##########
2934
# Build: build package, compile protobufs
3035
FROM rps_common AS rps_build
3136

3237
# Build the proto files into python
3338
COPY --chown=aryn:aryn ./protocols ./protocols
34-
RUN make -f ../Makefile build_proto
39+
RUN --mount=type=cache,id=cache_poetry_1000,target=/tmp/poetry_cache,uid=1000,gid=1000,sharing=locked \
40+
make -f ../Makefile docker_build_proto
3541

3642
##########
3743
# Run: run the server
@@ -45,7 +51,7 @@ COPY --chown=aryn:aryn ./config ./config
4551
COPY --chown=aryn:aryn ./rps_docker_entrypoint.sh ./
4652
RUN make -f ../Makefile server_build
4753
RUN chmod +x rps_docker_entrypoint.sh
48-
RUN chown -R aryn:aryn .
54+
RUN make -f ../Makefile user_check
4955

5056
EXPOSE $RPS_PORT
5157

‎Makefile

+30-16
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,51 @@
11
help:
2-
@echo "install_poetry: installs poetry on ubuntu"
2+
@echo "install_rps: installs dependencies, builds proto, then installs the package"
33
@echo "clean: clean up grpc-generated code (by deletion)"
44
@echo "build_proto: generate code from the .proto files in protocols/proto-remote-processor"
5-
@echo "install_rps: installs dependencies, builds proto, then installs the package"
6-
@echo "common_build: install main dependencies"
7-
@echo "server_build: install the package, but not the dependencies"
8-
9-
install_poetry:
10-
apt update
11-
DEBIAN_FRONTEND=noninteractive apt -y install --no-install-recommends python3-poetry gcc python3-dev
12-
apt clean
13-
-rm -rf /var/lib/apt/lists/*
14-
poetry config virtualenvs.path /rps/poetry_venv
155

166
clean:
177
-rm -rd proto_remote_processor
188

199
build_proto:
20-
poetry install --no-root --only build
2110
poetry run python -m grpc_tools.protoc -I protocols/ --python_out=. --pyi_out=. --grpc_python_out=. protocols/proto-remote-processor/*.proto
2211

2312
install_rps:
2413
poetry install --no-root
2514
make build_proto
2615
poetry install --only-root
2716

17+
### Docker steps sorted in the same order as the Dockerfile
18+
### Not for general use so undocumented
19+
20+
aryn_user:
21+
groupadd --gid 1000 aryn
22+
useradd --uid 1000 --gid 1000 --home-dir /aryn --password=y --no-create-home aryn
23+
chown -R aryn:aryn /aryn
24+
25+
install_poetry:
26+
touch /var/lib/apt/.cache_var_lib_apt # make it possible to find the cache directory for buildx builds
27+
touch /var/cache/apt/.cache_var_cache_apt
28+
apt update
29+
DEBIAN_FRONTEND=noninteractive apt -y install --no-install-recommends python3-poetry gcc python3-dev
30+
2831
common_build:
32+
test "$(POETRY_CACHE_DIR)" = /tmp/poetry_cache # catch a bug where putting ARG too early in Dockerfile doesn't get the env var
33+
touch /tmp/poetry_cache/.poetry_cache_dir
2934
poetry install --no-root --only main
35+
poetry env info
36+
37+
docker_build_proto:
38+
test "$(POETRY_CACHE_DIR)" = /tmp/poetry_cache
39+
poetry install --no-root --only build
40+
make -f ../Makefile build_proto
3041

3142
server_build:
3243
poetry install --only-root
3344

34-
aryn_user:
35-
groupadd --gid 1000 aryn
36-
useradd --uid 1000 --gid 1000 --home-dir /aryn --password=y --no-create-home aryn
37-
chown -R aryn:aryn /aryn
45+
user_check:
46+
FILES=$$(find /aryn -print | wc -l); \
47+
ARYN_FILES=$$(find /aryn -user aryn -print | wc -l); \
48+
echo "Found $${ARYN_FILES}/$${FILES} owned by aryn"; \
49+
find /aryn ! -user aryn -print; \
50+
test $${FILES} -ge 1000 && \
51+
test $${ARYN_FILES} -eq $${FILES}

‎docker/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Repo name: arynai/opensearch-rps
12
FROM gradle:jdk17 AS assemble_plugin
23

34
WORKDIR /build

0 commit comments

Comments
 (0)