Skip to content

Instantly share code, notes, and snippets.

@jpic
Last active October 31, 2020 05:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpic/e6d9e5ba6d6cff868c9279fd279a4dca to your computer and use it in GitHub Desktop.
Save jpic/e6d9e5ba6d6cff868c9279fd279a4dca to your computer and use it in GitHub Desktop.
Parallel npm + pip container build + pod management
#!/usr/bin/env python
"""
Shlaxfile for shlax itself.
"""
from shlax.shortcuts import *
env = dict(
DJANGO_SETTINGS_MODULE='ylserver.settings',
UWSGI_MODULE='ylserver.wsgi:application',
PYTHONIOENCODING='UTF-8',
PYTHONUNBUFFERED=1,
POSTGRES_DB='yourlab',
POSTGRES_USER='yourlab',
POSTGRES_PASSWORD='yourlab',
STATIC_URL='/static/',
)
install = Target(
Run('''
mkdir -p ./data/postgres ./dump
chown 999 ./data/postgres ./dump
chmod 700 ./data/postgres ./dump
''', root=True)
)
django = Container(
build=Buildah(
Packages('''
gettext shadow python3 py3-pip py3-psycopg2
uwsgi-python uwsgi-http uwsgi-spooler dumb-init bash
git curl
'''),
Copy('setup.py', 'src', '/app'),
Async(
Pip('/app[server]', 'djcli'),
Npm('install', 'build'),
),
User('app', '/app', getenv('_CONTAINERS_ROOTLESS_UID')),
Buildah.Env(**env),
Copy('uwsgi.ini', '/app/uwsgi.ini'),
Buildah.Config(
cmd='/usr/bin/dumb-init bash -xc \'%s\'' % ' && '.join([
'until djcli dbcheck; do sleep 1; done',
'ylserver migrate --noinput',
'uwsgi --ini /app/uwsgi.ini',
]),
port=8000,
workingdir='/app',
),
base='alpine:edge',
commit='docker://yourlab',
),
volumes={
getenv('HOME') + '/.ssh/authorized_keys': '/app/.ssh/authorized_keys',
}
)
postgres = Container(
image='docker.io/postgres',
env=env,
volumes={
'./data/postgres': '/var/lib/postgresql/data',
'./dump': '/dump',
},
)
pod = Pod(
django=django,
postgres=postgres,
)
env['POSTGRES_HOST'] = f'{pod.name}-postgres'
if __name__ == '__main__':
cli = Group(doc=__doc__)
cli.load(pod)
cli['postgres'] = Group('postgres').load(postgres)
cli['django'] = Group('django').load(django)
cli['install'] = Command(install)
cli.entry_point()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment