1
- FROM node:16.16-alpine3.16 as static_files
1
+ FROM node:16-bullseye-slim as static_files
2
2
3
3
WORKDIR /code
4
4
ENV PATH /code/node_modules/.bin:$PATH
@@ -24,7 +24,6 @@ RUN set -ex \
24
24
mime-support \
25
25
postgresql-client \
26
26
vim \
27
- gdal-bin \
28
27
" \
29
28
&& seq 1 8 | xargs -I{} mkdir -p /usr/share/man/man{} \
30
29
&& apt-get update && apt-get install -y --no-install-recommends $RUN_DEPS \
@@ -48,10 +47,11 @@ RUN set -ex \
48
47
&& apt-get update && apt-get install -y --no-install-recommends $BUILD_DEPS \
49
48
&& pip install -U -q pip-tools \
50
49
&& pip-sync requirements/base/base.txt requirements/deploy/deploy.txt \
51
- \
52
50
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $BUILD_DEPS \
53
51
&& rm -rf /var/lib/apt/lists/*
54
52
53
+ FROM base AS deploy
54
+
55
55
# Copy your application code to the container (make sure you create a .dockerignore file if any large files or directories should be excluded)
56
56
RUN mkdir /code/
57
57
WORKDIR /code/
@@ -67,7 +67,6 @@ EXPOSE 8000
67
67
ENV DJANGO_SETTINGS_MODULE=traffic_stops.settings.deploy
68
68
69
69
# Call collectstatic (customize the following line with the minimal environment variables needed for manage.py to run):
70
- RUN touch /code/.env
71
70
RUN DATABASE_URL='' ENVIRONMENT='' DJANGO_SECRET_KEY='dummy' DOMAIN='' python manage.py collectstatic --noinput
72
71
73
72
# Tell uWSGI where to find your wsgi file (change this):
@@ -82,6 +81,8 @@ ENV UWSGI_WORKERS=2 UWSGI_THREADS=4
82
81
# uWSGI static file serving configuration (customize or comment out if not needed):
83
82
ENV UWSGI_STATIC_MAP="/static/=/code/static/" UWSGI_STATIC_EXPIRES_URI="/static/.*\. [a-f0-9]{12,}\. (css|js|png|jpg|jpeg|gif|ico|woff|ttf|otf|svg|scss|map|txt) 315360000"
84
83
84
+ RUN touch /code/.env
85
+
85
86
# Change to a non-root user
86
87
USER ${APP_USER}:${APP_USER}
87
88
@@ -90,3 +91,86 @@ ENTRYPOINT ["/code/docker-entrypoint.sh"]
90
91
91
92
# Start uWSGI
92
93
CMD ["newrelic-admin" , "run-program" , "uwsgi" , "--single-interpreter" , "--enable-threads" , "--show-config" ]
94
+
95
+ FROM python:3.8-slim-bullseye AS dev
96
+
97
+ ARG USERNAME=appuser
98
+ ARG USER_UID=1000
99
+ ARG USER_GID=$USER_UID
100
+
101
+ # Create non-root user
102
+ RUN groupadd --gid $USER_GID $USERNAME \
103
+ && useradd --uid $USER_UID --gid $USER_GID --create-home --shell /bin/bash $USERNAME
104
+
105
+ # Install packages for Dev Container development
106
+ # build-essential -- for gcc to compile non-wheel packages with C dependencies
107
+ # docker-ce-cli -- docker CLI
108
+ # docker-compose-plugin -- docker compose CLI
109
+ # git-core -- to pull, commit, and push from dev container
110
+ # gnupg2 -- GNU privacy guard - a free PGP replacement
111
+ # libpq-dev -- header files for PostgreSQL
112
+ # openssh-client -- for git over SSH
113
+ # sudo -- to run commands as superuser
114
+ # vim -- enhanced vi editor for commits
115
+ ENV KUBE_CLIENT_VERSION="v1.22.15"
116
+ ENV HELM_VERSION="3.8.2"
117
+ RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib/apt \
118
+ --mount=type=cache,mode=0755,target=/root/.cache/pip \
119
+ set -ex \
120
+ && RUN_DEPS=" \
121
+ build-essential \
122
+ docker-ce-cli \
123
+ docker-compose-plugin \
124
+ git-core \
125
+ gnupg2 \
126
+ libpcre3 \
127
+ libpq-dev \
128
+ mime-support \
129
+ nodejs \
130
+ openssh-client \
131
+ postgresql-client-12 \
132
+ sudo \
133
+ vim \
134
+ " \
135
+ && apt-get update && apt-get -y install curl wget gnupg2 lsb-release \
136
+ # starship.rs prompt
137
+ && curl -sS https://starship.rs/install.sh | sh -s -- -y \
138
+ # kubectl
139
+ && curl --silent -L https://dl.k8s.io/release/$KUBE_CLIENT_VERSION/bin/linux/$(dpkg --print-architecture)/kubectl -o /usr/local/bin/kubectl \
140
+ && chmod +x /usr/local/bin/kubectl \
141
+ # helm
142
+ && curl --silent -L https://get.helm.sh/helm-v$HELM_VERSION-linux-$(dpkg --print-architecture).tar.gz --output - | tar -xzC /tmp \
143
+ && mv /tmp/linux-$(dpkg --print-architecture)/helm /usr/local/bin/helm \
144
+ && chmod +x /usr/local/bin/helm \
145
+ # docker
146
+ && curl https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor | tee /etc/apt/trusted.gpg.d/docker.gpg >/dev/null \
147
+ && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/trusted.gpg.d/docker.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null \
148
+ # nodejs
149
+ && sh -c 'echo "deb https://deb.nodesource.com/node_16.x $(lsb_release -cs) main" > /etc/apt/sources.list.d/nodesource.list' \
150
+ && wget --quiet -O- https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - \
151
+ # PostgreSQL
152
+ && sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' \
153
+ && curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg >/dev/null \
154
+ # dev packages
155
+ && apt-get update \
156
+ && apt-get install -y --no-install-recommends $RUN_DEPS \
157
+ # sudo
158
+ && echo $USERNAME ALL=\( root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
159
+ && chmod 0440 /etc/sudoers.d/$USERNAME
160
+
161
+ # Install Docker Buildx component for Docker v23.0.0+
162
+ COPY --from=docker/buildx-bin:latest /buildx /usr/libexec/docker/cli-plugins/docker-buildx
163
+
164
+ COPY --chown=$USER_UID:$USER_GID . /code/
165
+
166
+ USER $USERNAME
167
+ RUN set -ex \
168
+ && touch /code/.env \
169
+ && echo 'eval "$(starship init bash)"' >> ~/.bashrc
170
+
171
+ ENV DJANGO_SETTINGS_MODULE=traffic_stops.settings.dev
172
+ ENV PATH=/code/venv/bin:$PATH
173
+
174
+ WORKDIR /code
175
+
176
+ CMD ["python" , "/code/manage.py" , "runserver" , "0.0.0.0:8000" ]
0 commit comments