-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docker): run specified commands on container creation. This feat…
…ure can be used for example to persist installed packages between updates
- Loading branch information
Showing
4 changed files
with
49 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
**/__pycache__/ | ||
venv/ | ||
guide/site | ||
.idea/ | ||
/.github/ | ||
/data/ | ||
/guide/site | ||
/guide/.cache | ||
flake.lock | ||
flake.nix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |