Skip to content

Commit

Permalink
init db on container start
Browse files Browse the repository at this point in the history
  • Loading branch information
escoand committed Aug 16, 2024
1 parent d7919d6 commit 56b30e1
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 40 deletions.
12 changes: 1 addition & 11 deletions .github/workflows/test_kube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,7 @@ jobs:
run: |-
set -euo pipefail
find init/ -name 'secrets.*.yaml' -print -exec podman kube play {} \;
find kube/ -name '*.yaml' -print -exec podman kube play --quiet --start=false {} \;
- name: Create databases
run: |-
set -euo pipefail
podman pod start mariadb
podman wait --condition healthy mariadb-app
./db_usr_pwd.sh MYSQL nextcloud
./db_usr_pwd.sh WORDPRESS_DB wordpress1
./db_usr_pwd.sh WORDPRESS_DB wordpress2
- name: Start pods
run: podman pod start -a
find kube/ -name '*.yaml' -print -exec podman kube play --quiet {} \;
- name: Wait for healthy state
run: |-
set -euo pipefail
Expand Down
28 changes: 0 additions & 28 deletions db_usr_pwd.sh

This file was deleted.

20 changes: 19 additions & 1 deletion kube/nextcloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,29 @@ spec:
mountPath: /var/www/html/data:z
subPath: data
initContainers:
- image: docker.io/library/nextcloud:29.0.4
- name: init-dirs
image: docker.io/library/nextcloud:29.0.4
command: ["mkdir", "-p", "/data/app", "/data/apps", "/data/config", "/data/data"]
volumeMounts:
- name: nextcloud
mountPath: /data:z
- name: init-db
image: docker.io/library/mariadb:11.4.3
command:
- sh
- -c
- |-
cat <<EOF | mariadb -h mariadb -p"$MARIADB_ROOT_PASSWORD"
CREATE DATABASE IF NOT EXISTS $MYSQL_DATABASE;
CREATE USER IF NOT EXISTS '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD';
GRANT ALL PRIVILEGES ON $MYSQL_DATABASE.* TO '$MYSQL_USER'@'%';
FLUSH PRIVILEGES;
EOF
envFrom:
- secretRef:
name: mariadb
- secretRef:
name: nextcloud
volumes:
- name: nextcloud
persistentVolumeClaim:
Expand Down
18 changes: 18 additions & 0 deletions kube/wordpress1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ spec:
volumeMounts:
- name: wordpress1
mountPath: /var/www/html/wp-content:z
initContainers:
- name: init-db
image: docker.io/library/mariadb:11.4.3
command:
- sh
- -c
- |-
cat <<EOF | mariadb -h mariadb -p"$MARIADB_ROOT_PASSWORD"
CREATE DATABASE IF NOT EXISTS $WORDPRESS_DB_NAME;
CREATE USER IF NOT EXISTS '$WORDPRESS_DB_USER'@'%' IDENTIFIED BY '$WORDPRESS_DB_PASSWORD';
GRANT ALL PRIVILEGES ON $WORDPRESS_DB_NAME.* TO '$WORDPRESS_DB_USER'@'%';
FLUSH PRIVILEGES;
EOF
envFrom:
- secretRef:
name: mariadb
- secretRef:
name: wordpress1
volumes:
- name: wordpress1
persistentVolumeClaim:
Expand Down
18 changes: 18 additions & 0 deletions kube/wordpress2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ spec:
volumeMounts:
- name: wordpress2
mountPath: /var/www/html/wp-content:z
initContainers:
- name: init-db
image: docker.io/library/mariadb:11.4.3
command:
- sh
- -c
- |-
cat <<EOF | mariadb -h mariadb -p"$MARIADB_ROOT_PASSWORD"
CREATE DATABASE IF NOT EXISTS $WORDPRESS_DB_NAME;
CREATE USER IF NOT EXISTS '$WORDPRESS_DB_USER'@'%' IDENTIFIED BY '$WORDPRESS_DB_PASSWORD';
GRANT ALL PRIVILEGES ON $WORDPRESS_DB_NAME.* TO '$WORDPRESS_DB_USER'@'%';
FLUSH PRIVILEGES;
EOF
envFrom:
- secretRef:
name: mariadb
- secretRef:
name: wordpress2
volumes:
- name: wordpress2
persistentVolumeClaim:
Expand Down

0 comments on commit 56b30e1

Please sign in to comment.