feat(compose/api): move healthcheck to Dockerfile + update entrypoint.sh

This commit is contained in:
jon r 2025-02-26 00:28:43 +01:00
parent bc71203869
commit 235c415205
8 changed files with 72 additions and 55 deletions

View File

@ -29,10 +29,6 @@ FUNKWHALE_SPA_HTML_ROOT=http://nginx/
LDAP_ENABLED=False LDAP_ENABLED=False
BROWSABLE_API_ENABLED=True BROWSABLE_API_ENABLED=True
# celeryworker
CELERYD_CONCURRENCY=0
# api + nginx # api + nginx
STATIC_ROOT=/staticfiles STATIC_ROOT=/staticfiles

View File

@ -1,8 +1,8 @@
# Exclude everything and allow only the necessary files # Exclude everything and allow only the necessary files
* *
!/docker/
!/config/ !/config/
!/funkwhale_api/ !/funkwhale_api/
!/entrypoint.sh
!/manage.py !/manage.py
!/poetry.lock !/poetry.lock
!/pyproject.toml !/pyproject.toml

View File

@ -103,6 +103,7 @@ ARG PIP_NO_CACHE_DIR=1
RUN set -eux; \ RUN set -eux; \
apk add --no-cache \ apk add --no-cache \
bash \ bash \
curl \
ffmpeg \ ffmpeg \
gettext \ gettext \
jpeg-dev \ jpeg-dev \
@ -132,6 +133,8 @@ RUN --mount=type=cache,target=~/.cache/pip; \
set -eux; \ set -eux; \
pip3 install --no-deps --editable . 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

View File

@ -51,6 +51,7 @@ ENV PATH="/venv/bin:$PATH"
RUN --mount=type=cache,target=/var/lib/apt/lists \ RUN --mount=type=cache,target=/var/lib/apt/lists \
apt update; \ apt update; \
apt install -y \ apt install -y \
curl \
ffmpeg \ ffmpeg \
gettext \ gettext \
libjpeg-dev \ libjpeg-dev \
@ -68,4 +69,8 @@ WORKDIR /app
COPY . /app COPY . /app
RUN poetry install --extras typesense 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

View File

@ -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-}

49
api/entrypoint.sh Executable file
View File

@ -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

View File

@ -50,22 +50,8 @@ services:
build: build:
context: ../api context: ../api
dockerfile: Dockerfile.debian dockerfile: Dockerfile.debian
healthcheck: command: develop
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/
"
celeryworker: celeryworker:
<<: *django <<: *django
command: > command: develop-celery
sh -c '
pip install watchdog[watchmedo] &&
watchmedo auto-restart --patterns="*.py" --recursive -- celery -A funkwhale_api.taskapp worker -l debug -B --concurrency=${CELERYD_CONCURRENCY}
'

View File

@ -1,26 +1,17 @@
FROM node:22-alpine FROM node:18-alpine
# needed to compile translations # 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 EXPOSE 8080
WORKDIR /app/
COPY scripts/ ./scripts/
ADD package.json yarn.lock ./
RUN yarn install
<<<<<<< HEAD COPY . .
CMD ["yarn", "dev", "--host"]
======= CMD [ "yarn", "serve" ]
CMD ["yarn", "serve"]
HEALTHCHECK --start-period=30s --interval=10s --timeout=5s \ HEALTHCHECK --start-period=30s --interval=10s --timeout=5s \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/ || exit 1 CMD wget --no-verbose --tries=1 --spider http://localhost:8080/ || exit 1
>>>>>>> afceb5bf3 (chore(compose): dependencies, environments and healthchecks)