diff --git a/Dockerfile b/Dockerfile index 7a759e54..2112b0b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,6 +30,7 @@ ENV UMASK=022 ENV YTP_CONFIG_PATH=/config ENV YTP_TEMP_PATH=/tmp ENV YTP_DOWNLOAD_PATH=/downloads +ENV YTP_PORT=8081 # removed ffmpeg as 6.1.0 is broken with DASH protocal downloads COPY --from=mwader/static-ffmpeg:6.1.1 /ffmpeg /usr/bin/ @@ -47,22 +48,23 @@ RUN sed -i 's/\r$//g' /entrypoint.sh && chmod +x /entrypoint.sh COPY --chown=app:app ./app /app/app COPY --chown=app:app --from=npm_builder /ytptube/dist /app/frontend/dist COPY --chown=app:app --from=python_builder /app/.venv /app/.venv +COPY --chown=app:app ./healthcheck.sh /usr/local/bin/healthcheck ENV PATH="/app/.venv/bin:$PATH" -RUN chown -R app:app /config /downloads +RUN chown -R app:app /config /downloads && chmod +x /usr/local/bin/healthcheck VOLUME /config VOLUME /downloads EXPOSE 8081 -# Switch to user -# USER app WORKDIR /tmp +HEALTHCHECK --interval=10s --timeout=20s --start-period=10s --retries=3 CMD [ "/usr/local/bin/healthcheck" ] + ENTRYPOINT ["/entrypoint.sh"] CMD ["/app/.venv/bin/python", "/app/app/main.py"] diff --git a/app/main.py b/app/main.py index 52be5d8a..5ddeae12 100644 --- a/app/main.py +++ b/app/main.py @@ -204,6 +204,10 @@ class Main: f'Added task to grab {task.get("name",task.get("url"))} content every [{cron_timer}].') def addRoutes(self): + @self.routes.get(self.config.url_prefix + 'ping') + async def ping(_) -> Response: + return web.Response(text='pong') + @self.routes.post(self.config.url_prefix + 'add') async def add(request: Request) -> Response: post = await request.json() diff --git a/healthcheck.sh b/healthcheck.sh new file mode 100644 index 00000000..4d0e93b8 --- /dev/null +++ b/healthcheck.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -eu pipefail + +/usr/bin/curl -f http://localhost:${YTP_PORT:-8081}/ping