1- # # Setting base OS layer
2- # # docker build -t container_tag --build-arg IMAGE_SOURCE=node IMAGE_TAG=12-buster .
1+ # #
2+ # # ---- Base OS layer ----
3+ # # docker build -t <container_tag> --build-arg IMAGE_SOURCE=node IMAGE_TAG=lts-alpine .
4+ # #
35ARG IMAGE_SOURCE=node
4- ARG IMAGE_TAG=12-buster
6+ ARG IMAGE_TAG=lts-alpine
57
6- # # Setting base image
7- FROM ${IMAGE_SOURCE}:${IMAGE_TAG}
8+ FROM ${IMAGE_SOURCE}:${IMAGE_TAG} AS base
89
9- # # Setting argument variables
10+ # # setup base stage
11+ RUN echo "**** Base stage ****"
12+
13+ # # setup image arguments
1014ARG PYTHON_VERSION=3.8.2
1115
12- # # User with uid/gid
1316ARG USER
1417ARG UID
1518ARG GID
@@ -23,14 +26,13 @@ ARG LC_ALL="en_US.UTF-8"
2326ARG BUILD_DATE="$(date -u +\" %Y-%m-%dT%H:%M:%SZ\" )"
2427ARG VCS_REF="$(git rev-parse --short HEAD)"
2528
26- # # Working directories
2729ARG APP_DIR="/usr/src/app"
2830ARG DATA_DIR="/usr/src/data"
31+ ARG TEMP_DIR="/tmp"
2932
30- # # Dependencies
31- ARG PACKAGES="git curl tini dos2unix locales"
33+ ARG INSTALL_PACKAGES="git curl tini dos2unix locales"
3234
33- # # General metadata
35+ # # setup image labels
3436LABEL "name" ="$NAME"
3537LABEL "version" ="$VERSION"
3638LABEL "description" ="$DESCRIPTION"
@@ -47,42 +49,35 @@ LABEL "com.github.vcs-ref"="$VCS_REF"
4749LABEL "com.github.name" ="$NAME"
4850LABEL "com.github.description" ="$DESCRIPTION"
4951
50- # # Setting environment variables
52+ # # setup environment variables
5153ENV PYTHON_VERSION $PYTHON_VERSION
5254
5355ENV APP_DIR=$APP_DIR \
54- DATA_DIR=$DATA_DIR
56+ DATA_DIR=$DATA_DIR \
57+ TEMP_DIR=$TEMP_DIR
5558
56- # System-level base config
5759ENV TZ=UTC \
5860 LANGUAGE=en_US:en \
5961 LC_ALL=$LC_ALL \
62+ LC_CTYPE=$LC_ALL \
6063 LANG=$LC_ALL \
6164 PYTHONIOENCODING=UTF-8 \
6265 PYTHONLEGACYWINDOWSSTDIO=UTF-8 \
6366 PYTHONUNBUFFERED=1 \
6467 PYTHONDONTWRITEBYTECODE=1 \
6568 DEBIAN_FRONTEND=noninteractive \
66- APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1
67-
68- ENV PIP_DISABLE_PIP_VERSION_CHECK=1
69- ENV PIP_NO_CACHE_DIR=1
70-
71- ENV USER=${USER:-'cukebot' } \
69+ APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1 \
70+ PIP_DISABLE_PIP_VERSION_CHECK=1 \
71+ PIP_NO_CACHE_DIR=1 \
72+ PIP_DEFAULT_TIMEOUT=100 \
73+ NPM_CONFIG_LOGLEVEL=error \
74+ IN_DOCKER=True
75+
76+ ENV USER=${USER:-'devbot' } \
7277 UID=${UID:-5000} \
7378 GID=${GID:-10000}
7479
75- ENV npm_config_loglevel=error
76- ENV IN_DOCKER=True
77-
78- # # Mounting volumes
79- VOLUME ["$APP_DIR" ]
80-
81- # # Creating work directory
82- WORKDIR $APP_DIR
83-
84- # Create a cukebot user. Some tools (Bundler, npm publish) don't work properly
85- # when run as root
80+ # # create user
8681RUN addgroup --gid "$GID" "$USER" || exit 0
8782RUN adduser \
8883 --disabled-password \
@@ -93,81 +88,131 @@ RUN adduser \
9388 "$USER" \
9489 || exit 0
9590
96- # # Installing dependencies
91+ # # mount volumes
92+ VOLUME ["$APP_DIR" , "$DATA_DIR" , "$TEMP_DIR" ]
93+
94+ # # create working directory
95+ WORKDIR $APP_DIR
96+
97+ # # install dependencies
9798RUN echo "**** Installing build packages ****"
99+ # # RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
98100RUN apt-get update \
99- && apt-get install --assume-yes --no-install-recommends $PACKAGES \
101+ && apt-get install --assume-yes --no-install-recommends $INSTALL_PACKAGES \
100102 && apt-get autoclean \
101103 && apt-get clean \
102104 && apt-get autoremove \
103105 && rm -rf /var/lib/apt/lists/*
104106
105- # # Installing python
107+ # # install python
106108RUN echo "**** Installing Python ****"
107109RUN cd /tmp && curl -O https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz && \
108110 tar -xvf Python-${PYTHON_VERSION}.tar.xz && \
109111 cd Python-${PYTHON_VERSION} && \
110112 ./configure --enable-optimizations && \
111113 make -j 4 && \
112- make altinstall
114+ make altinstall && \
115+ ln -s /usr/local/bin/python3.8 /usr/bin/python3.8
116+
117+ # # show versions
118+ RUN echo "npm version: $(npm --version)"
119+ RUN echo "node version: $(node --version | awk -F. '{print $1}')"
120+ RUN echo "python version: $(python3 --version)"
121+
122+ # # setup entrypoint
123+ ENTRYPOINT [ "/usr/bin/tini" , "--" ]
124+
125+ # # remove cache
126+ RUN echo "**** Cleaning cache ****"
127+
128+ RUN apt-get remove -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev libbz2-dev g++
129+ RUN rm -rf /var/cache/apt/* /tmp/* /var/tmp/*
130+
131+ # # copy project files
132+ COPY package.json .
133+ COPY ./docs/requirements.txt .
134+
135+ # #
136+ # # ---- Python Dependencies ----
137+ # #
138+ FROM base AS python-dependencies
139+
140+ # # setup python dependencies stage
141+ RUN echo "**** Installing python modules stage ****"
142+
143+ RUN /usr/bin/python3.8 -m pip install --upgrade setuptools && \
144+ /usr/bin/python3.8 -m pip install --upgrade pip && \
145+ /usr/bin/python3.8 -m pip install -r requirements.txt
113146
114- # # Copying source files
147+ # # remove cache
148+ RUN echo "**** Cleaning python cache ****"
149+
150+ RUN rm -rf ~/.cache/pip
151+
152+ # #
153+ # # ---- Node Dependencies ----
154+ # #
155+ FROM base AS node-dependencies
156+
157+ # # setup node modules stage
158+ RUN echo "**** Installing node modules stage ****"
159+
160+ # # update npm settings
161+ RUN npm set progress=false && npm config set depth 0
162+
163+ # # install only <production> node_modules
164+ # # RUN npm install --no-audit --only=prod
165+
166+ # # copy production node_modules aside
167+ # # RUN cp -R node_modules prod_node_modules
168+
169+ # # install node_modules, including 'devDependencies'
170+ RUN npm install --no-audit
171+
172+ # # remove cache
173+ RUN echo "**** Cleaning node cache ****"
174+
175+ RUN npm cache clean --force
176+
177+ # #
178+ # # ---- Testing ----
179+ # #
180+ FROM node-dependencies AS test
181+
182+ # # setup testing stage
183+ RUN echo "**** Testing stage ****"
184+
185+ # # copy source files
115186COPY . ./
116187
117- # # Installing python dependencies
118- # # RUN pip3.8 install --no-cache-dir -r ./docs/requirements.txt --quiet
119- RUN echo "**** Installing Python modules ****"
120- RUN pip3.8 install --upgrade pip --quiet
121-
122- RUN pip3.8 install mkdocs --no-cache-dir --quiet
123- RUN pip3.8 install mkdocs-material --no-cache-dir --quiet
124- RUN pip3.8 install pygments --no-cache-dir --quiet
125- RUN pip3.8 install markdown --no-cache-dir --quiet
126- RUN pip3.8 install markdown-include --no-cache-dir --quiet
127- RUN pip3.8 install markdown-checklist --no-cache-dir --quiet
128- RUN pip3.8 install fontawesome_markdown --no-cache-dir --quiet
129- RUN pip3.8 install mkdocs-redirects --no-cache-dir --quiet
130- RUN pip3.8 install mkdocs-material-extensions --no-cache-dir --quiet
131- RUN pip3.8 install mkdocs-techdocs-core --no-cache-dir --quiet
132- RUN pip3.8 install mkdocs-git-revision-date-localized-plugin --no-cache-dir --quiet
133- RUN pip3.8 install mkdocs-awesome-pages-plugin --no-cache-dir --quiet
134- RUN pip3.8 install mdx_truly_sane_lists --no-cache-dir --quiet
135- RUN pip3.8 install smarty --no-cache-dir --quiet
136- RUN pip3.8 install dumb-init --no-cache-dir --quiet
137- RUN pip3.8 install mkdocs-include-markdown-plugin --no-cache-dir --quiet
138- # RUN pip3.8 install mkdocs_pymdownx_material_extras --no-cache-dir --quiet
139- RUN pip3.8 install click-man --no-cache-dir --quiet
140- # # click-man --target path/to/man/pages mkdocs
141- RUN pip3.8 install cookiecutter --no-cache-dir --quiet
142-
143- # # Removing unnecessary dependencies
144- RUN echo "**** Cleaning Up cache ****"
145- RUN apt remove -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev libbz2-dev g++
146- RUN rm -rf /var/cache/apt/* /tmp/Python-${PYTHON_VERSION}
147-
148- # # Show versions
149- RUN echo "NPM version: $(npm --version)"
150- RUN echo "NODE version: $(node --version | awk -F. '{print \" $1\" }')"
151- RUN echo "PYTHON version: $(python3 --version)"
152-
153- # # Install node dependencies
154- RUN echo "**** Installing project packages ****"
155- RUN npm install
156-
157- # # Run format checking & linting
188+ # # run format checking & linting
158189RUN npm run test:all
159190
160- # # Setting volumes
161- VOLUME /tmp
191+ # #
192+ # # ---- Release ----
193+ # #
194+ FROM base AS release
195+
196+ # # setup release stage
197+ RUN echo "**** Release stage ****"
198+
199+ # # copy dependencies
200+ # COPY --from=node-dependencies ${APP_DIR}/prod_node_modules ./node_modules
201+ COPY --from=node-dependencies ${APP_DIR}/node_modules ./node_modules
202+ COPY --from=python-dependencies /usr/local/lib/python3.8/site-packages /usr/local/lib/python3.8/site-packages
203+
204+ # # setup environment path
205+ ENV PATH=/root/.local:$PATH
206+
207+ # # copy app sources
208+ COPY . ./
162209
163- # # Setting user
210+ # # setup user
164211USER $USER
165212
166- # # Expose port
213+ # # expose port
167214EXPOSE 8000
168215
169- # # Running package bundle
170- ENTRYPOINT [ "/usr/bin/tini" , "--" , "/bin/sh" , "-c" , "mkdocs" ]
171- # ENTRYPOINT ["mkdocs"]
172- CMD ["serve" , "--verbose" , "--dirtyreload" , "--dev-addr=0.0.0.0:8000" ]
173- # CMD ["mkdocs", "serve", "--verbose", "--dirtyreload", "-a", "0.0.0.0:8000"]
216+ # # define cmd
217+ CMD [ "/usr/bin/python3.8" , "-m" , "mkdocs" , "serve" , "--verbose" , "--dirtyreload" , "--dev-addr=0.0.0.0:8000" ]
218+ # # CMD [ "mkdocs", "serve", "--verbose", "--dirtyreload", "-a", "0.0.0.0:8000" ]
0 commit comments