Skip to content

Commit 31b8fc2

Browse files
author
lijianguo
committed
chore(dockerfile): use drycc/base image
1 parent 90b98e2 commit 31b8fc2

File tree

6 files changed

+87
-58
lines changed

6 files changed

+87
-58
lines changed

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 --rm ${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: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,45 @@
1-
FROM docker.io/library/python:3.9-alpine
1+
FROM docker.io/drycc/base:bullseye
22

3+
RUN adduser --system \
4+
--shell /bin/bash \
5+
--disabled-password \
6+
--home /app \
7+
--group \
8+
drycc
9+
10+
ENV PYTHON_VERSION="3.10.2"
311
COPY requirements.txt /app/requirements.txt
412

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

2840
COPY . /app
2941

30-
31-
ENV PATH /app/.venv/bin:/app/bin:$PATH
42+
USER drycc
3243
WORKDIR /app
33-
CMD ["/app/bin/boot"]
44+
CMD ["PATH=/app/.venv/bin:\$PATH", "/app/bin/boot"]
3445
EXPOSE 8000

rootfs/Dockerfile.test

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,52 @@
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="/opt/drycc/postgresql/data" \
7+
PYTHON_VERSION="3.10.2" \
8+
REDIS_VERSION="6.2.6" \
9+
RABBITMQ_VERSION="3.9.13" \
10+
POSTGRES_VERSION="14.2" \
11+
GOSU_VERSION="1.14"
712

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-
gcc \
13-
rust \
14-
cargo \
15-
postgresql-dev \
16-
libffi-dev \
17-
musl-dev \
18-
openssl-dev \
13+
RUN buildDeps='gcc rustc cargo libffi-dev musl-dev openssl'; \
14+
install-packages mercurial ca-certificates git $buildDeps \
15+
&& install-stack python $PYTHON_VERSION \
16+
&& install-stack redis $REDIS_VERSION \
17+
&& install-stack rabbitmq $RABBITMQ_VERSION \
18+
&& install-stack postgresql $POSTGRES_VERSION \
19+
&& install-stack gosu $GOSU_VERSION && . init-stack \
1920
&& python3 -m venv /app/.venv \
2021
&& source /app/.venv/bin/activate \
2122
&& pip3 install --disable-pip-version-check --no-cache-dir -r /app/requirements.txt \
2223
&& pip3 install --disable-pip-version-check --no-cache-dir -r /app/dev_requirements.txt \
23-
&& find /app/.venv /usr/local -type f -executable ! -path '*/cryptography*' -exec scanelf --needed --nobanner --format '%n#p' '{}' ';' \
24-
| tr ',' '\n' \
25-
| sort -u \
26-
| awk 'system("[[ -e /app/.venv/lib/" $1 " || -e /usr/local/lib/" $1 " ]]") == 0 { next } { print "so:" $1 }' \
27-
| xargs -rt apk add --no-cache --virtual .python-rundeps \
28-
&& apk add --update --virtual .controller-rundeps \
29-
git \
30-
mercurial \
31-
ca-certificates \
32-
su-exec \
33-
bash \
34-
shadow \
35-
postgresql \
36-
redis \
37-
rabbitmq-server \
24+
# cleanup
25+
&& scanelp /app/.venv/lib > runtime.txt \
26+
&& apt-get purge -y --auto-remove $buildDeps \
27+
&& install-packages $(< runtime.txt) \
28+
&& apt-get autoremove -y \
29+
&& apt-get clean -y \
30+
&& rm -rf \
31+
/usr/share/doc \
32+
/usr/share/man \
33+
/usr/share/info \
34+
/usr/share/locale \
35+
/var/lib/apt/lists/* \
36+
/var/log/* \
37+
/var/cache/debconf/* \
38+
/etc/systemd \
39+
/lib/lsb \
40+
/lib/udev \
41+
/usr/lib/`echo $(uname -m)`-linux-gnu/gconv/IBM* \
42+
/usr/lib/`echo $(uname -m)`-linux-gnu/gconv/EBC* \
43+
&& mkdir -p /usr/share/man/man{1..8} \
3844
&& mkdir -p /run/postgresql $PGDATA \
45+
&& groupadd postgres && useradd -g postgres postgres \
3946
&& chown -R postgres:postgres /run/postgresql $PGDATA \
40-
&& apk del .build-deps \
41-
&& su-exec postgres initdb -D $PGDATA
47+
&& gosu postgres initdb -D $PGDATA
4248

4349
COPY . /app
44-
45-
ENV PATH /app/.venv/bin:/app/bin:$PATH
4650
WORKDIR /app
4751
CMD ["/app/bin/boot"]
4852
EXPOSE 8000

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,6 +5,8 @@
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 start_redis() {
1012
cd /tmp
@@ -18,7 +20,7 @@ function start_rabbitmq() {
1820
cd -
1921
}
2022

21-
su-exec postgres pg_ctl -D "$PGDATA" start
23+
gosu postgres pg_ctl -D "$PGDATA" start && ln -s /tmp/.s.PGSQL.5432 /var/run/postgresql/.s.PGSQL.5432
2224
start_redis
2325
start_rabbitmq
2426
python3 manage.py check

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)