Skip to content

Commit 45c3e32

Browse files
committed
[db] Make gitpod-db:dbtest-init self-contained by starting a mysql DB if needed
1 parent 84cf4a1 commit 45c3e32

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

components/gitpod-db/BUILD.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ packages:
6464
ephemeral: true
6565
config:
6666
commands:
67+
# Check if a DB is present. If not: start one and wait until it's up
68+
# Note: In CI there is a DB running as sidecar; in workspaces we're starting it once.
69+
# Re-use of the instance because of the init scripts (cmp. next step).
70+
- ["sh", "-c", "mysqladmin ping -h \"$DB_HOST\" \"$DB_PORT\" -p$DB_PASSWORD -u $DB_USER --silent || (docker run -d -e MYSQL_ROOT_PASSWORD=$DB_PASSWORD -e MYSQL_TCP_PORT=$DB_PORT -p $DB_PORT:$DB_PORT mysql:5.7; while ! mysqladmin ping -h \"$DB_HOST\" -P \"$DB_PORT\" -p$DB_PASSWORD -u $DB_USER --silent; do echo \"waiting for DB...\"; sleep 2; done)"]
71+
# Apply the DB initialization scripts (re-creates the "gitpod" DB if already there)
6772
- ["sh", "-c", "find chart-config-db-init--init-scripts -name \"*.sql\" | sort | xargs cat | mysql -h \"$DB_HOST\" -P \"$DB_PORT\" -p$DB_PASSWORD -u $DB_USER"]
73+
# Run DB migrations
6874
- ["sh", "-c", "mkdir -p mig; cd mig; ../components-gitpod-db--migrations/install.sh"]
6975
- ["yarn", "--cwd", "mig/node_modules/@gitpod/gitpod-db", "typeorm", "migrations:run"]
7076
- name: docker

0 commit comments

Comments
 (0)