WIP: cleanup setup

This commit is contained in:
Benjamin Bach 2024-07-14 21:19:32 +02:00
parent 1405a95094
commit b366bc2499
No known key found for this signature in database
GPG key ID: 486F0D69C845416E
7 changed files with 21 additions and 51 deletions

View file

@ -7,7 +7,6 @@ steps:
- name: docker
image: plugins/docker
environment:
DJANGO_ENV: production
BUILD: "${DRONE_COMMIT_SHA}"
settings:
repo: docker.data.coop/membersystem
@ -17,7 +16,6 @@ steps:
password:
from_secret: DOCKER_PASSWORD
build_args_from_env:
- DJANGO_ENV
- BUILD
tags:
- "${DRONE_BUILD_NUMBER}"

View file

@ -6,4 +6,3 @@ DATABASE_URL=postgres://postgres:postgres@postgres:5432/postgres
# Use something along the the following if you are not using docker
# DATABASE_URL=postgres://postgres:postgres@localhost:5432/datacoop_membersystem
DEBUG=True
DJANGO_ENV=development

View file

@ -7,16 +7,12 @@ ENV PYTHONFAULTHANDLER=1 \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100
ARG DJANGO_ENV
ARG BUILD
ENV BUILD ${BUILD}
WORKDIR /app
RUN groupadd -g 1000 www && useradd -u 1000 -ms /bin/bash -g www www
COPY --chown=www:www . .
RUN mkdir /app/src/static \
&& chown www:www /app/src/static \
RUN groupadd -g 1000 www && useradd -u 1000 -ms /bin/bash -g www www \
&& apt-get update \
&& apt-get install -y \
binutils \
@ -29,8 +25,14 @@ RUN mkdir /app/src/static \
libgdk-pixbuf2.0-0 \
libffi-dev \
shared-mime-info \
gettext \
&& pip install . \
gettext
COPY --chown=www:www . .
RUN mkdir /app/src/static \
&& chown www:www /app/src/static
RUN pip install . \
&& django-admin compilemessages
ENTRYPOINT ["./entrypoint.sh"]

View file

@ -1,6 +1,5 @@
DOCKER_COMPOSE = COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker compose
DOCKER_RUN = ${DOCKER_COMPOSE} run -u `id -u`
DOCKER_BUILD = DOCKER_BUILDKIT=1 docker build
DOCKER_CONTAINER_NAME = backend
MANAGE_EXEC = python /app/src/manage.py
MANAGE_COMMAND = ${DOCKER_RUN} ${DOCKER_CONTAINER_NAME} ${MANAGE_EXEC}
@ -10,12 +9,6 @@ init: setup_venv pre_commit_install migrate
run:
${DOCKER_COMPOSE} up
setup_venv:
rm -rf venv
python3.11 -m venv venv;
venv/bin/python -m pip install wheel setuptools;
venv/bin/python -m pip install pre-commit boto3 pip-tools;
pre_commit_install:
venv/bin/pre-commit install
@ -37,22 +30,5 @@ shell:
manage_command:
${MANAGE_COMMAND} ${ARGS}
add_dependency:
${DOCKER_RUN} ${DOCKER_CONTAINER_NAME} poetry add --lock ${DEPENDENCY}
add_dev_dependency:
${DOCKER_RUN} ${DOCKER_CONTAINER_NAME} poetry add -D --lock ${DEPENDENCY}
poetry_lock:
${DOCKER_RUN} ${DOCKER_CONTAINER_NAME} poetry lock --no-update
poetry_command:
${DOCKER_RUN} ${DOCKER_CONTAINER_NAME} poetry ${COMMAND}
build_dev_docker_image: compile_requirements
build_dev_docker_image:
${DOCKER_COMPOSE} build ${DOCKER_CONTAINER_NAME}
compile_requirements:
./venv/bin/pip-compile --output-file requirements/base.txt requirements/base.in
./venv/bin/pip-compile --output-file requirements/test.txt requirements/test.in
./venv/bin/pip-compile --output-file requirements/dev.txt requirements/dev.in

View file

@ -56,7 +56,7 @@ Activate the venv
Install requirements
$ pip install -r requirements/dev.txt
$ pip install .
Run migrations

View file

@ -1,5 +1,3 @@
version: '3.7'
services:
backend:
@ -13,7 +11,8 @@ services:
volumes:
- ./:/app/
depends_on:
- postgres
postgres:
condition: service_healthy
env_file:
- .env
@ -25,6 +24,13 @@ services:
- 5432:5432
env_file:
- .env
# This healthcheck has a large number of retries, this is currently based on the number of
# retries necessary to get the database running in GitHub Actions.
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres -d postgres" ]
interval: 5s
timeout: 5s
retries: 30
volumes:
postgres_data:

View file

@ -1,16 +1,5 @@
#!/bin/sh
echo "Waiting for postgres..."
POSTGRES_PORT=${POSTGRES_PORT:-5432}
POSTGRES_HOST=${POSTGRES_HOST:-localhost}
while ! nc -z "$POSTGRES_HOST" "$POSTGRES_PORT"; do
sleep 0.1
done
echo "PostgreSQL started"
# Only migrate, collectstatic and compilemessages if we are NOT in development
if [ -z "$DEBUG" ]; then
python src/manage.py migrate;