-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from H2CK/kubernetes
Initialize db on start up / support k8s example template
- Loading branch information
Showing
10 changed files
with
1,071 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/bash | ||
INIT_DB=${DB_PASSWORD:-FALSE} | ||
IDB_HOST=${DB_HOST:-localhost} | ||
IDB_PORT=${DB_PORT:-3306} | ||
IDB_USER=${DB_USER:-root} | ||
IDB_PASSWORD=${DB_PASSWORD:-password} | ||
IDB_DB_NAME=${DB_NAME:-webtrees} | ||
IDB_DB_PREFIX="wt_" | ||
IDB_WT_ADMIN=${WT_ADMIN:-admin} | ||
IDB_WT_ADMINPW=${WT_ADMINPW:-admin123} | ||
IDB_WT_ADMINMAIL=${WT_ADMINMAIL:-noreply@webtrees.net} | ||
|
||
#Check if initial database configuration should be set | ||
if [ "$INIT_DB" != "FALSE" ] | ||
then | ||
#Check if not yet set, if file exists, do nothing | ||
CONFIG_FILE=/var/www/html/data/config.ini.php | ||
if [ -f "$CONFIG_FILE" ]; then | ||
echo "Configuration file $CONFIG_FILE yet exist. No settings will be modified." | ||
else | ||
echo "Creating the initial database settings in configuration file $CONFIG_FILE and creating database." | ||
cp /config.ini.php "$CONFIG_FILE" | ||
sed -i 's/<DB_HOST>/'"$IDB_HOST"'/g' "$CONFIG_FILE" | ||
sed -i 's/<DB_PORT>/'"$IDB_PORT"'/g' "$CONFIG_FILE" | ||
sed -i 's/<DB_USER>/'"$IDB_USER"'/g' "$CONFIG_FILE" | ||
sed -i 's/<DB_PASSWORD>/'"$IDB_PASSWORD"'/g' "$CONFIG_FILE" | ||
sed -i 's/<DB_NAME>/'"$IDB_DB_NAME"'/g' "$CONFIG_FILE" | ||
sed -i 's/<DB_PREFIX>/'"$IDB_DB_PREFIX"'/g' "$CONFIG_FILE" | ||
chown www-data:docker-data "$CONFIG_FILE" | ||
chmod 660 "$CONFIG_FILE" | ||
#Create database structure and add admin user | ||
cp /webtrees.sql /mod_webtrees.sql | ||
sed -i 's/<DB_NAME>/'"$IDB_DB_NAME"'/g' /mod_webtrees.sql | ||
sed -i 's/<WT_ADMIN_NAME>/'"$IDB_WT_ADMIN"'/g' /mod_webtrees.sql | ||
#Encode password and escape for sed | ||
WTCRYPT=$(php -r "echo crypt('$IDB_WT_ADMINPW', '');") | ||
sed -i 's/<WT_ADMIN_PW>/'"$(echo $WTCRYPT | sed -e 's/[]\/$*.^[]/\\&/g')"'/g' /mod_webtrees.sql | ||
sed -i 's/<WT_ADMIN_MAIL>/'"$IDB_WT_ADMINMAIL"'/g' /mod_webtrees.sql | ||
#Write to database | ||
mysql -u "$IDB_USER" --password="$IDB_PASSWORD" -h "$IDB_HOST" < /mod_webtrees.sql | ||
#Alternative to set Webtrees admin user: | ||
#echo "UPDATE wt_user SET user_name='$IDB_WT_ADMIN', email='$IDB_WT_ADMINMAIL', real_name='Admin', password='$WTCRYPT' WHERE user_id=1" | mysql -u "$IDB_USER" --password="$IDB_PASSWORD" -h "$IDB_HOST" "$IDB_DB_NAME" | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
; <?php exit; ?> DO NOT DELETE THIS LINE | ||
dbhost="<DB_HOST>" | ||
dbport="<DB_PORT>" | ||
dbuser="<DB_USER>" | ||
dbpass="<DB_PASSWORD>" | ||
dbname="<DB_NAME>" | ||
tblpfx="<DB_PREFIX>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Kubernetes template | ||
|
||
This example template for kubernetes automatically creates a MySQL 5.7 database and a webtrees instance that uses this database. There for you have to set the database and webtrees admin credentials in the file `kustomization.yaml`. | ||
Webtrees will be provided without SSL on port 80. | ||
The template uses a persitent volume claim. Therefore your K8S instance has to provide a perstitant_storage. | ||
|
||
You can apply the (modified) template using the command `kubectl apply -f kustomization.yaml`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
secretGenerator: | ||
- name: mysql-pass | ||
literals: | ||
- password=YOUR_PASSWORD | ||
- name: webtrees-admin-pass | ||
literals: | ||
- password=YOUR_WEBTREES_ADMIN_PASSWORD | ||
--- | ||
resources: | ||
- mysql-deployment.yaml | ||
- wwebtrees-deployment.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: webtrees-mysql | ||
labels: | ||
app: webtrees | ||
spec: | ||
ports: | ||
- port: 3306 | ||
selector: | ||
app: webtrees | ||
tier: mysql | ||
clusterIP: None | ||
--- | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
name: mysql-pv-claim | ||
labels: | ||
app: webtrees | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 10Gi | ||
--- | ||
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2 | ||
kind: Deployment | ||
metadata: | ||
name: webtrees-mysql | ||
labels: | ||
app: webtrees | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: webtrees | ||
tier: mysql | ||
strategy: | ||
type: Recreate | ||
template: | ||
metadata: | ||
labels: | ||
app: webtrees | ||
tier: mysql | ||
spec: | ||
containers: | ||
- image: mysql:5.7 | ||
name: mysql | ||
env: | ||
- name: MYSQL_ROOT_PASSWORD | ||
valueFrom: | ||
secretKeyRef: | ||
name: mysql-pass | ||
key: password | ||
ports: | ||
- containerPort: 3306 | ||
name: mysql | ||
volumeMounts: | ||
- name: mysql-persistent-storage | ||
mountPath: /var/lib/mysql | ||
volumes: | ||
- name: mysql-persistent-storage | ||
persistentVolumeClaim: | ||
claimName: mysql-pv-claim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: webtrees | ||
labels: | ||
app: webtrees | ||
spec: | ||
ports: | ||
- port: 80 | ||
selector: | ||
app: webtrees | ||
tier: frontend | ||
type: LoadBalancer | ||
--- | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
name: wt-pv-claim | ||
labels: | ||
app: webtrees | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 10Gi | ||
--- | ||
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2 | ||
kind: Deployment | ||
metadata: | ||
name: webtrees | ||
labels: | ||
app: webtrees | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: webtrees | ||
tier: frontend | ||
strategy: | ||
type: Recreate | ||
template: | ||
metadata: | ||
labels: | ||
app: webtrees | ||
tier: frontend | ||
spec: | ||
containers: | ||
- image: dtjs48jkt/webtrees | ||
name: webtrees | ||
env: | ||
- name: DISABLE_SSL | ||
value: true | ||
- name: PORT | ||
value: 80 | ||
- name: DB_HOST | ||
value: webtrees-mysql | ||
- name: WT_ADMINPW | ||
valueFrom: | ||
secretKeyRef: | ||
name: webtrees-admin-pass | ||
key: password | ||
- name: DB_PASSWORD | ||
valueFrom: | ||
secretKeyRef: | ||
name: mysql-pass | ||
key: password | ||
ports: | ||
- containerPort: 80 | ||
name: webtrees | ||
volumeMounts: | ||
- name: webtrees-persistent-storage | ||
mountPath: /var/www/html/data | ||
subPath: data | ||
- name: webtrees-persistent-storage | ||
mountPath: /var/www/html/media | ||
subPath: media | ||
volumes: | ||
- name: webtrees-persistent-storage | ||
persistentVolumeClaim: | ||
claimName: wt-pv-claim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.