From c6776faa8c764cfb1bf9be8ff65444c6d76c95d9 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 27 Aug 2022 18:22:58 +0100 Subject: [PATCH] Use slim container variant This reduces the size of the container, which makes working with it much easier --- .gitlab-ci.yml | 10 +++++++--- Dockerfile | 13 ++++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 43966b5..c0c74dc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -21,7 +21,7 @@ static: expire_in: 30 mins pip: - image: python:3.10 + image: python:3.10-slim stage: build variables: PIP_CACHE_DIR: $CI_PROJECT_DIR/.pip-cache @@ -29,6 +29,9 @@ pip: key: pip-$CI_COMMIT_REF_SLUG paths: - "$CI_PROJECT_DIR/.pip-cache" + before_script: + - apt-get update --yes + - apt-get install --yes build-essential libpq-dev script: - python -m venv env - source env/bin/activate @@ -40,11 +43,12 @@ pip: expire_in: 30 mins .python_test_template: - image: python:3.10 + image: python:3.10-slim stage: test dependencies: - pip before_script: + - apt-get update && apt-get install --yes git libpq-dev - source env/bin/activate variables: SECRET_KEY: super-secret @@ -144,7 +148,7 @@ container: before_script: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY script: - - docker build -t website --target production -t $DEV_IMAGE_TAG . + - docker build --target production -t $DEV_IMAGE_TAG . - docker push $DEV_IMAGE_TAG - > if [ "$CI_COMMIT_REF_SLUG" == "master"]; then diff --git a/Dockerfile b/Dockerfile index 659b654..dac779a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM node:16-slim as frontend COPY package.json package-lock.json ./ -RUN npm ci --no-audit --progress=false --omit=dev +RUN npm ci --no-audit - -progress=false --omit=dev # Compile static files COPY ./scripts ./scripts @@ -9,7 +9,7 @@ COPY ./static/src ./static/src RUN npm run build # The actual container -FROM python:3.10 as production +FROM python:3.10-slim as production ENV VIRTUAL_ENV=/venv @@ -17,7 +17,12 @@ RUN useradd website --create-home -u 1000 && mkdir /app $VIRTUAL_ENV && chown -R WORKDIR /app -RUN wget https://github.com/aptible/supercronic/releases/download/v0.2.1/supercronic-linux-amd64 -O /usr/local/bin/supercronic && chmod +x /usr/local/bin/supercronic +RUN apt-get update --yes --quiet && apt-get install --yes --quiet --no-install-recommends \ + build-essential \ + libpq-dev \ + curl + +RUN curl -fsSL https://github.com/aptible/supercronic/releases/download/v0.2.1/supercronic-linux-amd64 -o /usr/local/bin/supercronic && chmod +x /usr/local/bin/supercronic ENV PATH=$VIRTUAL_ENV/bin:$PATH \ PYTHONUNBUFFERED=1 @@ -30,6 +35,8 @@ RUN python -m venv $VIRTUAL_ENV COPY --chown=website requirements/base.txt ./requirements/base.txt RUN pip install --no-cache --upgrade pip && pip install --no-cache -r ./requirements/base.txt +RUN apt-get remove --yes build-essential && apt-get autoremove --yes && rm -rf /var/lib/apt/lists /var/cache/apt + COPY --chown=website --from=frontend ./static/build ./static/build COPY --chown=website ./etc ./etc