Skip to content

Commit

Permalink
added README, improved scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
EsGeh authored and EsGeh committed Nov 12, 2019
1 parent 620e0e5 commit 2f7cb9b
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 21 deletions.
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Edition Open Access 1.5

Source code for the Edition Open Access website.
Publications are provided in a number of different formats:

- online HTML version
- PDF
- Ebook (EPUB)

# Installation

In order to provide a consistent environment we are using docker.
A set of python scripts is used for automatisation.
Installing and running the project work without Docker or the scripts is possible, but not recommended. In this case you are on your own.
A bunch of other repositories are needed in order to run this project.
They are automatically pulled by the init script.

## Configuration

- Environment variables: see file `.env`

These variables are available inside the `docker-compose.yaml` file and are also loaded into the python scripts.
The file is created/overwritten with default settings by the `init.py` script.

- Django settings: see `src/eoa/settings.py`

For further information please check the django documentation.

## Prerequisites

- Python 3
- Docker, Docker Compose

## Initialise the Repository

$ ./scripts/init.py [--build]

This will pull remote repositories and resources, initialize the database, etc.
Force recreating the docker image by adding `--build` e.g. if `Dockerfile` or `requirements.txt` has changed.

## Import Publications, Initialize CMS pages (TODO)

Not yet documented.

## Run the Webserver

$ ./scripts/run.py

The webpage can now be explored in your local browser.

## Stop the Webserver

$ ./scripts/stop.py

## Run Command in the Webserver container

$ ./scripts/exec_in_container.py [-- CMD ...]

## Clean the Repository

$ ./scripts/exit.py

This should remove all remote repositories and resources not part of this repository.
Docker images are not deleted though.

# Installation for Production (TODO)

Not documented yet.
It might be necessary to tweak the django settings, among other adjustments.
17 changes: 14 additions & 3 deletions scripts/init.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

from utils.settings import BASE_DIR, load_config, create_docker_env_file
from utils.functions import exec_in_container
from utils.functions import exec_in_container, run

from pathlib import Path
import shlex
Expand Down Expand Up @@ -115,9 +115,13 @@ def init_sqldb( config ):
from argparse import ArgumentParser

parser = ArgumentParser(
description="initialize the repository: create directories, initialize xml database, initialize sql database"
description="initialize the repository: download git deps, create directories, initialize xml database, initialize sql database"
)
parser.parse_args()
parser.add_argument(
"--build",
action = "store_true"
)
args = parser.parse_args()

# orig_config_file -> env_file:
create_docker_env_file()
Expand All @@ -144,4 +148,11 @@ def init_sqldb( config ):

create_dirs( config )

# rebuild docker image:
if args.build:
run(
env = config,
build = True,
)

init_sqldb( config )
24 changes: 6 additions & 18 deletions scripts/run.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,13 @@
#!/usr/bin/env python3

from utils.settings import BASE_DIR, load_config
# from utils.functions import exec_in_xmldb
from utils.functions import run

import subprocess
import shlex
import os
from time import sleep

def run(
env,
cmd=[]
):
if len(cmd) > 0:
# run application
subprocess.call(
shlex.split("docker-compose run webserver") + cmd,
env=env
)
else:
# run application
subprocess.call(
shlex.split("docker-compose up -d"),
env=env
)

if __name__ == '__main__':

from argparse import ArgumentParser
Expand All @@ -34,6 +17,10 @@ def run(
parser = ArgumentParser(
description="run the webserver"
)
parser.add_argument(
"--build",
action = "store_true"
)
parser.add_argument(
"CMD",
nargs="*"
Expand All @@ -45,5 +32,6 @@ def run(
(vars(args)['CMD'])
run(
env=config,
build = args.build,
cmd=CMD
)
18 changes: 18 additions & 0 deletions scripts/utils/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@
import shlex


def run(
env,
build=False,
cmd=[]
):
if len(cmd) > 0:
# run application
subprocess.call(
shlex.split("docker-compose run webserver") + cmd,
env=env
)
else:
# run application
subprocess.call(
shlex.split("docker-compose up -d") + (["--build"] if build else []),
env=env
)

def exec_in_container(
*args,
env
Expand Down

0 comments on commit 2f7cb9b

Please sign in to comment.