Skip to content

Commit 554182e

Browse files
feat: run the docker container as dev (#8606)
* feat: run the docker container as dev * fix: $@ -> $* Old bug, but might as well fix it now --------- Co-authored-by: Jennifer Richards <[email protected]>
1 parent 232a861 commit 554182e

File tree

3 files changed

+72
-5
lines changed

3 files changed

+72
-5
lines changed

dev/celery/docker-init.sh

+9-4
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,16 @@ if [[ -n "${CELERY_GID}" ]]; then
4949
fi
5050

5151
run_as_celery_uid () {
52-
SU_OPTS=()
53-
if [[ -n "${CELERY_GROUP}" ]]; then
54-
SU_OPTS+=("-g" "${CELERY_GROUP}")
52+
IAM=$(whoami)
53+
if [ "${IAM}" = "${CELERY_USERNAME:-root}" ]; then
54+
SU_OPTS=()
55+
if [[ -n "${CELERY_GROUP}" ]]; then
56+
SU_OPTS+=("-g" "${CELERY_GROUP}")
57+
fi
58+
su "${SU_OPTS[@]}" "${CELERY_USERNAME:-root}" -s /bin/sh -c "$*"
59+
else
60+
/bin/sh -c "$*"
5561
fi
56-
su "${SU_OPTS[@]}" "${CELERY_USERNAME:-root}" -s /bin/sh -c "$@"
5762
}
5863

5964
log_term_timing_msgs () {

docker-compose.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ services:
6767
restart: unless-stopped
6868

6969
celery:
70-
image: ghcr.io/ietf-tools/datatracker-celery:latest
70+
build:
71+
context: .
72+
dockerfile: docker/celery.Dockerfile
7173
init: true
7274
environment:
7375
CELERY_APP: ietf

docker/celery.Dockerfile

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
FROM ghcr.io/ietf-tools/datatracker-celery:latest
2+
LABEL maintainer="IETF Tools Team <[email protected]>"
3+
4+
ENV DEBIAN_FRONTEND=noninteractive
5+
6+
# Install needed packages and setup non-root user.
7+
ARG USERNAME=dev
8+
ARG USER_UID=1000
9+
ARG USER_GID=$USER_UID
10+
COPY docker/scripts/app-setup-debian.sh /tmp/library-scripts/docker-setup-debian.sh
11+
RUN sed -i 's/\r$//' /tmp/library-scripts/docker-setup-debian.sh && chmod +x /tmp/library-scripts/docker-setup-debian.sh
12+
13+
# Add Postgresql Apt Repository to get 14
14+
RUN echo "deb http://apt.postgresql.org/pub/repos/apt $(. /etc/os-release && echo "$VERSION_CODENAME")-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list
15+
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
16+
17+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
18+
&& apt-get install -y --no-install-recommends postgresql-client-14 pgloader \
19+
# Remove imagemagick due to https://security-tracker.debian.org/tracker/CVE-2019-10131
20+
&& apt-get purge -y imagemagick imagemagick-6-common \
21+
# Install common packages, non-root user
22+
# Syntax: ./docker-setup-debian.sh [install zsh flag] [username] [user UID] [user GID] [upgrade packages flag] [install Oh My Zsh! flag] [Add non-free packages]
23+
&& bash /tmp/library-scripts/docker-setup-debian.sh "true" "${USERNAME}" "${USER_UID}" "${USER_GID}" "false" "true" "true"
24+
25+
# Setup default python tools in a venv via pipx to avoid conflicts
26+
ENV PIPX_HOME=/usr/local/py-utils \
27+
PIPX_BIN_DIR=/usr/local/py-utils/bin
28+
ENV PATH=${PATH}:${PIPX_BIN_DIR}
29+
COPY docker/scripts/app-setup-python.sh /tmp/library-scripts/docker-setup-python.sh
30+
RUN sed -i 's/\r$//' /tmp/library-scripts/docker-setup-python.sh && chmod +x /tmp/library-scripts/docker-setup-python.sh
31+
RUN bash /tmp/library-scripts/docker-setup-python.sh "none" "/usr/local" "${PIPX_HOME}" "${USERNAME}"
32+
33+
# Remove library scripts for final image
34+
RUN rm -rf /tmp/library-scripts
35+
36+
# Copy the startup file
37+
COPY dev/celery/docker-init.sh /docker-init.sh
38+
RUN sed -i 's/\r$//' /docker-init.sh && \
39+
chmod +x /docker-init.sh
40+
41+
ENTRYPOINT [ "/docker-init.sh" ]
42+
43+
# Fix user UID / GID to match host
44+
RUN groupmod --gid $USER_GID $USERNAME \
45+
&& usermod --uid $USER_UID --gid $USER_GID $USERNAME \
46+
&& chown -R $USER_UID:$USER_GID /home/$USERNAME \
47+
|| exit 0
48+
49+
# Switch to local dev user
50+
USER dev:dev
51+
52+
# Install current datatracker python dependencies
53+
COPY requirements.txt /tmp/pip-tmp/
54+
RUN pip3 --disable-pip-version-check --no-cache-dir install --user --no-warn-script-location -r /tmp/pip-tmp/requirements.txt
55+
RUN pip3 --disable-pip-version-check --no-cache-dir install --user --no-warn-script-location watchdog[watchmedo]
56+
57+
RUN sudo rm -rf /tmp/pip-tmp
58+
59+
VOLUME [ "/assets" ]
60+

0 commit comments

Comments
 (0)