Skip to content

Commit f9b5533

Browse files
author
lijianguo
committed
chore(dockerfile): use drycc/base image
1 parent 365a542 commit f9b5533

7 files changed

Lines changed: 91 additions & 63 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ test-integration:
6666

6767
upload-coverage:
6868
$(eval CI_ENV := $(shell curl -s https://codecov.io/env | bash))
69-
docker run ${CI_ENV} -v ${CURDIR}:/test -w /test/rootfs ${IMAGE}.test codecov --required
69+
docker run ${CI_ENV} -v ${CURDIR}:/test -w /test/rootfs ${IMAGE}.test /test/rootfs/bin/upload-coverage
7070

7171
.PHONY: check-kubectl check-docker build docker-build docker-build-test deploy clean commit-hook full-clean test test-style test-unit test-functional test-integration upload-coverage

rootfs/Dockerfile

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,58 @@
1-
FROM node:16-alpine3.14 as build-app
1+
FROM docker.io/drycc/base:bullseye as build-app
22

33
ADD web /app
44
WORKDIR /app
55

6-
RUN yarn install \
6+
ENV NODE_VERSION="16.14.0"
7+
8+
RUN install-stack node $NODE_VERSION && . init-stack \
9+
&& npm install --global yarn \
10+
&& yarn install \
711
&& yarn build
812

9-
FROM docker.io/library/python:3.9-alpine
13+
FROM docker.io/drycc/base:bullseye
14+
15+
RUN adduser --system \
16+
--shell /bin/bash \
17+
--disabled-password \
18+
--home /app \
19+
--group \
20+
drycc
1021

22+
ENV PYTHON_VERSION="3.10.2"
1123
COPY requirements.txt /app/requirements.txt
1224

13-
RUN apk add --update --virtual .build-deps \
14-
postgresql-dev \
15-
gcc \
16-
libffi-dev \
17-
musl-dev \
18-
openldap-dev \
19-
openssl-dev \
20-
cargo \
21-
rust \
22-
&& ln /usr/lib/libldap.so /usr/lib/libldap_r.so \
25+
RUN buildDeps='gcc rustc cargo libffi-dev musl-dev libldap2-dev libsasl2-dev'; \
26+
install-packages $buildDeps \
27+
&& install-stack python $PYTHON_VERSION && . init-stack \
2328
&& python3 -m venv /app/.venv \
2429
&& source /app/.venv/bin/activate \
2530
&& pip3 install --disable-pip-version-check --no-cache-dir -r /app/requirements.txt \
26-
&& find /app/.venv /usr/local -type f -executable ! -path '*/cryptography*' -exec scanelf --needed --nobanner --format '%n#p' '{}' ';' \
27-
| tr ',' '\n' \
28-
| sort -u \
29-
| awk 'system("[[ -e /app/.venv/lib/" $1 " || -e /usr/local/lib/" $1 " ]]") == 0 { next } { print "so:" $1 }' \
30-
| xargs -rt apk add --no-cache --virtual .python-rundeps \
31-
&& apk add --update --virtual .passport-rundeps \
32-
ca-certificates \
33-
su-exec \
34-
bash \
35-
shadow \
36-
&& apk del .build-deps
31+
# cleanup
32+
&& scanelp /app/.venv/lib > runtime.txt \
33+
&& apt-get purge -y --auto-remove $buildDeps \
34+
&& install-packages $(< runtime.txt) \
35+
&& apt-get autoremove -y \
36+
&& apt-get clean -y \
37+
&& rm -rf \
38+
/usr/share/doc \
39+
/usr/share/man \
40+
/usr/share/info \
41+
/usr/share/locale \
42+
/var/lib/apt/lists/* \
43+
/var/log/* \
44+
/var/cache/debconf/* \
45+
/etc/systemd \
46+
/lib/lsb \
47+
/lib/udev \
48+
/usr/lib/`echo $(uname -m)`-linux-gnu/gconv/IBM* \
49+
/usr/lib/`echo $(uname -m)`-linux-gnu/gconv/EBC* \
50+
&& mkdir -p /usr/share/man/man{1..8}
3751

3852
COPY . /app
3953
COPY --from=build-app /app/dist /app/web/dist
4054

41-
ENV PATH /app/.venv/bin:/app/bin:$PATH
55+
USER drycc
4256
WORKDIR /app
43-
CMD ["/app/bin/boot"]
57+
CMD ["PATH=/app/.venv/bin:\$PATH", "/app/bin/boot"]
4458
EXPOSE 8000

rootfs/Dockerfile.test

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,48 @@
1-
FROM docker.io/library/python:3.9-alpine
1+
FROM docker.io/drycc/base:bullseye
22

33
COPY requirements.txt /app/requirements.txt
44
COPY dev_requirements.txt /app/dev_requirements.txt
55

6-
ENV PGDATA /var/lib/postgresql/12
6+
ENV PGDATA="/var/lib/postgresql/14/data" \
7+
PYTHON_VERSION="3.10.2" \
8+
POSTGRES_VERSION="14.2" \
9+
GOSU_VERSION="1.14"
710

8-
ENV PATH="/app/.venv/bin:${PATH}"
9-
10-
RUN echo https://dl-cdn.alpinelinux.org/alpine/edge/testing >>/etc/apk/repositories \
11-
&& apk add --update --virtual .build-deps \
12-
postgresql-dev \
13-
gcc \
14-
libffi-dev \
15-
musl-dev \
16-
openldap-dev \
17-
openssl-dev \
18-
cargo \
19-
rust \
20-
&& ln /usr/lib/libldap.so /usr/lib/libldap_r.so \
11+
RUN buildDeps='gcc rustc cargo libffi-dev musl-dev libldap2-dev libsasl2-dev'; \
12+
install-packages ldap-utils mercurial ca-certificates openssl git $buildDeps \
13+
&& install-stack python $PYTHON_VERSION \
14+
&& install-stack postgresql $POSTGRES_VERSION \
15+
&& install-stack gosu $GOSU_VERSION && . init-stack \
2116
&& python3 -m venv /app/.venv \
2217
&& source /app/.venv/bin/activate \
2318
&& pip3 install --disable-pip-version-check --no-cache-dir -r /app/requirements.txt \
2419
&& pip3 install --disable-pip-version-check --no-cache-dir -r /app/dev_requirements.txt \
25-
&& find /app/.venv /usr/local -type f -executable ! -path '*/cryptography*' -exec scanelf --needed --nobanner --format '%n#p' '{}' ';' \
26-
| tr ',' '\n' \
27-
| sort -u \
28-
| awk 'system("[[ -e /app/.venv/lib/" $1 " || -e /usr/local/lib/" $1 " ]]") == 0 { next } { print "so:" $1 }' \
29-
| xargs -rt apk add --no-cache --virtual .python-rundeps \
30-
&& apk add --update --virtual .passport-rundeps \
31-
git \
32-
mercurial \
33-
ca-certificates \
34-
su-exec \
35-
bash \
36-
shadow \
37-
postgresql \
38-
openssl \
20+
# cleanup
21+
&& scanelp /app/.venv/lib > runtime.txt \
22+
&& apt-get purge -y --auto-remove $buildDeps \
23+
&& install-packages $(< runtime.txt) \
24+
&& apt-get autoremove -y \
25+
&& apt-get clean -y \
26+
&& rm -rf \
27+
/usr/share/doc \
28+
/usr/share/man \
29+
/usr/share/info \
30+
/usr/share/locale \
31+
/var/lib/apt/lists/* \
32+
/var/log/* \
33+
/var/cache/debconf/* \
34+
/etc/systemd \
35+
/lib/lsb \
36+
/lib/udev \
37+
/usr/lib/`echo $(uname -m)`-linux-gnu/gconv/IBM* \
38+
/usr/lib/`echo $(uname -m)`-linux-gnu/gconv/EBC* \
39+
&& mkdir -p /usr/share/man/man{1..8} \
3940
&& mkdir -p /run/postgresql $PGDATA \
41+
&& groupadd postgres && useradd -g postgres postgres \
4042
&& chown -R postgres:postgres /run/postgresql $PGDATA \
41-
&& apk del .build-deps \
42-
&& su-exec postgres initdb -D $PGDATA
43+
&& gosu postgres initdb -D $PGDATA
4344

4445
COPY . /app
45-
46-
ENV PATH /app/.venv/bin:/app/bin:$PATH
4746
WORKDIR /app
4847
CMD ["/app/bin/boot"]
4948
EXPOSE 8000

rootfs/bin/boot

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
# fail hard and fast even on pipelines
77
set -eo pipefail
8-
8+
# shellcheck disable=SC1091
9+
source /app/.venv/bin/activate
910
# set debug based on envvar
1011
[[ $DRYCC_DEBUG == "true" ]] && set -x
1112

rootfs/bin/test-style

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55

66
# fail hard and fast even on pipelines
77
set -eou pipefail
8-
8+
# shellcheck disable=SC1091
9+
source /app/.venv/bin/activate
910
flake8 --show-source

rootfs/bin/test-unit

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55

66
# fail hard and fast even on pipelines
77
set -eou pipefail
8+
# shellcheck disable=SC1091
9+
source /app/.venv/bin/activate
810

911
function creating_rsa_key() {
1012
mkdir -p /var/run/secrets/drycc/passport/ \
1113
&& openssl genrsa -out /var/run/secrets/drycc/passport/oidc-rsa-private-key 4096
1214
}
1315

14-
su-exec postgres pg_ctl -D "$PGDATA" start
16+
gosu postgres pg_ctl -D "$PGDATA" start && ln -s /tmp/.s.PGSQL.5432 /var/run/postgresql/.s.PGSQL.5432
1517
creating_rsa_key
1618
python3 manage.py check
1719
coverage run manage.py test --settings=api.settings.testing --noinput api

rootfs/bin/upload-coverage

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
#
3+
# This script is designed to be run inside the container
4+
#
5+
6+
# fail hard and fast even on pipelines
7+
set -eou pipefail
8+
# shellcheck disable=SC1091
9+
source /app/.venv/bin/activate
10+
11+
codecov --required

0 commit comments

Comments
 (0)