Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
basic config copied from eoa2-xmldb repo. ran 'django-admin startproj…
…ect'
  • Loading branch information
EsGeh authored and EsGeh committed Nov 11, 2019
0 parents commit 620e0e5
Show file tree
Hide file tree
Showing 21 changed files with 834 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
@@ -0,0 +1,3 @@
/runtime_data
/scripts
/env
109 changes: 109 additions & 0 deletions .gitignore
@@ -0,0 +1,109 @@

# manual entries:
/dependencies/
/runtime_data/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
17 changes: 17 additions & 0 deletions Dockerfile
@@ -0,0 +1,17 @@
FROM python:3

ENV PYTHONUNBUFFERED 1
ENV SHELL /bin/bash

# ------------------------------------------
# install necessary packages via apt-get:
# ------------------------------------------
# RUN apt-get update && \
# apt-get install -y --no-install-recommends \
# libsaxonhe-java

# ------------------------------------------
# install python dependencies:
# ------------------------------------------
COPY requirements.txt "$INSTALL_DIR/"
RUN pip install -r requirements.txt
34 changes: 34 additions & 0 deletions docker-compose.yaml
@@ -0,0 +1,34 @@
version: '3.7'

services:

db:
image: postgres:11
volumes:
- ./${DATABASE_DATA_DIR}:${DATABASE_DATA_DIR_IN_CONTAINER}
container_name: ${DB_CONTAINER}
user: ${USER}:${GROUP}
environment:
# postgres data dir
- PGDATA=${DATABASE_DATA_DIR_IN_CONTAINER}
# postgres user
- POSTGRES_USER=postgres

# eoa-django
webserver:
depends_on:
- db
build: .
image: ${WEB_SERVER_IMAGE}
container_name: ${WEB_SERVER_CONTAINER}
command: python3 manage.py runserver 0.0.0.0:8000
volumes:
- ./${SRC_DIR}:${SRC_DIR_IN_CONTAINER}
- ./${RES_DIR_RUNTIME}:${RES_DIR_IN_CONTAINER}
working_dir: ${SRC_DIR_IN_CONTAINER}
environment:
- INSTALL_DIR=${SRC_DIR_IN_CONTAINER}
- RES_DIR=${RES_DIR_IN_CONTAINER}
ports:
- "8000:8000"
user: ${USER}:${GROUP}
2 changes: 2 additions & 0 deletions requirements.txt
@@ -0,0 +1,2 @@
Django==2.2
psycopg2-binary
1 change: 1 addition & 0 deletions res/static
27 changes: 27 additions & 0 deletions scripts/config/env.conf
@@ -0,0 +1,27 @@
[config]

###################################################
# container names:
WEB_SERVER_CONTAINER=eoa_1_5_webserver
DB_CONTAINER=db
WEB_SERVER_IMAGE=eoa_1_5_webserver

###################################################
# volumes:

RUNTIME_DIR=runtime_data

DATABASE_DATA_DIR=${RUNTIME_DIR}/postgres_data
DATABASE_DATA_DIR_IN_CONTAINER=/eoa/postgres_data

SRC_DIR=src
SRC_DIR_IN_CONTAINER=/eoa/server

RES_DIR=res
RES_DIR_RUNTIME=${RUNTIME_DIR}/res.rt
RES_DIR_IN_CONTAINER=/eoa/res

###################################################
# user and group:
# USER=$(id -u)
# GROUP=$(id -g)
26 changes: 26 additions & 0 deletions scripts/config/load_env.fish
@@ -0,0 +1,26 @@
#!/bin/fish

if not set -q SCRIPT_DIR
echo "ERROR in (status -m): \$SCRIPT_DIR is undefined!"
exit 1
end
set BASE_DIR "$SCRIPT_DIR/.."

#######################################
# actual script
#######################################

set RUNTIME_DIR "runtime_data"

###################################################
# export all these variables, so
# they can be referenced in the docker-compose.yaml
###################################################

# convert bash syntax to fish syntax:
set commands (cat ./scripts/config/env.conf | grep -E --invert-match '^#|^[[:space:]]*$' | sed 's/^\(.*\)=\(.*\)/set -x \1 \2/' | sed 's/\$(/(/g')

for cmd in $commands
echo "cmd: $cmd"
eval "$cmd"
end
25 changes: 25 additions & 0 deletions scripts/config/load_env.sh
@@ -0,0 +1,25 @@
#!/bin/bash

if [[ "$SCRIPT_DIR" == "" ]]; then
echo "ERROR in ./scripts/config/load_env.sh: \$SCRIPT_DIR is undefined!"
exit 1
fi
BASE_DIR="$SCRIPT_DIR/.."

#######################################
# actual script
#######################################


# these are the default settings used by all scripts:

RUNTIME_DIR=runtime_data

###################################################
# export all these variables, so
# they can be referenced in the docker-compose.yaml
###################################################
set -a
source $SCRIPT_DIR/config/env.conf
set -a
# (stop exporting variables)
32 changes: 32 additions & 0 deletions scripts/exec_in_container.py
@@ -0,0 +1,32 @@
#!/usr/bin/env python3

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

from pathlib import Path
import os

if __name__ == '__main__':

from argparse import ArgumentParser

config = load_config()

parser = ArgumentParser(
description="open bash to the container, optionally exec CMD there"
)
parser.add_argument(
"CMD",
nargs='*',
)
args = parser.parse_args()

CMDS= \
(vars(args)['CMD'])

print( CMDS )

exec_in_container(
*CMDS,
env=config
)
42 changes: 42 additions & 0 deletions scripts/exit.py
@@ -0,0 +1,42 @@
#!/usr/bin/env python3

from utils.settings import BASE_DIR, load_config

from pathlib import Path
import shutil
import os

def rm_dirs( config ):
path = Path( BASE_DIR, config['RUNTIME_DIR'] )
print( "removing dir '{}'".format( path ) )
shutil.rmtree(
path,
ignore_errors=True
)
# os.system('rm -rf "{}"'.format( path ))

def rm_docker_env_file( config ):
path = Path(
BASE_DIR / ".env"
)
print( "removing '{}'".format( path ) )
path.unlink()


if __name__ == '__main__':

from argparse import ArgumentParser

config = load_config()

parser = ArgumentParser(
description="clean up the repository: remove xml database, remove sql database"
)
args = parser.parse_args()

from stop import stop

stop( config )

rm_dirs( config )
rm_docker_env_file( config )

0 comments on commit 620e0e5

Please sign in to comment.