Skip to content
Snippets Groups Projects
Commit e05919c1 authored by robinwilliam.hundt's avatar robinwilliam.hundt
Browse files

First version of script

parent afe06d86
No related branches found
No related tags found
No related merge requests found
# grady-docker-helper # Grady Docker Helper
A small script to help with the creation of a new Grady instance. A small script to help with the creation of a new Grady instance.
\ No newline at end of file
## Usage
Display help:
```
python3 create-instance.py -h
```
Create a new instance folder with all necessary files:
```
python3 create-instance.py sose 18 ckurs lecturer 1.0.0 ..
```
The last argument is the path at which the folder is created, default: ..
import argparse
import os
import shutil
CWD = os.getcwd()
DEFAULT_FOLDER_PATH = os.path.join(CWD, '..')
SRC_DIR = os.path.dirname(__file__)
DOCKER_COMPOSE_PATH = os.path.join(SRC_DIR, 'example.docker-compose.yml')
def main():
parser = argparse.ArgumentParser(
description='Create the necessary files for a new grady instance',
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument('semester', help="Is this 'sose' or 'wise' ?")
parser.add_argument('year', help="Year of the semester in the format '18' or '1819' for a sose")
parser.add_argument('course', help="E.g. 'ckurs', 'cs1' or 'cs2'")
parser.add_argument('lecturer', help="The lecturer of the course")
parser.add_argument('version', help="Grady version that is deployed")
parser.add_argument(
'path',
default=DEFAULT_FOLDER_PATH,
nargs='?',
help="Path where the instance folder is created. "
"Folder name is autogenerated and should not be part of the path"
)
args = parser.parse_args()
create_instance(args)
def create_instance(args):
instance_folder = create_folder(args)
shutil.copy2(DOCKER_COMPOSE_PATH, os.path.join(instance_folder, 'docker-compose.yml'))
with open(os.path.join(instance_folder, 'secret'), 'x'):
pass
create_env_file(args, instance_folder)
print("Created instance at: {}\n"
"Run 'docker-compose pull' and 'docker-compose up' to start the instance".format(instance_folder))
def create_folder(args):
folder_name = "{}_{}_{}_{}".format(args.semester, args.year, args.course, args.lecturer)
folder_name = os.path.join(args.path, folder_name)
try:
os.mkdir(folder_name)
except OSError:
print("The folder {} already exists. Please enter different parameters".format(folder_name))
exit(1)
return folder_name
def create_env_file(args, instance_folder):
env_template = "INSTANCE={}\n" \
"URLPATH={}\n" \
"VERSION={}\n"
urlpath = "/{}/{}{}".format(args.course, args.semester, args.year)
env_content = env_template.format(os.path.basename(instance_folder), urlpath, args.version)
with open(os.path.join(instance_folder, '.env'), 'x') as env_file:
env_file.write(env_content)
if __name__ == '__main__':
main()
version: "3"
services:
postgres:
image: postgres:9.6
restart: always
labels:
traefik.enable: "false"
networks:
- internal
volumes:
- ./database:/var/lib/postgresql/data
grady:
image: docker.gitlab.gwdg.de/j.michal/grady:${VERSION}
restart: always
entrypoint:
- ./deploy.sh
volumes:
- ./secret:/code/secret
environment:
GRADY_INSTANCE: ${INSTANCE}
SCRIPT_NAME: ${URLPATH}
networks:
- internal
- proxy
labels:
traefik.backend: ${INSTANCE}
traefik.enable: "true"
traefik.frontend.rule: Host:grady.informatik.uni-goettingen.de;PathPrefix:${URLPATH}
traefik.docker.network: proxy
traefik.port: "8000"
depends_on:
- postgres
networks:
proxy:
external: true
internal:
external: false
# This is an example .env file which is not use for the instance generation
INSTANCE=sose_18_ckurs_brosenne
URLPATH=/ckurs/sose18
VERSION=1.0.0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment