Skip to content

Commit 3bc7df1

Browse files
authored
Update confd with env vars and secrets (#3)
* also add shellcheck to linter
1 parent 7ca795f commit 3bc7df1

File tree

6 files changed

+65
-51
lines changed

6 files changed

+65
-51
lines changed

.github/workflows/lint-test-build-push.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
steps:
1212
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
1313

14-
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
15-
1614
- uses: hadolint/hadolint-action@54c9adbab1582c2ef04b2016b760714a4bfde3cf # v3.1.0
1715

16+
- run: shellcheck **/*.sh
17+
1818
build-push:
1919
needs: [lint-test]
2020
uses: libops/.github/.github/workflows/build-push-ghcr.yaml@main

Dockerfile

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,27 @@ EXPOSE 80
77
WORKDIR /var/www/ojs
88

99
ARG \
10+
# renovate: datasource=repology depName=alpine_3_22/antiword
11+
ANTIWORD_VERSION=0.37-r6 \
12+
# renovate: datasource=repology depName=alpine_3_22/ghostscript
13+
GHOSTSCRIPT_VERSION=10.05.1-r0 \
1014
# renovate: datasource=repology depName=alpine_3_22/npm
1115
NPM_VERSION=11.3.0-r1 \
1216
# renovate: datasource=github-tags depName=ojs packageName=pkp/ojs
1317
OJS_VERSION=3_5_0-1 \
1418
# renovate: datasource=repology depName=alpine_3_22/php83
15-
PHP_VERSION=8.3.26-r0
19+
PHP_VERSION=8.3.26-r0 \
20+
# renovate: datasource=repology depName=alpine_3_22/poppler-utils
21+
POPPLER_VERSION=25.04.0-r0
1622

1723
RUN apk add --no-cache \
24+
antiword=="${ANTIWORD_VERSION}" \
25+
ghostscript=="${GHOSTSCRIPT_VERSION}" \
1826
npm=="${NPM_VERSION}" \
1927
php83-bcmath=="${PHP_VERSION}" \
2028
php83-ftp=="${PHP_VERSION}" \
2129
php83-gettext=="${PHP_VERSION}" \
30+
poppler-utils=="${POPPLER_VERSION}" \
2231
&& cleanup.sh
2332

2433
RUN git clone https://github.com/pkp/ojs.git . \
@@ -42,13 +51,15 @@ RUN npm install \
4251
RUN chown -R nginx:nginx /var/www/ojs
4352

4453
ENV \
45-
OJS_DB_HOST=mariadb \
46-
OJS_DB_PORT=3306 \
47-
OJS_DB_NAME=ojs \
48-
OJS_DB_USER=changeme \
49-
OJS_DB_PASSWORD=changeme \
54+
DB_HOST=mariadb \
55+
DB_PORT=3306 \
56+
DB_NAME=ojs \
57+
DB_USER=ojs \
58+
DB_PASSWORD=changeme \
5059
OJS_SALT=changeme \
5160
OJS_API_KEY_SECRET=changeme \
61+
OJS_SECRET_KEY=changeme \
62+
OJS_BASE_URL=http://localhost \
5263
OJS_ADMIN_USERNAME=admin \
5364
OJS_ADMIN_EMAIL=admin@localhost \
5465
OJS_ADMIN_PASSWORD=changeme \
@@ -57,6 +68,8 @@ ENV \
5768
OJS_FILES_DIR=/var/www/files \
5869
OJS_OAI_REPOSITORY_ID=ojs.localhost \
5970
OJS_ENABLE_BEACON=1 \
71+
OJS_SESSION_LIFETIME=30 \
72+
OJS_X_FORWARDED_FOR=Off \
6073
# see https://github.com/Islandora-Devops/isle-buildkit/tree/main/nginx#nginx-settings
6174
PHP_MAX_EXECUTION_TIME=300 \
6275
PHP_MAX_INPUT_TIME=300 \

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ The installation will run automatically on first startup. The default admin cred
2727

2828
| Environment Variable | Default | Source | Description |
2929
| :------------------- | :------ | :----- | :---------- |
30-
| OJS_DB_HOST | mariadb | environment | MariaDB/MySQL hostname |
31-
| OJS_DB_PORT | 3306 | environment | MariaDB/MySQL port |
32-
| OJS_DB_NAME | ojs | environment | Database name |
33-
| OJS_DB_USER | ojs | environment | Database user |
34-
| OJS_DB_PASSWORD | (generated) | secret | Database password (stored in `./secrets/OJS_DB_PASSWORD`) |
30+
| DB_HOST | mariadb | environment | MariaDB/MySQL hostname |
31+
| DB_PORT | 3306 | environment | MariaDB/MySQL port |
32+
| DB_NAME | ojs | environment | Database name |
33+
| DB_USER | ojs | environment | Database user |
34+
| DB_PASSWORD | (generated) | secret | Database password (stored in `./secrets/OJS_DB_PASSWORD`) |
3535
| OJS_SALT | (generated) | secret | Salt for password hashing (stored in `./secrets/OJS_SALT`) |
3636
| OJS_API_KEY_SECRET | (generated) | secret | Secret for API key encoding (stored in `./secrets/OJS_API_KEY_SECRET`) |
37+
| OJS_SECRET_KEY | (generated) | secret | Internally this is used for any encryption (specifically cookie encryption if enabled) (stored in `./secrets/OJS_SECRET_KEY`) |
3738
| OJS_ADMIN_USERNAME | admin | environment | Initial admin username |
3839
| OJS_ADMIN_EMAIL | admin@example.com | environment | Initial admin email |
3940
| OJS_ADMIN_PASSWORD | (generated) | secret | Initial admin password (stored in `./secrets/OJS_ADMIN_PASSWORD`) |
@@ -42,6 +43,8 @@ The installation will run automatically on first startup. The default admin cred
4243
| OJS_FILES_DIR | /var/www/files | environment | Directory for uploaded files |
4344
| OJS_OAI_REPOSITORY_ID | ojs.localhost | environment | OAI-PMH repository identifier |
4445
| OJS_ENABLE_BEACON | 1 | environment | Enable PKP usage statistics beacon (1=enabled, 0=disabled) |
46+
| OJS_SESSION_LIFETIME | 30 | environment | How long to stay logged in (in days) |
47+
| OJS_X_FORWARDED_FOR | Off | environment | Trust X-Forwarded-For header. Enable PKP usage statistics beacon (Off, On) |
4548

4649
### Nginx and PHP Settings
4750

docker-compose.yaml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ secrets:
1616
file: ./secrets/OJS_SALT
1717
OJS_ADMIN_PASSWORD:
1818
file: ./secrets/OJS_ADMIN_PASSWORD
19+
OJS_SECRET_KEY:
20+
file: ./secrets/OJS_SECRET_KEY
1921

2022
services:
2123
init:
@@ -32,20 +34,14 @@ services:
3234
ports:
3335
- 80:80
3436
environment:
35-
OJS_DB_HOST: mariadb
36-
OJS_DB_NAME: ojs
37-
OJS_DB_USER: ojs
38-
OJS_ADMIN_USERNAME: admin
39-
OJS_ADMIN_EMAIL: admin@example.com
40-
OJS_LOCALE: en
41-
OJS_TIMEZONE: UTC
42-
OJS_FILES_DIR: /var/www/files
4337
OJS_OAI_REPOSITORY_ID: ojs.localhost
4438
OJS_ENABLE_BEACON: 1
4539
secrets:
4640
- source: DB_ROOT_PASSWORD
4741
- source: OJS_API_KEY_SECRET
42+
- source: OJS_SECRET_KEY
4843
- source: OJS_DB_PASSWORD
44+
target: DB_PASSWORD
4945
- source: OJS_SALT
5046
- source: OJS_ADMIN_PASSWORD
5147
volumes:

rootfs/etc/confd/templates/config.inc.tmpl

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626

2727
; An application-specific key that is required for the app to run
2828
; Internally this is used for any encryption (specifically cookie encryption if enabled)
29-
app_key =
29+
app_key = {{ getenv "OJS_SECRET_KEY" }}
3030

3131
; Set this to On once the system has been installed
3232
; (This is generally done automatically by the installer)
3333
installed = Off
3434

3535
; The canonical URL to the OJS installation (excluding the trailing slash)
36-
base_url = "http://localhost"
36+
base_url = "{{ getenv "OJS_BASE_URL" }}"
3737

3838
; Enable strict mode. This will more aggressively cause errors/warnings when
3939
; deprecated behaviour exists in the codebase.
@@ -47,7 +47,7 @@ session_cookie_name = OJSSID
4747

4848
; Number of days to save login cookie for if user selects to remember
4949
; (set to 0 to force expiration at end of current session)
50-
session_lifetime = 30
50+
session_lifetime = {{ getenv "OJS_SESSION_LIFETIME" }}
5151

5252
; SameSite configuration for the cookie, see possible values and explanations
5353
; at https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite
@@ -59,7 +59,7 @@ session_samesite = Lax
5959
; time zones.
6060
; I.e.: "Europe/Amsterdam"
6161
; time_zone="Europe/Amsterdam"
62-
time_zone = "UTC"
62+
time_zone = "{{ getenv "OJS_TIMEZONE" }}"
6363

6464
; Short and long date formats
6565
date_format_short = "Y-m-d"
@@ -96,13 +96,17 @@ restful_urls = On
9696
; An empty string indicates that all hosts should be trusted (not recommended!)
9797
; Example:
9898
; allowed_hosts = '["myjournal.tld", "anotherjournal.tld", "mylibrary.tld"]'
99-
allowed_hosts = '["localhost"]'
99+
{{- $url := getenv "OJS_BASE_URL" -}}
100+
{{- $cleaned := $url | replace "http://" "" | replace "https://" "" -}}
101+
{{- $host := index (split $cleaned "/") 0 -}}
102+
{{- $domain := index (split $host ":") 0 -}}
103+
allowed_hosts = '["localhost", "{{ $domain }}"]'
100104

101105
; Allow the X_FORWARDED_FOR header to override the REMOTE_ADDR as the source IP
102106
; Set this to "On" if you are behind a reverse proxy and you control the
103107
; X_FORWARDED_FOR header.
104108
; Warning: This defaults to "On" if unset for backwards compatibility.
105-
trust_x_forwarded_for = Off
109+
trust_x_forwarded_for = {{ getenv "OJS_X_FORWARDED_FOR" }}
106110

107111
; Display a message on the site admin and journal manager user home pages if there is an upgrade available
108112
show_upgrade_warning = On
@@ -113,7 +117,7 @@ enable_minified = On
113117

114118
; Provide a unique site ID and OAI base URL to PKP for statistics and security
115119
; alert purposes only.
116-
enable_beacon = On
120+
enable_beacon = {{ if getenv "OJS_ENABLE_BEACON" }}On{{ else }}Off{{ end }}
117121

118122
; Set this to "On" if you would like to only have a single, site-wide Privacy
119123
; Statement, rather than a separate Privacy Statement for each journal. Setting
@@ -139,13 +143,13 @@ sandbox = Off
139143
[database]
140144

141145
driver = mysqli
142-
host = {{ getenv "OJS_DB_HOST" }}
143-
username = {{ getenv "OJS_DB_USER" }}
144-
password = {{ getenv "OJS_DB_PASSWORD" }}
145-
name = {{ getenv "OJS_DB_NAME" }}
146+
host = {{ getenv "DB_HOST" }}
147+
username = {{ getenv "DB_USER" }}
148+
password = {{ getenv "DB_PASSWORD" }}
149+
name = {{ getenv "DB_NAME" }}
150+
port = {{ getenv "DB_PORT" }}
146151

147152
; Set the non-standard port and/or socket, if used
148-
; port = 3306
149153
; unix_socket = /var/run/mysqld/mysqld.sock
150154

151155
; Database collation
@@ -208,7 +212,7 @@ connection_charset = utf8
208212
; Complete path to directory to store uploaded files
209213
; (This directory should not be directly web-accessible)
210214
; Windows users should use forward slashes
211-
files_dir = files
215+
files_dir = {{ getenv "OJS_FILES_DIR" }}
212216

213217
; Path to the directory to store public uploaded files
214218
; (This directory should be web-accessible and the specified path
@@ -379,14 +383,14 @@ results_per_keyword = 500
379383

380384
; PDF
381385
; index[application/pdf] = "/usr/bin/pstotext -enc UTF-8 -nopgbrk %s - | /usr/bin/tr '[:cntrl:]' ' '"
382-
; index[application/pdf] = "/usr/bin/pdftotext -enc UTF-8 -nopgbrk %s - | /usr/bin/tr '[:cntrl:]' ' '"
386+
index[application/pdf] = "/usr/bin/pdftotext -enc UTF-8 -nopgbrk %s - | /usr/bin/tr '[:cntrl:]' ' '"
383387

384388
; PostScript
385389
; index[application/postscript] = "/usr/bin/pstotext -enc UTF-8 -nopgbrk %s - | /usr/bin/tr '[:cntrl:]' ' '"
386-
; index[application/postscript] = "/usr/bin/ps2ascii %s | /usr/bin/tr '[:cntrl:]' ' '"
390+
index[application/postscript] = "/usr/bin/ps2ascii %s | /usr/bin/tr '[:cntrl:]' ' '"
387391

388392
; Microsoft Word
389-
; index[application/msword] = "/usr/bin/antiword %s"
393+
index[application/msword] = "/usr/bin/antiword %s"
390394
; index[application/msword] = "/usr/bin/catdoc %s"
391395

392396

@@ -401,7 +405,7 @@ oai = On
401405

402406
; OAI Repository identifier. This setting forms part of OAI-PMH record IDs.
403407
; Changing this setting may affect existing clients and is not recommended.
404-
repository_id = ojs.pkp.sfu.ca
408+
repository_id = {{ getenv "OJS_OAI_REPOSITORY_ID" }}
405409

406410
; Maximum number of records per request to serve via OAI
407411
oai_max_records = 100

rootfs/etc/s6-overlay/scripts/ojs-setup.sh

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ set -eou pipefail
55

66
function mysql_create_database {
77
cat <<-EOF | create-database.sh
8-
CREATE DATABASE IF NOT EXISTS ${OJS_DB_NAME} CHARACTER SET utf8 COLLATE utf8_general_ci;
8+
CREATE DATABASE IF NOT EXISTS ${DB_NAME} CHARACTER SET utf8 COLLATE utf8_general_ci;
99
10-
CREATE USER IF NOT EXISTS '${OJS_DB_USER}'@'%' IDENTIFIED BY '${OJS_DB_PASSWORD}';
11-
GRANT ALL PRIVILEGES ON ${OJS_DB_NAME}.* to '${OJS_DB_USER}'@'%';
10+
CREATE USER IF NOT EXISTS '${DB_USER}'@'%' IDENTIFIED BY '${DB_PASSWORD}';
11+
GRANT ALL PRIVILEGES ON ${DB_NAME}.* to '${DB_USER}'@'%';
1212
FLUSH PRIVILEGES;
1313
14-
SET PASSWORD FOR ${OJS_DB_USER}@'%' = PASSWORD('${OJS_DB_PASSWORD}')
14+
SET PASSWORD FOR ${DB_USER}@'%' = PASSWORD('${DB_PASSWORD}')
1515
EOF
1616
}
1717

1818
function check_ojs_installed {
1919
# Check if OJS database tables exist
2020
# Query the database for one of the core OJS tables (journals table)
21-
mysql -h"${OJS_DB_HOST}" -u"${OJS_DB_USER}" -p"${OJS_DB_PASSWORD}" "${OJS_DB_NAME}" \
21+
mysql -h"${DB_HOST}" -u"${DB_USER}" -p"${DB_PASSWORD}" "${DB_NAME}" \
2222
-e "SELECT 1 FROM journals LIMIT 1" &>/dev/null
2323
return $?
2424
}
@@ -32,10 +32,10 @@ function install_ojs {
3232
form_data="${form_data}&timeZone=${OJS_TIMEZONE}"
3333
form_data="${form_data}&filesDir=${OJS_FILES_DIR}"
3434
form_data="${form_data}&databaseDriver=mysqli"
35-
form_data="${form_data}&databaseHost=${OJS_DB_HOST}"
36-
form_data="${form_data}&databaseUsername=${OJS_DB_USER}"
37-
form_data="${form_data}&databasePassword=${OJS_DB_PASSWORD}"
38-
form_data="${form_data}&databaseName=${OJS_DB_NAME}"
35+
form_data="${form_data}&databaseHost=${DB_HOST}"
36+
form_data="${form_data}&databaseUsername=${DB_USER}"
37+
form_data="${form_data}&databasePassword=${DB_PASSWORD}"
38+
form_data="${form_data}&databaseName=${DB_NAME}"
3939
form_data="${form_data}&oaiRepositoryId=${OJS_OAI_REPOSITORY_ID}"
4040
form_data="${form_data}&enableBeacon=${OJS_ENABLE_BEACON}"
4141
form_data="${form_data}&adminUsername=${OJS_ADMIN_USERNAME}"
@@ -53,7 +53,6 @@ function install_ojs {
5353
echo "=========================================="
5454
echo "OJS Installation Complete!"
5555
echo "=========================================="
56-
chmod 440 /var/www/ojs/config.inc.php
5756
rm /tmp/ojs-install.log
5857
else
5958
echo "=========================================="
@@ -62,12 +61,11 @@ function install_ojs {
6261
cat /tmp/ojs-install.log
6362
echo "=========================================="
6463
fi
64+
sed -i 's/installed = Off/installed = On/' /var/www/ojs/config.inc.php
65+
chmod 440 /var/www/ojs/config.inc.php
6566
}
6667

6768
function main {
68-
export DB_HOST=${OJS_DB_HOST}
69-
export DB_PORT=${OJS_DB_PORT}
70-
7169
mysql_create_database
7270

7371
# wait for nginx

0 commit comments

Comments
 (0)