Skip to content

Commit 8355eeb

Browse files
authored
Fixes 1574785232 (#638)
* switched to using official postgres docker image with postgis installed * add make target for building docker images * README update
1 parent e0f5daf commit 8355eeb

File tree

6 files changed

+55
-109
lines changed

6 files changed

+55
-109
lines changed

.dockerignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
.Python
55
.tx/
66
.vscode/
7-
*.ini
7+
settings.ini
88
*.sublime-project
99
*.sublime-workspace
1010
**/.DS_Store
@@ -24,4 +24,4 @@ messages.mo
2424
share/
2525
src/
2626
uploads/
27-
node_modules/
27+
node_modules/

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ po2json:
2121
./convert-po2json
2222
version:
2323
./update_version.sh
24+
docker: version
25+
docker-compose build

README.md

+46-20
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
### Introduction
2323

24-
This document details the steps required in deploying a fully functional installment of Apollo 3. Apollo is a data management platform to support citizen election observation and other large-scale structured data collection efforts. Developed by Tim Akinbo and his team at TimbaObjects in conjunction with NDI’s Elections team, Apollo aids the management of observers, verification of collected information, and automated aggregation for analysis. Citizen watchdogs play a critical role in validating political processes, but to be convincing must back claims with data. Elections are one of the foundations of legitimate democracy when the official results truly represent the will of the voters. Systematic election observation requires large amounts of structured information from hundreds or thousands of observers and determining what it means – fast. Apollo aids the management of observers, verification of collected information, and automated aggregation for analysis.
24+
This document details the steps required in deploying a fully functional installation of Apollo 3. Apollo is a data management platform to support citizen election observation and other large-scale structured data collection efforts. Developed by Tim Akinbo and his team at TimbaObjects in conjunction with NDI’s Elections team, Apollo aids the management of observers, verification of collected information, and automated aggregation for analysis. Citizen watchdogs play a critical role in validating political processes, but to be convincing must back claims with data. Elections are one of the foundations of legitimate democracy when the official results truly represent the will of the voters. Systematic election observation requires large amounts of structured information from hundreds or thousands of observers and determining what it means – fast. Apollo aids the management of observers, verification of collected information, and automated aggregation for analysis.
2525

2626

2727
### Install
@@ -42,8 +42,6 @@ After installing git, you will be able to clone the current version of Apollo fr
4242
git clone https://github.com/nditech/dev-elections.git
4343
```
4444

45-
Due to the fact this repository is private, to clone this repository to a regular server you will need to upload a deployment SSH to this repository [here](https://github.com/nditech/dev-elections/settings/keys), or use an authenticated URL (if you have an account on GitHub that has access to the repository).
46-
4745
After downloading, configure a settings file in the main folder called `settings.ini`. A basic sample settings file is shown below. The install will not work if a settings file is not created with a Secret Key specified. The secret key should be any randomly generated string of characters of similar length to the example provided. For more information on additional configuration settings, read the section "[Application Configuration Settings](#application-configuration-settings)" below.
4846

4947
```
@@ -58,9 +56,9 @@ In order to simplify the deployment process, Apollo now includes a docker compos
5856

5957
To build and start the application, simply run:
6058

61-
`docker-compose up -d`
59+
`make docker`
6260

63-
The main application container and worker containers will be built and run together with the supporting database and task queue containers. After running the command initially, subsequent builds will use cached container images. To deploy the code from scratch without drawing upon the cached images (for example to incorporate subsequent any changes made to the Apollo code outside of the docker containers), run `docker run build --no-cache`.
61+
The main application container and worker containers will be built and run together with the supporting database and task queue containers. After running the command initially, subsequent builds will use cached container images. To deploy the code from scratch without drawing upon the cached images (for example to incorporate subsequent any changes made to the Apollo code outside of the docker containers), run `docker-compose build --no-cache`.
6462

6563

6664

@@ -112,25 +110,25 @@ You should now be able to login to your site by navigating to port `:5000` on yo
112110

113111
Each deployment installation can be further customized by modifying the contents of the `settings.ini` file. Here are a collection of settings parameters and sample values together with an explanation of what they do.
114112

115-
SECRET_KEY
113+
**SECRET_KEY**
116114
(e.g. LBZyd8EY80mALqb7bl8o3da8)
117115

118116
The secret key contains a random string of characters, numbers and symbols and is used internally for signing and encrypting cookies and other security-related tokens. Best security practice requires that you set the value to a random value before starting the containers. Note that if this value is changed after the application is already fully configured, then user logins will stop working as the application would not be able to decrypt stored passwords. So this should remain the same throughout the lifetime of the application. This is a compulsory configuration option.
119117

120118

121-
SSL_REQUIRED
119+
**SSL_REQUIRED**
122120
(e.g. False)
123121

124122
This parameter determines whether the application server will explicitly check if all requests are being served over a secure (https) connection. By setting this value to True, you effectively turn this check on and all connections must be secure before access is granted.
125123

126124

127-
TIMEZONE
125+
**TIMEZONE**
128126
(e.g. Africa/Lagos)
129127

130128
The timezone parameter configures the timezone that the application server uses by default. Usually this is set to the timezone of the country for which the application instance is deployed. For a full list of support timezone values, please visit this wikipedia article.
131129

132130

133-
GOOGLE_TAG_MANAGER
131+
**GOOGLE_TAG_MANAGER**
134132
(e.g. GTM-1234567)
135133

136134

@@ -141,57 +139,85 @@ If you need to manage tags that are inserted into the application, one way to do
141139
More information on using Google Tag Manager can be found [here](https://marketingplatform.google.com/about/tag-manager/), and [here](https://developers.google.com/tag-manager/).
142140

143141

144-
REDIS_DATABASE
142+
**REDIS_DATABASE**
145143
(e.g. 0)
146144

147145
This value determines the redis database that is used by the application. It takes the default value of 0 but (in the unlikely event that you need to share a redis installation) it can be changed to a different value. By default most redis installations have a maximum value of 15.
148146

149147

150-
REDIS_HOSTNAME
148+
**REDIS_HOSTNAME**
151149
(e.g. redis)
152150

153151
As was described above, if you require connecting to an external redis server, you can specify the value of the hostname for this redis database here.
154152

155153

156-
DATABASE_HOSTNAME
154+
**DATABASE_HOSTNAME**
157155
(e.g. postgres)
158156

159157
As was the case in REDIS_HOSTNAME, there might be cases where an external PostgreSQL database is to be used, setting the DATABASE_HOSTNAME allows the application and worker applications to connect to this.
160158

161159

162-
DATABASE_NAME
160+
**DATABASE_NAME**
163161
(e.g. apollo)
164162

165163
If you need to use the non-default database name for the installation, you can change the value here. Please note that if you are using an external PostgreSQL server, you may not need to create and link to the postgres container; in which case, simply providing the DATABASE_HOSTNAME and the DATABASE_NAME will be sufficient for the application containers to connect to the provided database.
166164

167165
You would also need to drop the DATABASE_NAME environment specification (-e DATABASE_NAME=...) when creating the application containers.
168166

169167

170-
DEBUG
168+
**DEBUG**
171169
(e.g. False)
172170

173171
Debug information is usually only used when the application is being built or when an issue is being debugged. The default value of False is sufficient and should only be changed to True if there’s the need to debug the application. Setting DEBUG to True may reveal sensitive information to the user and should only be used when actual debugging is being done and reverted to the default value when debugging is over.
174172

175-
MAIL_SERVER
173+
**MAIL_SERVER**
176174
(e.g. smtp.sendgrid.net)
177-
MAIL_PORT
175+
**MAIL_PORT**
178176
(e.g. 587)
179-
MAIL_USE_TLS
177+
**MAIL_USE_TLS**
180178
(e.g. True)
181-
MAIL_USERNAME
179+
**MAIL_USERNAME**
182180
(e.g. sendgrid-username)
183-
MAIL_PASSWORD
181+
**MAIL_PASSWORD**
184182
(e.g sendgrid-apikey)
185183

186184
These set of configuration values allow the administrator to configure a mail server for the purpose of being able to send out transactional emails like password resets, notices on task completion, etc. It is highly recommended that these values are configured.
187185

188186

189-
PROMETHEUS_SECRET
187+
**PROMETHEUS_SECRET**
190188
(e.g. pmsecretz)
191189

192190
Apollo 3 provides support for an external monitoring server (Prometheus) to be able to obtain application performance metrics. In order to randomize the URL from which the stats are retrieved from, the PROMETHEUS_SECRET is added as an additional URL fragment and must be correct for the metrics to be provided. The metrics url becomes https://apollo3servername/metrics/{PROMETHEUS_SECRET}.
193191

194192

193+
**MAPBOX_TOKEN**
194+
(e.g. pk.eyJ1I.BOh_5nWoa-sWP)
195+
196+
If you would rather have the better looking MapBox base tiles for the maps, you should add your MapBox API token as a parameter to the settings file.
197+
198+
199+
**ENABLE_SOCIAL_LOGIN**
200+
(e.g. True)
201+
202+
If you would like to offer the option to login with either a Facebook or Google account, you should enable the social login plugin by setting this parameter to True.
203+
204+
**GOOGLE_CLIENT_ID**
205+
**GOOGLE_CLIENT_SECRET**
206+
207+
To enable Google authentication, you'll need to create credentials for the Apollo application in your Google account (https://console.developers.google.com/apis/credentials). Copy the client id and secret and set them to the `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET` respectively.
208+
209+
**FACEBOOK_CLIENT_ID**
210+
**FACEBOOK_CLIENT_SECRET**
211+
212+
Similarly, to enable Facebook login, you'll need to obtain Facebook Login (https://developers.facebook.com/docs/facebook-login) credentials to use with Apollo. After setting the appropriate parameters, login with Facebook will be enabled.
213+
214+
215+
**API_KEY**
216+
(e.g. 3a;lk9243)
217+
218+
The `API_KEY` setting enables external API access to the artefacts exposed by Apollo. This parameter specifies the key that must accompany every API request to enable access.
219+
220+
195221
### Legacy Installation Method
196222

197223
An older installation method is documented below. In almost all cases, using docker compose is preferable. However if for some reason this is not possible, use the method below instead in place of the section above labeled *Installation and Deployment*.

postgis/Dockerfile

+2-56
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,6 @@
1-
FROM postgres:10-alpine
1+
FROM postgres:12
22
MAINTAINER Tim Akinbo <[email protected]>
33

4-
ENV POSTGIS_VERSION 2.5.2
5-
ENV POSTGIS_SHA256 225aeaece00a1a6a9af15526af81bef2af27f4c198de820af1367a792ee1d1a9
6-
7-
RUN set -ex \
8-
\
9-
&& apk add --no-cache --virtual .fetch-deps \
10-
ca-certificates \
11-
openssl \
12-
tar \
13-
\
14-
&& wget -O postgis.tar.gz "https://github.com/postgis/postgis/archive/$POSTGIS_VERSION.tar.gz" \
15-
&& echo "$POSTGIS_SHA256 *postgis.tar.gz" | sha256sum -c - \
16-
&& mkdir -p /usr/src/postgis \
17-
&& tar \
18-
--extract \
19-
--file postgis.tar.gz \
20-
--directory /usr/src/postgis \
21-
--strip-components 1 \
22-
&& rm postgis.tar.gz \
23-
\
24-
&& apk add --no-cache --virtual .build-deps \
25-
autoconf \
26-
automake \
27-
g++ \
28-
json-c-dev \
29-
libtool \
30-
libxml2-dev \
31-
make \
32-
perl \
33-
\
34-
&& apk add --no-cache --virtual .build-deps-edge \
35-
--repository http://dl-cdn.alpinelinux.org/alpine/edge/testing \
36-
--repository http://dl-cdn.alpinelinux.org/alpine/edge/main \
37-
gdal-dev \
38-
geos-dev \
39-
proj-dev \
40-
protobuf-c-dev \
41-
&& cd /usr/src/postgis \
42-
&& ./autogen.sh \
43-
&& ./configure \
44-
&& make \
45-
&& make install \
46-
&& apk add --no-cache --virtual .postgis-rundeps \
47-
json-c \
48-
&& apk add --no-cache --virtual .postgis-rundeps-edge \
49-
--repository http://dl-cdn.alpinelinux.org/alpine/edge/testing \
50-
--repository http://dl-cdn.alpinelinux.org/alpine/edge/main \
51-
geos \
52-
gdal \
53-
proj \
54-
protobuf-c \
55-
&& cd / \
56-
&& rm -rf /usr/src/postgis \
57-
&& apk del .fetch-deps .build-deps .build-deps-edge
4+
RUN apt update && apt install -y postgis
585

596
COPY ./initdb-postgis.sh /docker-entrypoint-initdb.d/postgis.sh
60-
COPY ./update-postgis.sh /usr/local/bin

postgis/initdb-postgis.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
set -e
44

55
# Perform all actions as $POSTGRES_USER
66
export PGUSER="$POSTGRES_USER"
77

88
# Create the 'template_postgis' template db
9-
"${psql[@]}" <<- 'EOSQL'
9+
psql <<- 'EOSQL'
1010
CREATE DATABASE template_postgis;
1111
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template_postgis';
1212
EOSQL
1313

1414
# Load PostGIS into both template_database and $POSTGRES_DB
1515
for DB in template_postgis "$POSTGRES_DB"; do
1616
echo "Loading PostGIS extensions into $DB"
17-
"${psql[@]}" --dbname="$DB" <<-'EOSQL'
17+
psql --dbname="$DB" <<-'EOSQL'
1818
CREATE EXTENSION IF NOT EXISTS postgis;
1919
CREATE EXTENSION IF NOT EXISTS postgis_topology;
2020
CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;

postgis/update-postgis.sh

-28
This file was deleted.

0 commit comments

Comments
 (0)