Skip to content

Commit 729e64d

Browse files
chore(bot): change Docker base image to python:3.7-slim (#796)
While scanning the Kodiak Docker image with [Grype](https://github.com/anchore/grype), we noticed a significant amount of vulnerabilities. This PR upgrade the base image to the latest 3.7 image and use the slim version which come with a smaller size and reduce the attack surface. I also took the opportunity to use a non root user. - previously: image size 1.31GB, 3694 vulnerabilities - now: image size 607Mb, 87 vulnerabilities
1 parent a16e7ba commit 729e64d

3 files changed

Lines changed: 31 additions & 23 deletions

File tree

.circleci/config.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 2
33
jobs:
44
bot_test:
55
docker:
6-
- image: python:3.7
6+
- image: python:3.7-slim
77
auth:
88
username: $DOCKER_USER
99
password: $DOCKER_PASS
@@ -12,6 +12,11 @@ jobs:
1212
username: $DOCKER_USER
1313
password: $DOCKER_PASS
1414
steps:
15+
- run:
16+
name: install git
17+
command: |
18+
apt update
19+
apt install -y git
1520
- checkout
1621
- run:
1722
name: skip build if no changes
@@ -84,7 +89,7 @@ jobs:
8489
# https://circleci.com/docs/2.0/building-docker-images/
8590
bot_build_container:
8691
docker:
87-
- image: docker:18.05.0-ce
92+
- image: docker:20.10.23
8893
auth:
8994
username: $DOCKER_USER
9095
password: $DOCKER_PASS

bot/Dockerfile

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
FROM python:3.7@sha256:6eaf19442c358afc24834a6b17a3728a45c129de7703d8583392a138ecbdb092
1+
FROM python:3.7-slim
2+
3+
RUN apt update && \
4+
apt-get install --no-install-recommends -y \
5+
supervisor \
6+
git && \
7+
python -m pip install --upgrade pip && \
8+
pip install \
9+
--no-cache-dir \
10+
--root-user-action=ignore \
11+
cryptography===37.0.4 \
12+
poetry===1.1.15 && \
13+
poetry config virtualenvs.in-project true && \
14+
groupadd kodiak && \
15+
useradd --uid 1000 --gid kodiak kodiak && \
16+
mkdir -p /var/app && \
17+
chown -R kodiak:kodiak /var/app
218

3-
RUN set -ex && mkdir -p /var/app
4-
5-
RUN apt-get update && apt-get install -y supervisor
6-
7-
RUN mkdir -p /var/log/supervisor
8-
9-
# use cryptography version for poetry that doesn't require Rust
10-
RUN python3 -m pip install cryptography===37.0.4
11-
RUN python3 -m pip install poetry===1.1.13
12-
13-
RUN poetry config virtualenvs.in-project true
19+
WORKDIR /var/app
1420

1521
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
1622

17-
WORKDIR /var/app
18-
19-
COPY pyproject.toml poetry.lock /var/app/
23+
COPY --chown=kodiak pyproject.toml poetry.lock ./
2024

2125
# install deps
2226
RUN poetry install
2327

24-
COPY . /var/app
28+
COPY --chown=kodiak . ./
2529

26-
# workaround for: https://github.com/sdispater/poetry/issues/1123
27-
RUN rm -rf /var/app/pip-wheel-metadata/
28-
29-
# install cli
30-
RUN poetry install
30+
USER kodiak
3131

3232
CMD ["/usr/bin/supervisord"]

bot/supervisord.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
[supervisord]
22
nodaemon=true
3+
user=kodiak
34

45
[program:ingest]
56
command=/var/app/.venv/bin/python -m kodiak.entrypoints.ingest
67
stdout_logfile=/dev/stdout
8+
stderr_logfile=/dev/stdout
79
stdout_logfile_maxbytes=0
810

911
[program:worker]
1012
command=/var/app/.venv/bin/python -m kodiak.entrypoints.worker
1113
stdout_logfile=/dev/stdout
14+
stderr_logfile=/dev/stdout
1215
stdout_logfile_maxbytes=0

0 commit comments

Comments
 (0)