From c1354b331c10a0151fa0fe51b573fa61860dce7f Mon Sep 17 00:00:00 2001 From: William Brown Date: Oct 22 2019 23:46:54 +0000 Subject: Ticket 3 - Docker support This adds an improved dockerfile and readme related to that topic. https://pagure.io/389-ds-portal/issue/3 Review by: mhonek (thanks!) --- diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9f01192 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +#!BuildTag: 389-ds-portal +FROM opensuse/leap:15.1 +MAINTAINER wbrown@suse.de + +EXPOSE 8080 + +RUN zypper ar http://download.opensuse.org/update/leap/15.1/oss/ u && \ + zypper ar http://download.opensuse.org/distribution/leap/15.1/repo/oss/ m && \ + zypper ar http://download.opensuse.org/repositories/network:ldap/openSUSE_Leap_15.1/ "network:ldap" && \ + zypper mr -p 97 "network:ldap" && \ + zypper --gpg-auto-import-keys ref + +RUN zypper in -y python3-Flask python3-cryptography python3-ldap python3-lib389 python3-pip python3-devel apache2 apache2-devel gcc && \ + pip3 install mod_wsgi + +ADD ./ /home/flask +WORKDIR /home/flask + +VOLUME /data + +# HEALTHCHECK + +# How do we avoid user/group? +CMD mod_wsgi-express start-server --user wwwrun --group wwwrun --port 8080 --url-alias /static /home/flask/static entry.wsgi + + diff --git a/README.md b/README.md index fc064e0..23e390c 100644 --- a/README.md +++ b/README.md @@ -48,11 +48,11 @@ You will need a working 389 instance. For the moment this must expose ldapi at: The easiest way to setup a 389 server to test with this is in a docker container: - docker run -v 389data:/data -i -t 389ds/dirsrv:latest + docker run --name=389-ds -v 389data:/data -i -t 389ds/dirsrv:latest You can then run this project in a container such as: - docker run -v 389data:/data -i -t opensuse/tumbleweed:latest /bin/sh + docker run --name=389-ds-portal -v 389data:/data -p 8080 -i -t opensuse/tumbleweed:latest /bin/sh To run this you will require python3, python3-Flask and temporarily python3-cryptography. @@ -68,3 +68,24 @@ Testing py.test ./test.py +Docker +------ + +To build the image run: + + docker build -t 389-ds-portal:devel . + +Then to run it with an instance: + + docker run --name=389-ds -v 389data:/data -i -t 389ds/dirsrv:latest + docker run --name=389-ds-portal -v 389data:/data -p 8080:8080 -i -t 389-ds-portal:devel + +You may need to add some users to the container such as: + + docker exec -i -t 389-ds /usr/sbin/dsconf localhost backend create --be-name userRoot --suffix dc=example,dc=com + docker exec -i -t 389-ds /usr/sbin/dsidm -b dc=example,dc=com localhost initialise + docker exec -i -t 389-ds /usr/sbin/dsidm -b dc=example,dc=com localhost user create --uid william --cn william --displayName william --uidNumber 1000 --gidNumber 1000 --homeDirectory /home/william + docker exec -i -t 389-ds /usr/sbin/dsidm -b dc=example,dc=com localhost account reset_password uid=william,ou=People,dc=example,dc=com + +Now you should be able to use the portal as a test. + diff --git a/entry.wsgi b/entry.wsgi new file mode 100644 index 0000000..465fe7e --- /dev/null +++ b/entry.wsgi @@ -0,0 +1 @@ +from server import app as application diff --git a/server.py b/server.py index e5c20bb..ff9bae8 100644 --- a/server.py +++ b/server.py @@ -17,6 +17,7 @@ app = Flask(__name__) # Set the secret key to some random bytes. Keep this really secret! app.secret_key = os.urandom(16) +# app.secret_key = b'\xb5\x97\x93~!t\x97\r\x1e\xfd\xea\xf8\xe9\xd5\x91\xb0' # url_for('static', filename='css/bootstrap.min.css') # url_for('static', filename='js/bootstrap.min.js')