diff --git a/Dockerfile b/Dockerfile index a7bf01657..29e61d091 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,9 +18,15 @@ RUN touch /root/.bowerrc \ && echo "{ \"allow_root\": true }" >> /root/.bowerrc \ && npm cache clean +RUN npm install -g bower + WORKDIR /sapl ADD . /sapl -RUN pip install -r requirements/dev-requirements.txt --upgrade setuptools --no-cache-dir \ -&& python3 manage.py bower install +RUN chmod +x ./start.sh + +# RUN pip install -r requirements/requirements.txt --upgrade setuptools --no-cache-dir + +VOLUME ["/sapl/data"] +ENTRYPOINT ["./start.sh"] diff --git a/config/env-sample b/config/env-sample new file mode 100644 index 000000000..c358f9017 --- /dev/null +++ b/config/env-sample @@ -0,0 +1,8 @@ +DATABASE_URL = postgresql://postgres:@sapldb:/sapl +KEY +DEBUG = False +EMAIL_USE_TLS = True +EMAIL_PORT = 587 +EMAIL_HOST = '' +EMAIL_HOST_USER = '' +EMAIL_HOST_PASSWORD = '' diff --git a/docker-env.sh b/docker-env.sh new file mode 100644 index 000000000..07528b0f1 --- /dev/null +++ b/docker-env.sh @@ -0,0 +1,6 @@ +#/bin/bash + +KEY=`python gen-key.py` +echo $KEY + +sed -e "s/SECRET_KEY = None/SECRET_KEY = $KEY/g" config/env-sample diff --git a/envfile b/envfile new file mode 100644 index 000000000..a7aef4b0f --- /dev/null +++ b/envfile @@ -0,0 +1 @@ +EMAIL_HOST_USER=foo diff --git a/gen-env.py b/gen-env.py new file mode 100644 index 000000000..70c8bb39a --- /dev/null +++ b/gen-env.py @@ -0,0 +1,43 @@ +import os +from genkey import generate_secret + +key = None +if os.path.exists('data/secret.key'): + with open('data/secret.key', 'r') as f: + key = f.read() +else: + with open('data/secret.key', 'w') as f: + key = generate_secret() + f.write("%s" % key) + +with open(".env", "w") as f: + + f.write("DATABASE_URL = postgresql://postgres:@localhost:/sapldb\n") + f.write("SECRET_KEY: %s\n" % key) + + # TODO use template and dict? + f.write("DEBUG=False\n") + + f.write("EMAIL_USE_TLS = True\n") + + f.write("EMAIL_PORT = 587\n") + EMAIL_PORT = os.environ['EMAIL_PORT'] if 'EMAIL_PORT' in os.environ else '' + f.write("EMAIL_PORT: %s\n" % EMAIL_PORT) + + EMAIL_HOST = os.environ['EMAIL_HOST'] if 'EMAIL_HOST' in os.environ else '' + f.write("EMAIL_HOST: %s\n" % EMAIL_HOST) + + EMAIL_HOST_USER = os.environ['EMAIL_HOST_USER'] if 'EMAIL_HOST_USER' in os.environ else '' + f.write("EMAIL_HOST_USER: %s\n" % EMAIL_HOST_USER) + + EMAIL_HOST_PASSWORD = os.environ['EMAIL_HOST_PASSWORD'] if 'EMAIL_HOST_PASSWORD' in os.environ else '' + f.write("EMAIL_HOST_PASSWORD: %s\n" % EMAIL_HOST_PASSWORD) + + +# SECRET_KEY=TravisTest +# DEBUG=False +# EMAIL_USE_TLS = True +# EMAIL_PORT = 587 +# EMAIL_HOST = '' +# EMAIL_HOST_USER = '' +# EMAIL_HOST_PASSWORD = '' diff --git a/genkey.py b/genkey.py new file mode 100644 index 000000000..85f399c54 --- /dev/null +++ b/genkey.py @@ -0,0 +1,7 @@ +import random + +def generate_secret(): + return ''.join([random.SystemRandom().choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)]) + +if __name__ == '__main__': + print(generate_secret()) diff --git a/start.sh b/start.sh new file mode 100644 index 000000000..43eee863f --- /dev/null +++ b/start.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +touch .env + +python3 gen-env.py + +/bin/sh + +# Generate .env em /sapl/data volume + + + diff --git a/teste.sh b/teste.sh new file mode 100644 index 000000000..cd8bff322 --- /dev/null +++ b/teste.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +if [ "$1" ] +then + ls "$1/sapl" +fi