-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0828564
commit 25f7dbb
Showing
8 changed files
with
78 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,69 @@ | ||
# This is a multi-stage build file, which means a stage is used to build | ||
# the backend (dependencies), the frontend stack and a final production | ||
# stage re-using assets from the build stages. This keeps the final production | ||
# image minimal in size. | ||
|
||
# Stage 1 - Backend build environment | ||
# includes compilers and build tooling to create the environment | ||
FROM python:3.7-buster AS backend-build | ||
# Stage 1 - Compile needed python dependencies | ||
FROM python:3.7-buster AS build | ||
|
||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
libpq-dev \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
WORKDIR /app | ||
RUN mkdir /app/src | ||
|
||
# Ensure we use the latest version of pip | ||
RUN pip install pip setuptools -U | ||
COPY ./requirements /app/requirements | ||
RUN pip install pip setuptools -U | ||
RUN pip install -r requirements/production.txt | ||
|
||
|
||
# Stage 2 - Install frontend deps and build assets | ||
FROM node:13-buster AS frontend-build | ||
|
||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
git \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
# Stage 2 - build frontend | ||
FROM mhart/alpine-node:10 AS frontend-build | ||
|
||
WORKDIR /app | ||
|
||
# copy configuration/build files | ||
COPY ./build /app/build/ | ||
COPY ./*.json ./*.js ./.babelrc /app/ | ||
|
||
# install WITH dev tooling | ||
COPY ./*.json /app/ | ||
RUN npm ci | ||
|
||
# copy source code | ||
COPY ./src /app/src | ||
COPY ./gulpfile.js ./webpack.config.js ./.babelrc /app/ | ||
COPY ./build /app/build/ | ||
|
||
# build frontend | ||
COPY src/objecttypes/sass/ /app/src/objecttypes/sass/ | ||
COPY src/objecttypes/js/ /app/src/objecttypes/js/ | ||
RUN npm run build | ||
|
||
|
||
# Stage 3 - Build docker image suitable for production | ||
FROM python:3.7-buster | ||
# Stage 3 - Build docker image suitable for execution and deployment | ||
FROM python:3.7-buster AS production | ||
|
||
# Stage 3.1 - Set up the needed production dependencies | ||
# install all the dependencies for GeoDjango | ||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
procps \ | ||
vim \ | ||
postgresql-client \ | ||
# lxml deps | ||
# libxslt \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
COPY --from=build /usr/local/lib/python3.7 /usr/local/lib/python3.7 | ||
COPY --from=build /usr/local/bin/uwsgi /usr/local/bin/uwsgi | ||
|
||
# Stage 3.2 - Copy source code | ||
WORKDIR /app | ||
COPY ./bin/docker_start.sh /start.sh | ||
RUN mkdir /app/log | ||
RUN mkdir /app/media | ||
|
||
# copy backend build deps | ||
COPY --from=backend-build /usr/local/lib/python3.7 /usr/local/lib/python3.7 | ||
COPY --from=backend-build /usr/local/bin/uwsgi /usr/local/bin/uwsgi | ||
COPY --from=backend-build /app/src/ /app/src/ | ||
RUN mkdir /app/log /app/config | ||
|
||
# copy frontend build statics | ||
COPY --from=frontend-build /app/src/objecttypes/static /app/src/objecttypes/static | ||
|
||
# copy source code | ||
COPY --from=frontend-build /app/src/objecttypes/static/css /app/src/objecttypes/static/css | ||
COPY --from=frontend-build /app/src/objecttypes/static/js /app/src/objecttypes/static/js | ||
COPY ./src /app/src | ||
|
||
RUN useradd -M -u 1000 maykin | ||
RUN chown -R maykin /app | ||
|
||
# drop privileges | ||
USER maykin | ||
|
||
ARG COMMIT_HASH | ||
ARG RELEASE | ||
ENV GIT_SHA=${COMMIT_HASH} | ||
ENV RELEASE=${RELEASE} | ||
|
||
ENV DJANGO_SETTINGS_MODULE=objecttypes.conf.docker | ||
|
||
ARG SECRET_KEY=dummy | ||
|
||
# Run collectstatic, so the result is already included in the image | ||
RUN python src/manage.py collectstatic --noinput | ||
|
||
LABEL org.label-schema.vcs-ref=$COMMIT_HASH \ | ||
org.label-schema.vcs-url="https://github.com/maykinmedia/objecttypes-api" \ | ||
org.label-schema.version=$RELEASE \ | ||
org.label-schema.name="Objecttypes API" | ||
|
||
EXPOSE 8000 | ||
CMD ["/start.sh"] | ||
CMD ["/start.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
version: '3' | ||
|
||
services: | ||
db: | ||
image: postgres | ||
environment: | ||
- POSTGRES_USER=${DB_USER:-objecttypes} | ||
- POSTGRES_PASSWORD=${DB_PASSWORD:-objecttypes} | ||
|
||
web: | ||
build: . | ||
image: maykinmedia/objecttypes-api:latest | ||
environment: | ||
- DJANGO_SETTINGS_MODULE=objecttypes.conf.docker | ||
- SECRET_KEY=${SECRET_KEY:-fgv=c0hz&tl*8*3m3893@m+1pstrvidc9e^5@fpspmg%cy$15d} | ||
ports: | ||
- 8001:8000 | ||
depends_on: | ||
- db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters