From 541bf7d2d75051646188d3ae14d579d5fdc52bcb Mon Sep 17 00:00:00 2001 From: 3wc <3wc.cyberia@doesthisthing.work> Date: Fri, 9 Jul 2021 23:27:41 +0200 Subject: [PATCH 1/2] Initial attempt at Docker --- .drone.yml | 14 ++++++++++++++ Dockerfile | 26 ++++++++++++++++++++++++++ docker-compose.yml | 26 ++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 .drone.yml create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..a487bc8 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,14 @@ +--- +kind: pipeline +name: publish docker image +steps: + - name: build and publish + image: plugins/docker + settings: + username: + from_secret: docker_reg_username_3wc + password: + from_secret: docker_reg_passwd_3wc + repo: 3wordchant/capsul-flask + tags: latest + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9b7af19 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM python:3.8-alpine + +RUN apk add gettext git gcc python3-dev musl-dev \ + libffi-dev zlib-dev jpeg-dev libjpeg postgresql-dev build-base \ + --virtual .build-dependencies + +RUN mkdir /code +WORKDIR /code +COPY Pipfile Pipfile.lock /code/ + +RUN pip install pipenv setuptools wheel cppy + +RUN pipenv install --system --deploy --verbose + +RUN apk del .build-dependencies \ + && rm -rf /var/cache/apk/* /tmp/* + +RUN apk add --no-cache libpq libstdc++ libjpeg + +COPY . /code/ + +CMD ["gunicorn", "--bind", "0.0.0.0:5000", "-k", "gevent", "--worker-connections", "1000", "app:app"] + +VOLUME /code + +EXPOSE 5000 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ac5946e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,26 @@ +--- +version: "3.8" + +services: + app: + image: 3wordchant/capsul-flask:latest + build: . + volumes: + - "./:/code" + depends_on: + - db + ports: + - "5000:5000" + environment: + - "POSTGRES_CONNECTION_PARAMETERS=host=db port=5432 user=capsul password=capsul dbname=capsul" + db: + image: "postgres:9.6.5" + volumes: + - "postgres:/var/lib/postgresql/data" + environment: + POSTGRES_USER: capsul + POSTGRES_PASSWORD: capsul + POSTGRES_DB: capsul + +volumes: + postgres: From 647a19bfa7d90fb07f8d9318b42d8359422760f4 Mon Sep 17 00:00:00 2001 From: 3wc <3wc.cyberia@doesthisthing.work> Date: Sat, 10 Jul 2021 14:23:33 +0200 Subject: [PATCH 2/2] Multi-stage build oh my! --- Dockerfile | 28 +++++++++++++++++----------- docker-compose.yml | 2 +- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9b7af19..0bfea76 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,32 @@ -FROM python:3.8-alpine +FROM python:3.8-alpine as build RUN apk add gettext git gcc python3-dev musl-dev \ libffi-dev zlib-dev jpeg-dev libjpeg postgresql-dev build-base \ --virtual .build-dependencies -RUN mkdir /code -WORKDIR /code -COPY Pipfile Pipfile.lock /code/ +RUN mkdir -p /app/{code,venv} +WORKDIR /app/code +COPY Pipfile Pipfile.lock /app/code/ -RUN pip install pipenv setuptools wheel cppy +RUN python3 -m venv /app/venv +RUN pip install pipenv setuptools +ENV PATH="/app/venv/bin:$PATH" VIRTUAL_ENV="/app/venv" +RUN pip install wheel cppy +# Install dependencies into the virtual environment with Pipenv +RUN pipenv install --deploy --verbose -RUN pipenv install --system --deploy --verbose - -RUN apk del .build-dependencies \ - && rm -rf /var/cache/apk/* /tmp/* +FROM python:3.8-alpine RUN apk add --no-cache libpq libstdc++ libjpeg -COPY . /code/ +COPY . /app/code/ +WORKDIR /app/code + +COPY --from=build /app/venv /app/venv +ENV PATH="/app/venv/bin:$PATH" VIRTUAL_ENV="/app/venv" CMD ["gunicorn", "--bind", "0.0.0.0:5000", "-k", "gevent", "--worker-connections", "1000", "app:app"] -VOLUME /code +VOLUME /app/code EXPOSE 5000 diff --git a/docker-compose.yml b/docker-compose.yml index ac5946e..11b546b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: image: 3wordchant/capsul-flask:latest build: . volumes: - - "./:/code" + - "./:/app/code" depends_on: - db ports: