Skip to content

Commit 245e6f5

Browse files
authored
Merge pull request #3 from jianxiaoguo/main
chore(dockerfile): use drycc/base image
2 parents 924a353 + 2d5ba72 commit 245e6f5

7 files changed

Lines changed: 89 additions & 75 deletions

File tree

Makefile

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

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

6868
.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: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,47 @@
1-
FROM docker.io/library/python:3.9-alpine
1+
FROM docker.io/drycc/base:bullseye
22

3-
COPY requirements.txt /app/requirements.txt
3+
RUN adduser --system \
4+
--shell /bin/bash \
5+
--disabled-password \
6+
--home /app \
7+
--group \
8+
drycc
49

5-
ENV PATH="/app/.venv/bin:${PATH}"
10+
ENV PYTHON_VERSION="3.10.2" \
11+
HELM_VERSION="3.8.0"
612

713
COPY . /app
814

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

33-
ENV PATH /app/.venv/bin:/app/bin:$PATH
34-
CMD ["/app/bin/boot"]
44+
USER drycc
45+
WORKDIR /app
46+
CMD ["PATH=/app/.venv/bin:\$PATH", "/app/bin/boot"]
3547
EXPOSE 8000

rootfs/Dockerfile.test

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,50 @@
1-
FROM docker.io/library/python:3.9-alpine
1+
FROM docker.io/drycc/base:bullseye
22

3-
COPY requirements.txt /app/requirements.txt
3+
RUN adduser --system \
4+
--shell /bin/bash \
5+
--disabled-password \
6+
--home /app \
7+
--group \
8+
drycc
49

5-
ENV PATH="/app/.venv/bin:${PATH}"
10+
ENV PYTHON_VERSION="3.10.2" \
11+
HELM_VERSION="3.8.0" \
12+
KUBECTL_VERSION="1.23.4"
613

714
COPY . /app
8-
915
WORKDIR /app
1016

11-
RUN apk add --update --virtual .build-deps \
12-
musl-dev \
13-
openssl-dev \
17+
RUN buildDeps='musl-dev openssl'; \
18+
install-packages $buildDeps \
19+
&& install-stack python $PYTHON_VERSION \
20+
&& install-stack helm $HELM_VERSION \
21+
&& install-stack kubectl $KUBECTL_VERSION && . init-stack \
1422
&& python3 -m venv /app/.venv \
1523
&& source /app/.venv/bin/activate \
1624
&& pip3 install --disable-pip-version-check --no-cache-dir -r /app/requirements.txt \
1725
&& pip3 install --disable-pip-version-check --no-cache-dir -r /app/dev_requirements.txt \
18-
&& find /app/.venv /usr/local -type f -executable ! -path '*/cryptography*' -exec scanelf --needed --nobanner --format '%n#p' '{}' ';' \
19-
| tr ',' '\n' \
20-
| sort -u \
21-
| awk 'system("[[ -e /app/.venv/lib/" $1 " || -e /usr/local/lib/" $1 " ]]") == 0 { next } { print "so:" $1 }' \
22-
| xargs -rt apk add --no-cache --virtual .python-rundeps \
23-
&& apk add --update --virtual .helmbroker-rundeps \
24-
$runDeps \
25-
git \
26-
ca-certificates \
27-
su-exec \
28-
bash \
29-
shadow \
30-
curl \
31-
&& apk del .build-deps \
32-
&& chmod +x /app/bin/* \
33-
&& /app/bin/install
34-
COPY . /app
26+
# cleanup
27+
&& scanelp /app/.venv/lib > runtime.txt \
28+
&& apt-get purge -y --auto-remove $buildDeps \
29+
&& install-packages $(< runtime.txt) \
30+
&& apt-get autoremove -y \
31+
&& apt-get clean -y \
32+
&& rm -rf \
33+
/usr/share/doc \
34+
/usr/share/man \
35+
/usr/share/info \
36+
/usr/share/locale \
37+
/var/lib/apt/lists/* \
38+
/var/log/* \
39+
/var/cache/debconf/* \
40+
/etc/systemd \
41+
/lib/lsb \
42+
/lib/udev \
43+
/usr/lib/`echo $(uname -m)`-linux-gnu/gconv/IBM* \
44+
/usr/lib/`echo $(uname -m)`-linux-gnu/gconv/EBC* \
45+
&& mkdir -p /usr/share/man/man{1..8} \
3546

36-
ENV PATH /app/.venv/bin:/app/bin:$PATH
47+
USER drycc
48+
WORKDIR /app
3749
CMD ["/app/bin/boot"]
3850
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
# spawn a gunicorn server in the background
1011
echo ""
1112
echo "Starting up Gunicorn"

rootfs/bin/install

Lines changed: 0 additions & 23 deletions
This file was deleted.

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 --exclude .venv,migrations

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)