diff --git a/.dockerignore b/.dockerignore index 2a44415..978b2ef 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,9 @@ **/__pycache__/ venv/ -guide/site +.idea/ +/.github/ +/data/ +/guide/site +/guide/.cache +flake.lock +flake.nix diff --git a/Dockerfile b/Dockerfile index 62add2f..a02e7fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,14 +20,15 @@ RUN --mount=type=cache,target=/root/.cache/pip \ COPY . . RUN sed -i "s/\(COMMIT_HASH *= *\).*/\1'$(git rev-parse HEAD)'/" tgpy/version.py +RUN rm -rf .git guide poetry.lock pyproject.toml .dockerignore .gitignore README.md FROM base as runner COPY --from=builder /venv /venv ENV PATH="/venv/bin:$PATH" -COPY --from=builder /app/tgpy tgpy +COPY --from=builder /app /app ENV TGPY_DATA=/data VOLUME /data -ENTRYPOINT ["/venv/bin/python", "-m", "tgpy"] +ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/docker/install_mods.py b/docker/install_mods.py new file mode 100644 index 0000000..dfef599 --- /dev/null +++ b/docker/install_mods.py @@ -0,0 +1,31 @@ +import logging +from subprocess import Popen + +from tgpy.api.config import config + +logging.basicConfig( + format='[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s', + datefmt='%Y-%m-%d %H:%M:%S', + level=logging.INFO, +) +logger = logging.getLogger('install_mods') + + +def main(): + config.load() + command_groups: dict = config.get('docker.setup_commands', {}) + command_groups['_core'] = 'apt-get update' + for name, commands in sorted(command_groups.items()): + if isinstance(commands, str): + commands = [commands] + logger.info(f"Running setup command group '{name}'") + for command in commands: + logger.info(f"Running setup command '{command}'") + p = Popen(command, shell=True) + p.wait() + if p.returncode != 0: + logger.info("Running setup command failed") + + +if __name__ == '__main__': + main() diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..57eac9f --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -e +if [ ! -f container_setup_completed ]; then + PYTHONPATH=. python /app/docker/install_mods.py + touch container_setup_completed +fi + +exec python -m tgpy