Use slim container variant

This reduces the size of the container, which makes working with it much easier
This commit is contained in:
Jake Howard 2022-08-27 18:22:58 +01:00
parent 54a7dd2660
commit c6776faa8c
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 17 additions and 6 deletions

View file

@ -21,7 +21,7 @@ static:
expire_in: 30 mins expire_in: 30 mins
pip: pip:
image: python:3.10 image: python:3.10-slim
stage: build stage: build
variables: variables:
PIP_CACHE_DIR: $CI_PROJECT_DIR/.pip-cache PIP_CACHE_DIR: $CI_PROJECT_DIR/.pip-cache
@ -29,6 +29,9 @@ pip:
key: pip-$CI_COMMIT_REF_SLUG key: pip-$CI_COMMIT_REF_SLUG
paths: paths:
- "$CI_PROJECT_DIR/.pip-cache" - "$CI_PROJECT_DIR/.pip-cache"
before_script:
- apt-get update --yes
- apt-get install --yes build-essential libpq-dev
script: script:
- python -m venv env - python -m venv env
- source env/bin/activate - source env/bin/activate
@ -40,11 +43,12 @@ pip:
expire_in: 30 mins expire_in: 30 mins
.python_test_template: .python_test_template:
image: python:3.10 image: python:3.10-slim
stage: test stage: test
dependencies: dependencies:
- pip - pip
before_script: before_script:
- apt-get update && apt-get install --yes git libpq-dev
- source env/bin/activate - source env/bin/activate
variables: variables:
SECRET_KEY: super-secret SECRET_KEY: super-secret
@ -144,7 +148,7 @@ container:
before_script: before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script: script:
- docker build -t website --target production -t $DEV_IMAGE_TAG . - docker build --target production -t $DEV_IMAGE_TAG .
- docker push $DEV_IMAGE_TAG - docker push $DEV_IMAGE_TAG
- > - >
if [ "$CI_COMMIT_REF_SLUG" == "master"]; then if [ "$CI_COMMIT_REF_SLUG" == "master"]; then

View file

@ -9,7 +9,7 @@ COPY ./static/src ./static/src
RUN npm run build RUN npm run build
# The actual container # The actual container
FROM python:3.10 as production FROM python:3.10-slim as production
ENV VIRTUAL_ENV=/venv ENV VIRTUAL_ENV=/venv
@ -17,7 +17,12 @@ RUN useradd website --create-home -u 1000 && mkdir /app $VIRTUAL_ENV && chown -R
WORKDIR /app 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 \ ENV PATH=$VIRTUAL_ENV/bin:$PATH \
PYTHONUNBUFFERED=1 PYTHONUNBUFFERED=1
@ -30,6 +35,8 @@ RUN python -m venv $VIRTUAL_ENV
COPY --chown=website requirements/base.txt ./requirements/base.txt 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 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 --from=frontend ./static/build ./static/build
COPY --chown=website ./etc ./etc COPY --chown=website ./etc ./etc