forked from pycontw/pycon.tw
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request pycontw#1151 from pycontw/ben/dockerfile-enhanced
build(dockerfile): enhanced production dockerfile
- Loading branch information
Showing
2 changed files
with
49 additions
and
58 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
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,44 +1,41 @@ | ||
FROM python:3.6-slim-buster | ||
# [Node Stage to get node_modolues and node dependencies] | ||
FROM node:8.16.0-buster-slim as node_stage | ||
|
||
ENV PYTHONUNBUFFERED 1 | ||
WORKDIR /app | ||
COPY ./yarn.lock yarn.lock | ||
COPY ./package.json package.json | ||
|
||
ENV BASE_DIR /usr/local | ||
RUN apt-get update | ||
RUN apt-get install python-pip -y | ||
|
||
ENV NVM_INSTALLER_URL https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | ||
ENV NVM_DIR $BASE_DIR/nvm | ||
ENV YARN_VERSION 1.15.2-1 | ||
ENV NODE_VERSION 8.16.0 | ||
RUN npm install -g yarn | ||
RUN yarn install --dev --frozen-lockfile | ||
|
||
# [Python Stage for Django web server] | ||
FROM python:3.6-slim-buster as python_stage | ||
|
||
WORKDIR /app | ||
|
||
# make nodejs and yarn accessible and executable globally | ||
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH | ||
COPY --from=node_stage /node_modules ./node_modules | ||
COPY --from=node_stage /usr/local/bin/node /usr/local/bin/node | ||
|
||
ENV PYTHONUNBUFFERED 1 | ||
ENV BASE_DIR /usr/local | ||
|
||
# Infrastructure tools | ||
# gettext is used for django to compile .po to .mo files. | ||
RUN apt-get update | ||
RUN apt-get install apt-utils -y | ||
RUN apt-get update | ||
RUN apt-get install gettext python3-pip -y | ||
|
||
# Install Node and Yarn from upstream | ||
RUN curl -o- $NVM_INSTALLER_URL | bash \ | ||
&& . $NVM_DIR/nvm.sh \ | ||
&& nvm install $NODE_VERSION \ | ||
&& nvm alias default $NODE_VERSION \ | ||
&& nvm use default \ | ||
&& nvm --version \ | ||
&& npm install -g yarn \ | ||
&& yarn --version | ||
|
||
RUN apt-get install -y \ | ||
libpq-dev \ | ||
gcc \ | ||
zlib1g-dev \ | ||
libjpeg62-turbo-dev \ | ||
gettext | ||
|
||
# Only copy and install requirements to improve caching between builds | ||
# Install Python dependencies | ||
COPY ./requirements ./requirements | ||
RUN pip3 install -r ./requirements/dev.txt | ||
|
||
# # Install Javascript dependencies | ||
COPY ./package.json ./package.json | ||
COPY ./yarn.lock ./yarn.lock | ||
RUN yarn install --dev --frozen-lockfile | ||
|
||
# for entry point | ||
COPY ./docker-entrypoint.sh /docker-entrypoint.sh | ||
RUN chmod +x /docker-entrypoint.sh |