2023-01-06 15:43:48 +00:00
|
|
|
FROM alpine:3.17 AS builder
|
2019-12-04 04:50:46 +00:00
|
|
|
|
2019-12-15 15:33:09 +00:00
|
|
|
ARG BUILD_DEPENDENCIES="build-base \
|
|
|
|
libffi-dev \
|
|
|
|
libxml2-dev \
|
|
|
|
mariadb-connector-c-dev \
|
|
|
|
openldap-dev \
|
|
|
|
python3-dev \
|
|
|
|
xmlsec-dev \
|
2023-02-18 00:00:09 +00:00
|
|
|
npm \
|
2021-03-27 18:33:11 +00:00
|
|
|
yarn \
|
|
|
|
cargo"
|
2019-12-04 04:50:46 +00:00
|
|
|
|
2019-12-15 15:33:09 +00:00
|
|
|
ENV LC_ALL=en_US.UTF-8 \
|
|
|
|
LANG=en_US.UTF-8 \
|
|
|
|
LANGUAGE=en_US.UTF-8 \
|
|
|
|
FLASK_APP=/build/powerdnsadmin/__init__.py
|
|
|
|
|
|
|
|
# Get dependencies
|
2020-10-10 19:47:58 +00:00
|
|
|
# py3-pip should not belong to BUILD_DEPENDENCIES. Otherwise, when we remove
|
|
|
|
# them with "apk del" at the end of build stage, the python requests module
|
|
|
|
# will be removed as well - (Tested with alpine:3.12 and python 3.8.5).
|
|
|
|
RUN apk add --no-cache ${BUILD_DEPENDENCIES} && \
|
|
|
|
apk add --no-cache py3-pip
|
2019-12-15 15:33:09 +00:00
|
|
|
|
|
|
|
WORKDIR /build
|
2019-12-04 04:50:46 +00:00
|
|
|
|
|
|
|
# We copy just the requirements.txt first to leverage Docker cache
|
2019-12-15 15:33:09 +00:00
|
|
|
COPY ./requirements.txt /build/requirements.txt
|
2019-12-04 04:50:46 +00:00
|
|
|
|
2019-12-15 15:33:09 +00:00
|
|
|
# Get application dependencies
|
2020-03-12 23:27:19 +00:00
|
|
|
RUN pip install --upgrade pip && \
|
2023-01-06 15:43:48 +00:00
|
|
|
pip install --use-pep517 -r requirements.txt
|
2019-12-15 15:33:09 +00:00
|
|
|
|
|
|
|
# Add sources
|
|
|
|
COPY . /build
|
|
|
|
|
|
|
|
# Prepare assets
|
|
|
|
RUN yarn install --pure-lockfile --production && \
|
|
|
|
yarn cache clean && \
|
2019-12-20 16:22:51 +00:00
|
|
|
sed -i -r -e "s|'cssmin',\s?'cssrewrite'|'cssmin'|g" /build/powerdnsadmin/assets.py && \
|
2019-12-15 15:33:09 +00:00
|
|
|
flask assets build
|
|
|
|
|
|
|
|
RUN mv /build/powerdnsadmin/static /tmp/static && \
|
|
|
|
mkdir /build/powerdnsadmin/static && \
|
|
|
|
cp -r /tmp/static/generated /build/powerdnsadmin/static && \
|
2020-04-17 14:01:29 +00:00
|
|
|
cp -r /tmp/static/assets /build/powerdnsadmin/static && \
|
|
|
|
cp -r /tmp/static/img /build/powerdnsadmin/static && \
|
2023-02-21 12:37:42 +00:00
|
|
|
find /tmp/static/node_modules -name 'webfonts' -exec cp -r {} /build/powerdnsadmin/static \; && \
|
2019-12-15 15:33:09 +00:00
|
|
|
find /tmp/static/node_modules -name 'fonts' -exec cp -r {} /build/powerdnsadmin/static \; && \
|
|
|
|
find /tmp/static/node_modules/icheck/skins/square -name '*.png' -exec cp {} /build/powerdnsadmin/static/generated \;
|
|
|
|
|
|
|
|
RUN { \
|
|
|
|
echo "from flask_assets import Environment"; \
|
|
|
|
echo "assets = Environment()"; \
|
|
|
|
echo "assets.register('js_login', 'generated/login.js')"; \
|
|
|
|
echo "assets.register('js_validation', 'generated/validation.js')"; \
|
|
|
|
echo "assets.register('css_login', 'generated/login.css')"; \
|
|
|
|
echo "assets.register('js_main', 'generated/main.js')"; \
|
|
|
|
echo "assets.register('css_main', 'generated/main.css')"; \
|
|
|
|
} > /build/powerdnsadmin/assets.py
|
2019-12-04 04:50:46 +00:00
|
|
|
|
2019-12-15 15:33:09 +00:00
|
|
|
# Move application
|
|
|
|
RUN mkdir -p /app && \
|
|
|
|
cp -r /build/migrations/ /build/powerdnsadmin/ /build/run.py /app && \
|
|
|
|
mkdir -p /app/configs && \
|
|
|
|
cp -r /build/configs/docker_config.py /app/configs
|
2019-12-04 04:50:46 +00:00
|
|
|
|
2019-12-15 15:33:09 +00:00
|
|
|
# Build image
|
2023-01-06 15:43:48 +00:00
|
|
|
FROM alpine:3.17
|
2019-12-15 15:33:09 +00:00
|
|
|
|
2020-09-19 17:58:51 +00:00
|
|
|
ENV FLASK_APP=/app/powerdnsadmin/__init__.py \
|
|
|
|
USER=pda
|
2019-12-15 15:33:09 +00:00
|
|
|
|
2022-12-23 11:18:00 +00:00
|
|
|
RUN apk add --no-cache mariadb-connector-c postgresql-client py3-gunicorn py3-pyldap py3-flask py3-psycopg2 xmlsec tzdata libcap && \
|
2020-09-19 17:58:51 +00:00
|
|
|
addgroup -S ${USER} && \
|
|
|
|
adduser -S -D -G ${USER} ${USER} && \
|
2020-04-20 22:23:57 +00:00
|
|
|
mkdir /data && \
|
2020-09-19 17:58:51 +00:00
|
|
|
chown ${USER}:${USER} /data && \
|
|
|
|
setcap cap_net_bind_service=+ep $(readlink -f /usr/bin/python3) && \
|
|
|
|
apk del libcap
|
2019-12-15 15:33:09 +00:00
|
|
|
|
|
|
|
COPY --from=builder /usr/bin/flask /usr/bin/
|
2023-01-06 15:43:48 +00:00
|
|
|
COPY --from=builder /usr/lib/python3.10/site-packages /usr/lib/python3.10/site-packages/
|
2020-09-19 17:58:51 +00:00
|
|
|
COPY --from=builder --chown=root:${USER} /app /app/
|
2019-12-15 15:33:09 +00:00
|
|
|
COPY ./docker/entrypoint.sh /usr/bin/
|
|
|
|
|
|
|
|
WORKDIR /app
|
2020-12-07 18:46:08 +00:00
|
|
|
RUN chown ${USER}:${USER} ./configs /app && \
|
2020-09-19 17:58:51 +00:00
|
|
|
cat ./powerdnsadmin/default_config.py ./configs/docker_config.py > ./powerdnsadmin/docker_config.py
|
2019-12-04 04:50:46 +00:00
|
|
|
|
|
|
|
EXPOSE 80/tcp
|
2020-09-19 17:58:51 +00:00
|
|
|
USER ${USER}
|
2019-12-15 15:33:09 +00:00
|
|
|
HEALTHCHECK CMD ["wget","--output-document=-","--quiet","--tries=1","http://127.0.0.1/"]
|
2019-12-04 04:50:46 +00:00
|
|
|
ENTRYPOINT ["entrypoint.sh"]
|
2020-09-19 17:58:51 +00:00
|
|
|
CMD ["gunicorn","powerdnsadmin:create_app()"]
|