-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
68 lines (56 loc) · 2.94 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
FROM alpine AS build-base
RUN apk --no-cache upgrade
RUN apk --no-cache add alpine-sdk python3 python3-dev libxml2-dev libxslt-dev gzip
RUN python3 -m venv /app/venv && \
/app/venv/bin/pip install --upgrade pip && \
/app/venv/bin/pip install --upgrade setuptools wheel
FROM build-base AS build-static
RUN /app/venv/bin/pip install css-html-js-minify
COPY ./static/ /app/static/
RUN /app/venv/bin/css-html-js-minify --comments --overwrite /app/static
FROM build-base AS flake8
RUN /app/venv/bin/pip install --upgrade flake8
COPY ./.flake8 /usr/src/obra-hacks/.flake8
COPY ./python/ /usr/src/obra-hacks/python/
WORKDIR /usr/src/obra-hacks/
RUN /app/venv/bin/flake8 /usr/src/obra-hacks/python/
FROM build-base AS build-python
ARG SQLITE_VERSION="3.36.0"
ARG APSW_VERSION="${SQLITE_VERSION}-r1"
ARG CFLAGS="-DSQLITE_USE_ALLOCA=1 -DSQLITE_DQS=0 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS=1 -DSQLITE_OMIT_AUTOINIT=1 -Wno-sign-compare -Wno-unused-function -Wno-unused-variable -Wno-maybe-uninitialized -Wno-deprecated-declarations -Wno-pointer-sign"
ADD https://github.com/rogerbinns/apsw/archive/${APSW_VERSION}.tar.gz /usr/src/
RUN tar -zxvf /usr/src/${APSW_VERSION}.tar.gz -C /usr/src/
WORKDIR /usr/src/apsw-${APSW_VERSION}
RUN /app/venv/bin/python setup.py fetch --all --version=${SQLITE_VERSION}
RUN /app/venv/bin/python setup.py build --enable-all-extensions install
RUN /app/venv/bin/python setup.py test
COPY ./python/requirements.txt /usr/src/obra-hacks/python/requirements.txt
RUN /app/venv/bin/pip install -r /usr/src/obra-hacks/python/requirements.txt
COPY ./python/ /usr/src/obra-hacks/python/
RUN /app/venv/bin/pip install --no-deps --use-feature=in-tree-build /usr/src/obra-hacks/python/ && \
cp -v /usr/src/obra-hacks/python/app/* /app/
RUN (CACHE_TYPE=SimpleCache timeout 5 /app/venv/bin/python /app/obra-hacks.py & sleep 2 && curl -vsf --compressed http://127.0.0.1:5000/api/v1/events/years/)
COPY docker-entrypoint.sh /app/
RUN mkdir -p /data /tmp/spool /tmp/tls
FROM build-base AS build-shasum
COPY --from=build-static /app/ /app/
COPY ./conf/ /app/conf/
RUN export JS_CHECKSUM=$(sha256sum /app/static/js/index.js | awk '{print $1}') && \
sed -i "s/index.js/index.js?${JS_CHECKSUM}/" /app/conf/uwsgi.yaml /app/static/index.html && \
gzip -kvr /app/static
FROM scratch AS build-collect
COPY --chown=405:100 --from=build-shasum /app/ /app/
COPY --chown=405:100 --from=build-python /app/ /app/
COPY --chown=405:100 --from=build-python /data/ /data/
COPY --chown=405:100 --from=build-python /tmp/ /tmp/
FROM alpine
RUN apk --no-cache upgrade && apk --no-cache add libxml2 libxslt python3 bash libstdc++ openssl uwsgi-http uwsgi-python3 uwsgi-router_static
COPY --from=build-collect / /
LABEL maintainer="Brad Davidson <brad@oatmail.org>"
VOLUME ["/tmp"]
VOLUME ["/data"]
USER guest
ENV UWSGI_CERT=/tmp/tls/server.pem UWSGI_KEY=/tmp/tls/server.key CACHE_TYPE=uwsgi HOME=/data
EXPOSE 8080 8443
ENTRYPOINT ["/app/docker-entrypoint.sh"]
CMD ["uwsgi", "--yaml", "/app/conf/uwsgi.yaml"]