diff --git a/.env.example b/.env.example index 97339446d..9ebe3fc24 100644 --- a/.env.example +++ b/.env.example @@ -29,10 +29,6 @@ FUNKWHALE_SPA_HTML_ROOT=http://nginx/ LDAP_ENABLED=False BROWSABLE_API_ENABLED=True -# celeryworker - -CELERYD_CONCURRENCY=0 - # api + nginx STATIC_ROOT=/staticfiles diff --git a/api/.dockerignore b/api/.dockerignore index 729de9825..dc2e56f7a 100644 --- a/api/.dockerignore +++ b/api/.dockerignore @@ -1,8 +1,8 @@ # Exclude everything and allow only the necessary files * -!/docker/ !/config/ !/funkwhale_api/ +!/entrypoint.sh !/manage.py !/poetry.lock !/pyproject.toml diff --git a/api/Dockerfile.alpine b/api/Dockerfile.alpine index 6a5599b08..7b08b651d 100644 --- a/api/Dockerfile.alpine +++ b/api/Dockerfile.alpine @@ -103,6 +103,7 @@ ARG PIP_NO_CACHE_DIR=1 RUN set -eux; \ apk add --no-cache \ bash \ + curl \ ffmpeg \ gettext \ jpeg-dev \ @@ -132,6 +133,8 @@ RUN --mount=type=cache,target=~/.cache/pip; \ set -eux; \ pip3 install --no-deps --editable . -ENV IS_DOCKER_SETUP=true +ADD --chown=0:0 --chmod=u+x ./entrypoint.sh / +ENTRYPOINT [ "/entrypoint.sh" ] -CMD ["./docker/server.sh"] +HEALTHCHECK --start-period=60s --interval=10s --timeout=5s --retries=3 \ + CMD curl -o /dev/null -s -w "%{http_code}" http://localhost:5000/api/v1 | grep "301" || exit 1 diff --git a/api/Dockerfile.debian b/api/Dockerfile.debian index 8e4de64bb..4b3a561c2 100644 --- a/api/Dockerfile.debian +++ b/api/Dockerfile.debian @@ -51,6 +51,7 @@ ENV PATH="/venv/bin:$PATH" RUN --mount=type=cache,target=/var/lib/apt/lists \ apt update; \ apt install -y \ + curl \ ffmpeg \ gettext \ libjpeg-dev \ @@ -68,4 +69,8 @@ WORKDIR /app COPY . /app RUN poetry install --extras typesense -CMD ["./docker/server.sh"] +ADD --chown=0:0 --chmod=u+x ./entrypoint.sh / +ENTRYPOINT [ "/entrypoint.sh" ] + +HEALTHCHECK --start-period=60s --interval=10s --timeout=5s --retries=3 \ + CMD curl -o /dev/null -s -w "%{http_code}" http://localhost:5000/api/v1 | grep "301" || exit 1 diff --git a/api/docker/server.sh b/api/docker/server.sh deleted file mode 100755 index e4aebcb98..000000000 --- a/api/docker/server.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -set -eux - -funkwhale-manage collectstatic --noinput -funkwhale-manage migrate - -# shellcheck disable=SC2086 -exec gunicorn config.asgi:application \ - --workers "${FUNKWHALE_WEB_WORKERS-1}" \ - --worker-class uvicorn.workers.UvicornWorker \ - --bind 0.0.0.0:"${FUNKWHALE_API_PORT}" \ - ${GUNICORN_ARGS-} diff --git a/api/entrypoint.sh b/api/entrypoint.sh new file mode 100755 index 000000000..830ea9594 --- /dev/null +++ b/api/entrypoint.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env sh + +set -eux + +case "${1}" in + gunicorn) + # shellcheck disable=SC2086 + exec gunicorn config.asgi:application \ + --workers "${FUNKWHALE_WEB_WORKERS:-1}" \ + --worker-class uvicorn.workers.UvicornWorker \ + --bind 0.0.0.0:"${FUNKWHALE_API_PORT}" \ + ${GUNICORN_ARGS:-} + ;; + migrate) + funkwhale-manage migrate + ;; + collectstatic) + funkwhale-manage collectstatic --noinput + ;; + uvicorn) + exec uvicorn \ + --reload config.asgi:application \ + --host 0.0.0.0 \ + --port 5000 \ + --reload-dir config/ \ + --reload-dir funkwhale_api/ + ;; + develop) + ${0} migrate + ${0} collectstatic + ${0} uvicorn + ;; + develop-celery) + export CELERYD_CONCURRENCY=0 + watchmedo auto-restart \ + --patterns="*.py" \ + --recursive \ + -- \ + celery \ + -A funkwhale_api.taskapp worker \ + -B \ + -l debug \ + -s /tmp/celerybeat-schedule \ + --concurrency=${CELERYD_CONCURRENCY} + ;; + *) + exec "${@}" + ;; +esac diff --git a/compose/app.django.yml b/compose/app.django.yml index 7c1ec7a7a..3452c1dfb 100644 --- a/compose/app.django.yml +++ b/compose/app.django.yml @@ -50,22 +50,8 @@ services: build: context: ../api dockerfile: Dockerfile.debian - healthcheck: - test: 'curl -o /dev/null -s -w "%{http_code}" http://localhost:5000/api/v1 | grep "301" || exit 1' - interval: 10s - timeout: 5s - retries: 3 - start_period: 60s - command: > - sh -c " - funkwhale-manage collectstatic --no-input && - uvicorn --reload config.asgi:application --host 0.0.0.0 --port 5000 --reload-dir config/ --reload-dir funkwhale_api/ - " + command: develop celeryworker: <<: *django - command: > - sh -c ' - pip install watchdog[watchmedo] && - watchmedo auto-restart --patterns="*.py" --recursive -- celery -A funkwhale_api.taskapp worker -l debug -B --concurrency=${CELERYD_CONCURRENCY} - ' + command: develop-celery diff --git a/front/Dockerfile.dev b/front/Dockerfile.dev index ddd30d7f6..bd9d14299 100644 --- a/front/Dockerfile.dev +++ b/front/Dockerfile.dev @@ -1,26 +1,17 @@ -FROM node:22-alpine +FROM node:18-alpine # needed to compile translations -RUN apk add --no-cache jq bash coreutils git python3 +RUN apk add --no-cache jq bash coreutils python3 -WORKDIR /app/ - -# Create node_modules directory to prevent it from being hidden by volume mounts -RUN mkdir -p node_modules - -ADD scripts/ ./scripts/ -ADD package.json yarn.lock ./ -RUN yarn - -VOLUME /app -VOLUME /app/node_modules EXPOSE 8080 +WORKDIR /app/ +COPY scripts/ ./scripts/ +ADD package.json yarn.lock ./ +RUN yarn install -<<<<<<< HEAD -CMD ["yarn", "dev", "--host"] -======= -CMD ["yarn", "serve"] +COPY . . + +CMD [ "yarn", "serve" ] HEALTHCHECK --start-period=30s --interval=10s --timeout=5s \ CMD wget --no-verbose --tries=1 --spider http://localhost:8080/ || exit 1 ->>>>>>> afceb5bf3 (chore(compose): dependencies, environments and healthchecks)