Skip to content

Instantly share code, notes, and snippets.

@tobybellwood
Created May 27, 2022 00:42
Show Gist options
  • Save tobybellwood/2bd826ffd10d0a238a4ed28b355b6c46 to your computer and use it in GitHub Desktop.
Save tobybellwood/2bd826ffd10d0a238a4ed28b355b6c46 to your computer and use it in GitHub Desktop.
bare bones Lagoon database project
docker-compose-yaml: docker-compose.yml
project: generic
tasks:
post-rollout:
- run:
name: populate mariadb
command: |
mysql --host=mariadb --user=lagoon --password=lagoon --database=lagoon -e 'CREATE TABLE IF NOT EXISTS time ( timestamp timestamp NOT NULL);'
mysql --host=mariadb --user=lagoon --password=lagoon --database=lagoon -e 'SHOW CREATE TABLE time;'
mysql --host=mariadb --user=lagoon --password=lagoon --database=lagoon -e 'INSERT INTO time (timestamp) VALUES (CURRENT_TIMESTAMP);'
mysql --host=mariadb --user=lagoon --password=lagoon --database=lagoon -e 'SELECT * FROM time;'
service: mariadb
- run:
name: populate postgres
command: |
psql postgresql://lagoon:lagoon@postgres:5432/postgres -c 'CREATE TABLE IF NOT EXISTS time ( timestamp timestamp NOT NULL);'
psql postgresql://lagoon:lagoon@postgres:5432/postgres -c '\dt+'
psql postgresql://lagoon:lagoon@postgres:5432/postgres -c 'INSERT INTO time (timestamp) VALUES (CURRENT_TIMESTAMP);'
psql postgresql://lagoon:lagoon@postgres:5432/postgres -c 'SELECT * FROM time;'
service: postgres
environments:
generic-main:
cronjobs:
- name: add mariadb timestamps
schedule: "M * * * *"
command: |
mysql --host=mariadb --user=lagoon --password=lagoon --database=lagoon -e 'INSERT INTO time (timestamp) VALUES (CURRENT_TIMESTAMP);'
service: mariadb
- name: add postgres timestamps
schedule: "M * * * *"
command: |
psql postgresql://lagoon:lagoon@postgres:5432/postgres -c 'INSERT INTO time (timestamp) VALUES (CURRENT_TIMESTAMP);'
service: postgres
version: '2'
x-user:
&default-user
# The default user under which the containers should run. Change this if you are on linux and run with another user than id `1000`
user: '1000'
services:
mariadb:
image: uselagoon/mariadb-10.5:latest
labels:
lagoon.type: mariadb-single
ports:
- "3306" # exposes the port 3306 with a random local port, find it with `docker-compose port mariadb 3306`
<< : *default-user # uses the defined user from top
postgres:
image: uselagoon/postgres-14:latest
labels:
lagoon.type: postgres-single
ports:
- "5432" # exposes the port 5432 with a random local port, find it with `docker-compose port postgres 5432`
<< : *default-user # uses the defined user from top
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment