feat(compose/api): move healthcheck to Dockerfile + update entrypoint.sh
This commit is contained in:
		
							parent
							
								
									034a7b75cd
								
							
						
					
					
						commit
						99f3f36ed5
					
				| 
						 | 
					@ -27,10 +27,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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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-}
 | 
					 | 
				
			||||||
| 
						 | 
					@ -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
 | 
				
			||||||
| 
						 | 
					@ -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}
 | 
					 | 
				
			||||||
      '
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,7 +11,7 @@ RUN yarn install
 | 
				
			||||||
 | 
					
 | 
				
			||||||
COPY . .
 | 
					COPY . .
 | 
				
			||||||
 | 
					
 | 
				
			||||||
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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue