From eff15418b63bd8611396d7f30d4c0569cd9ca56d Mon Sep 17 00:00:00 2001
From: Josh Santos <nerdsville@fedoraproject.org>
Date: Mar 05 2021 22:44:43 +0000
Subject: [PATCH 1/10] Make fedora_elections importable as a module


---

diff --git a/fedora_elections/__init__.py b/fedora_elections/__init__.py
index 2a34232..f2fb527 100644
--- a/fedora_elections/__init__.py
+++ b/fedora_elections/__init__.py
@@ -63,7 +63,7 @@ logging.basicConfig()
 logging.config.dictConfig(APP.config.get("LOGGING") or {"version": 1})
 LOG = APP.logger
 
-APP.wsgi_app = fedora_elections.proxy.ReverseProxied(APP.wsgi_app)
+APP.wsgi_app = proxy.ReverseProxied(APP.wsgi_app)
 
 if APP.config.get('FASJSON'):
     ACCOUNTS = Client(
diff --git a/files/fedora-elections.wsgi b/files/fedora-elections.wsgi
index 74ca155..1f80a71 100644
--- a/files/fedora-elections.wsgi
+++ b/files/fedora-elections.wsgi
@@ -16,4 +16,4 @@ sys.stdout = sys.stderr
 ## as a python module (for example if you run it from a git clone).
 #sys.path.insert(0, '/path/to/fedora_elections/')
 
-from fedora_elections import app as application
+from fedora_elections import APP as application

From 0166180e4f31286bb5ab6fb7225764398a8f190a Mon Sep 17 00:00:00 2001
From: Josh Santos <nerdsville@fedoraproject.org>
Date: Mar 05 2021 22:45:14 +0000
Subject: [PATCH 2/10] Remove comments from sample apache config, adding more variables


---

diff --git a/files/fedora-elections.conf b/files/fedora-elections.conf
index dc905fb..57f8549 100644
--- a/files/fedora-elections.conf
+++ b/files/fedora-elections.conf
@@ -2,26 +2,27 @@
 #
 # Adjust as needed, including replacing @DATADIR@ by what it should be
 
-#Alias /fedora-elections/images @DATADIR@/fedora_elections/images
-#Alias /fedora-elections/static @DATADIR@/fedora_elections/static
-#
-#WSGIDaemonProcess fedora-elections user=apache group=apache maximum-requests=1000 display-name=fedora-elections  processes=2 threads=1
-#WSGISocketPrefix run/wsgi
-#WSGIRestrictStdout On
-#WSGIRestrictSignal Off
-#WSGIPythonOptimize 1
-#
-#WSGIScriptAlias /voting @DATADIR@/fedora_elections/fedora-elections.wsgi
-#
-#<Location />
-#    WSGIProcessGroup fedora-elections
-#    <IfModule mod_authz_core.c>
-#        # Apache 2.4
-#        Require all granted
-#    </IfModule>
-#    <IfModule !mod_authz_core.c>
-#         # Apache 2.2
-#        Order deny,allow
-#        Allow from all
-#    </IfModule>
-#</Location>
+ServerName $SERVERNAME
+Alias /fedora-elections/static/images $DATADIR/fedora_elections/images
+Alias /fedora-elections/static $DATADIR/fedora_elections/static
+
+WSGIDaemonProcess fedora-elections user=apache group=apache maximum-requests=1000 display-name=fedora-elections  processes=2 threads=1
+WSGISocketPrefix run/wsgi
+WSGIRestrictStdout On
+WSGIRestrictSignal Off
+WSGIPythonOptimize 1
+
+WSGIScriptAlias /voting $DATADIR/fedora_elections/fedora-elections.wsgi
+
+<Location />
+    WSGIProcessGroup fedora-elections
+    <IfModule mod_authz_core.c>
+        # Apache 2.4
+        Require all granted
+    </IfModule>
+    <IfModule !mod_authz_core.c>
+         # Apache 2.2
+        Order deny,allow
+        Allow from all
+    </IfModule>
+</Location>

From 7ce32456dec2ba3f3097ad45bdbe365015b8c5f5 Mon Sep 17 00:00:00 2001
From: Josh Santos <nerdsville@fedoraproject.org>
Date: Mar 05 2021 22:45:31 +0000
Subject: [PATCH 3/10] Update prod dependency list


---

diff --git a/README.md b/README.md
index 35c96d4..3340e63 100644
--- a/README.md
+++ b/README.md
@@ -73,25 +73,26 @@ Before launching fedora-elections, the following packages should be installed:
 
 * `httpd`
 * `libxslt`
+* `mod-wsgi`
 * `python`
-* `python-backports-ssl_match_hostname`
-* `python-bunch`
+* `python-arrow`
 * `python-chardet`
+* `python-fasjson-client`
 * `python-fedora`
 * `python-fedora-flask`
+* `python-fedora-messaging`
 * `python-flask`
+* `python-flask-oidc`
 * `python-flask-sqlalchemy`
 * `python-flask-wtf`
 * `python-jinja2`
 * `python-kitchen`
 * `python-lxml`
 * `python-openid`
-* `python-ordereddict`
-* `python-ordereddict`
 * `python-setuptools`
 * `python-simplejson`
 * `python-six`
-* `python-sqlalchemy0.7`
+* `python-sqlalchemy`
 * `python-urllib3`
 * `python-wtforms`
 

From f6711149f4aa7bd77a8c087c9194e6b76cbfe844 Mon Sep 17 00:00:00 2001
From: Josh Santos <nerdsville@fedoraproject.org>
Date: Mar 05 2021 22:45:42 +0000
Subject: [PATCH 4/10] Add prod dockerfile


---

diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..47a4108
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,57 @@
+FROM fedora:latest
+
+ENV ENV production
+ENV DATADIR /opt/elections/data
+ENV SERVERNAME fedora-elections
+
+RUN dnf -y update && \
+    dnf -y install gettext\
+        httpd \
+        libxslt \
+        mod_wsgi \
+        python \
+        python-arrow \
+        python-chardet \
+        python-fasjson-client \
+        python-fedora \
+        python-fedora-flask \
+        python-fedora-messaging \
+        python-flask \
+        python-flask-oidc \
+        python-flask-sqlalchemy \
+        python-flask-wtf \
+        python-jinja2 \
+        python-kitchen \
+        python-lxml \
+        python-openid \
+        python-setuptools \
+        python-simplejson \
+        python-six \
+        python-sqlalchemy \
+        python-urllib3 \
+        python-wtforms && \
+    mkdir /etc/fedora-elections && \
+    mkdir -p /opt/elections/data/fedora_elections && \
+    pip install fedora_elections_messages
+
+COPY files/fedora-elections.conf /etc/httpd/conf.d/fedora-elections.conf.sample
+
+# Replace env vars in apache config
+RUN cat /etc/httpd/conf.d/fedora-elections.conf.sample | \
+    envsubst > /etc/httpd/conf.d/fedora-elections.conf
+
+COPY files/fedora-elections.wsgi ${DATADIR}/fedora_elections
+COPY files/fedora-elections.cfg /etc/fedora-elections
+COPY fedora_elections/static ${DATADIR}/static
+
+WORKDIR /opt/elections
+
+COPY docker-entrypoint.sh /usr/local/bin/
+COPY . .
+
+RUN pip install .
+
+EXPOSE 80
+
+ENTRYPOINT [ "docker-entrypoint.sh" ]
+CMD [ "httpd", "-D", "FOREGROUND" ]
\ No newline at end of file

From 906eea489a11917f08108bd07ffeaf29c2a558ad Mon Sep 17 00:00:00 2001
From: Josh Santos <nerdsville@fedoraproject.org>
Date: Mar 05 2021 22:59:32 +0000
Subject: [PATCH 5/10] Add initial entrypoint


---

diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh
new file mode 100755
index 0000000..7ade262
--- /dev/null
+++ b/docker-entrypoint.sh
@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+
+if [ ! "$ENV" = "development" ]; then
+    echo "Nothing to do here; continuing..."
+    exec "$@"
+fi
+
+if [ ! -f client_secrets.json ]; then
+    oidc-register https://iddev.fedorainfracloud.org/ http://localhost:5005
+fi
+
+if [ ! -f /var/tmp/elections_dev.sqlite ]; then
+    python createdb.py
+fi
+
+exec "$@"
\ No newline at end of file

From 8d776e80cc590579d8cfd440e55426a59ed7a12f Mon Sep 17 00:00:00 2001
From: Josh Santos <nerdsville@fedoraproject.org>
Date: Mar 05 2021 23:01:09 +0000
Subject: [PATCH 6/10] Add command to createdb


---

diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh
index 7ade262..2b774ce 100755
--- a/docker-entrypoint.sh
+++ b/docker-entrypoint.sh
@@ -1,7 +1,8 @@
 #!/usr/bin/env bash
 
+python createdb.py
+
 if [ ! "$ENV" = "development" ]; then
-    echo "Nothing to do here; continuing..."
     exec "$@"
 fi
 
@@ -9,8 +10,4 @@ if [ ! -f client_secrets.json ]; then
     oidc-register https://iddev.fedorainfracloud.org/ http://localhost:5005
 fi
 
-if [ ! -f /var/tmp/elections_dev.sqlite ]; then
-    python createdb.py
-fi
-
 exec "$@"
\ No newline at end of file

From 73159543f366ee0df06cb337bfd14de19d7f3d77 Mon Sep 17 00:00:00 2001
From: Josh Santos <nerdsville@fedoraproject.org>
Date: Mar 06 2021 01:10:26 +0000
Subject: [PATCH 7/10] Add dev dockerfile and docker-compose


---

diff --git a/Dockerfile b/Dockerfile
index 47a4108..70bcbce 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -54,4 +54,4 @@ RUN pip install .
 EXPOSE 80
 
 ENTRYPOINT [ "docker-entrypoint.sh" ]
-CMD [ "httpd", "-D", "FOREGROUND" ]
\ No newline at end of file
+CMD [ "httpd", "-D", "FOREGROUND" ]
diff --git a/dev.Dockerfile b/dev.Dockerfile
new file mode 100644
index 0000000..4862885
--- /dev/null
+++ b/dev.Dockerfile
@@ -0,0 +1,38 @@
+FROM fedora:latest
+
+# USERNAME == GROUP for now
+ARG USERNAME=dev
+ARG USER_UID=1000
+ARG USER_GID=$USER_UID
+
+RUN groupadd -g ${USER_GID} ${USERNAME} && \
+    useradd -u ${USER_UID} -g ${USERNAME} ${USERNAME}
+
+ENV ENV development
+ENV BASE_DIR /opt/dev
+ENV APP_DIR ${BASE_DIR}/elections
+
+RUN dnf -y update && \
+    dnf -y install python \
+        python-devel \
+        git \
+        krb5-devel \
+        open-sans-fonts \
+        gcc \
+        python-devel \
+        python3.6 \
+        python3.7 \
+        python3.8 \
+        tox
+
+COPY docker-entrypoint.sh /usr/local/bin
+
+USER dev
+WORKDIR ${APP_DIR}
+
+COPY . .
+RUN pip install --user -r requirements.txt
+
+ENTRYPOINT ["docker-entrypoint.sh"]
+
+CMD [ "python", "runserver.py", "--host", "0.0.0.0" ]
diff --git a/docker-compose.development.yml b/docker-compose.development.yml
new file mode 100644
index 0000000..539a01a
--- /dev/null
+++ b/docker-compose.development.yml
@@ -0,0 +1,9 @@
+version: '3'
+services:
+  app:
+    build: .
+    dockerfile: dev.Dockerfile
+    ports:
+      - 5005:5005
+    volumes:
+      - .:/opt/dev/elections
diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh
index 2b774ce..ff144ea 100755
--- a/docker-entrypoint.sh
+++ b/docker-entrypoint.sh
@@ -3,11 +3,18 @@
 python createdb.py
 
 if [ ! "$ENV" = "development" ]; then
-    exec "$@"
+	exec "$@"
 fi
 
 if [ ! -f client_secrets.json ]; then
-    oidc-register https://iddev.fedorainfracloud.org/ http://localhost:5005
+	oidc-register https://iddev.fedorainfracloud.org/ http://localhost:5005
 fi
 
-exec "$@"
\ No newline at end of file
+if [ ! -f config ]; then
+	cat > config <<-EOL
+	OIDC_ID_TOKEN_COOKIE_SECURE = False
+	OIDC_REQUIRE_VERIFIED_EMAIL = False 
+	EOL
+fi
+
+exec "$@"

From 767a9984d38b06b1998bd9b0ea68c975b6d8b003 Mon Sep 17 00:00:00 2001
From: Josh Santos <nerdsville@fedoraproject.org>
Date: Mar 06 2021 01:14:03 +0000
Subject: [PATCH 8/10] Let group stand alone


---

diff --git a/dev.Dockerfile b/dev.Dockerfile
index 4862885..922353d 100644
--- a/dev.Dockerfile
+++ b/dev.Dockerfile
@@ -1,12 +1,12 @@
 FROM fedora:latest
 
-# USERNAME == GROUP for now
 ARG USERNAME=dev
+ARG GROUP=dev
 ARG USER_UID=1000
-ARG USER_GID=$USER_UID
+ARG USER_GID=1000
 
-RUN groupadd -g ${USER_GID} ${USERNAME} && \
-    useradd -u ${USER_UID} -g ${USERNAME} ${USERNAME}
+RUN groupadd -g ${USER_GID} ${GROUP} && \
+    useradd -u ${USER_UID} -g ${GROUP} ${USERNAME}
 
 ENV ENV development
 ENV BASE_DIR /opt/dev

From bf8ad3ec435abca94967002c6d3c68f8e23a6e08 Mon Sep 17 00:00:00 2001
From: Josh Santos <nerdsville@fedoraproject.org>
Date: Mar 06 2021 01:17:16 +0000
Subject: [PATCH 9/10] Rename development docker-compose


---

diff --git a/development.docker-compose.yml b/development.docker-compose.yml
new file mode 100644
index 0000000..539a01a
--- /dev/null
+++ b/development.docker-compose.yml
@@ -0,0 +1,9 @@
+version: '3'
+services:
+  app:
+    build: .
+    dockerfile: dev.Dockerfile
+    ports:
+      - 5005:5005
+    volumes:
+      - .:/opt/dev/elections
diff --git a/docker-compose.development.yml b/docker-compose.development.yml
deleted file mode 100644
index 539a01a..0000000
--- a/docker-compose.development.yml
+++ /dev/null
@@ -1,9 +0,0 @@
-version: '3'
-services:
-  app:
-    build: .
-    dockerfile: dev.Dockerfile
-    ports:
-      - 5005:5005
-    volumes:
-      - .:/opt/dev/elections

From 6ba77699ed9df5c722a44bbcfe220f66e4bd9fdb Mon Sep 17 00:00:00 2001
From: Josh Santos <nerdsville@fedoraproject.org>
Date: Mar 06 2021 01:17:57 +0000
Subject: [PATCH 10/10] Add production docker-compose


---

diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..318d3f4
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,6 @@
+version: '3'
+services:
+  app:
+    build: .
+    ports:
+      - 5005:5005

