Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-db/BUILD.yaml
2492 views
1
packages:
2
- name: lib
3
type: yarn
4
srcs:
5
- "src/**/*.ts"
6
- .eslintrc
7
- package.json
8
- mocha.opts
9
deps:
10
- :dbtest
11
- components/gitpod-protocol:lib
12
config:
13
packaging: library
14
yarnLock: ${coreYarnLockBase}/yarn.lock
15
tsconfig: tsconfig.json
16
dontTest: true
17
- name: latest-migration
18
type: generic
19
srcs:
20
- "src/typeorm/migration/*.ts"
21
- "scripts/generate-latest-migration.sh"
22
config:
23
dontTest: false
24
commands:
25
- ["sh", "-c", "scripts/generate-latest-migration.sh > latest-migration.txt"]
26
test:
27
- ["scripts/generate-latest-migration.sh", "test"]
28
- ["sh", "-c", "rm -rf src"]
29
- ["sh", "-c", "rm -rf scripts"]
30
- name: migrations
31
type: yarn
32
srcs:
33
- "src/**/*.ts"
34
- .eslintrc
35
- package.json
36
deps:
37
- components/gitpod-protocol:lib
38
config:
39
dontTest: true
40
packaging: offline-mirror
41
yarnLock: ${coreYarnLockBase}/yarn.lock
42
tsconfig: tsconfig.json
43
- name: dbtest
44
type: yarn
45
srcs:
46
- "src/**/*.ts"
47
- .eslintrc
48
- package.json
49
- mocha.opts
50
deps:
51
- :dbtest-init
52
- components/gitpod-protocol:lib
53
config:
54
packaging: library
55
yarnLock: ${coreYarnLockBase}/yarn.lock
56
tsconfig: tsconfig.json
57
commands:
58
test: ["yarn", "db-test"]
59
build: ["yarn", "build"]
60
- name: dbtest-init
61
type: generic
62
srcs:
63
- package.json
64
- hack/*.sql
65
deps:
66
- :migrations
67
- install/installer/pkg/components/database/incluster/init:init-scripts
68
env:
69
- DB_PORT=23306
70
- DB_USER=root
71
- DB_PASSWORD=test
72
- DB_ENCRYPTION_KEYS=[{"name":"general","version":1,"primary":true,"material":"5vRrp0H4oRgdkPnX1qQcS54Q0xggr6iyho42IQ1rO+c="}]
73
ephemeral: true
74
config:
75
commands:
76
# Check if a DB is present. If not: start one and wait until it's up
77
# Note: In CI there is a DB running as sidecar; in workspaces we're starting it once.
78
# Re-use of the instance because of the init scripts (cmp. next step).
79
# (gpl): It would be nice to use bitnami/mysql here as we do in previews. However the container does not start in Gitpod workspaces due to some docker/kernel/namespace issue.
80
- ["sh", "-c", "mysqladmin ping --wait=${DB_RETRIES:-1} -h $DB_HOST --port $DB_PORT -p$DB_PASSWORD -u$DB_USER --default-auth=mysql_native_password --silent || (docker container rm test-mysql; docker run --name test-mysql -d -e MYSQL_ROOT_PASSWORD=$DB_PASSWORD -e MYSQL_TCP_PORT=$DB_PORT -p $DB_PORT:$DB_PORT mysql:8.0.33 --default-authentication-plugin=mysql_native_password; while ! mysqladmin ping -h \"$DB_HOST\" -P \"$DB_PORT\" -p$DB_PASSWORD -u$DB_USER --default-auth=mysql_native_password --silent; do echo \"waiting for DB...\"; sleep 2; done)"]
81
# Apply the DB initialization scripts (re-creates the "gitpod" DB if already there)
82
- ["mkdir", "-p", "init-scripts"]
83
- ["sh", "-c", "find . -name \"*.sql\" | sort | xargs -I file cp file init-scripts"]
84
- ["sh", "-c", "ls init-scripts | sort | xargs -I file cat init-scripts/file | sed -e 's/__GITPOD_USERNAME__/gitpod/g' | sed -e 's/__GITPOD_USERNAME__/gitpod/g' | sed -e 's/__GITPOD_DB_NAME__/gitpod/g' | tee debug.txt | mysql -h \"$DB_HOST\" -P \"$DB_PORT\" -p$DB_PASSWORD -u $DB_USER"]
85
# Run DB migrations
86
- ["sh", "-c", "mkdir -p mig; cd mig; ../components-gitpod-db--migrations/install.sh"]
87
# migrate 'migrations'
88
- ["yarn", "--cwd", "mig/node_modules/@gitpod/gitpod-db", "run", "migrate-migrations"]
89
# Run actual migrations
90
- ["yarn", "--cwd", "mig/node_modules/@gitpod/gitpod-db", "typeorm", "migrations:run"]
91
# Clean out package to not bload the build artifact
92
- ["rm", "-rf", "mig"]
93
- name: docker
94
type: docker
95
srcs:
96
- migrate.sh
97
- migrate_gcp.sh
98
- typeorm.sh
99
- typeorm_gcp.sh
100
deps:
101
- :migrations
102
argdeps:
103
- imageRepoBase
104
config:
105
buildArgs:
106
VERSION: ${version}
107
dockerfile: leeway.Dockerfile
108
metadata:
109
helm-component: dbMigrations
110
image:
111
- ${imageRepoBase}/db-migrations:${version}
112
- ${imageRepoBase}/db-migrations:commit-${__git_commit}
113
scripts:
114
- name: init-testdb
115
description: "Starts a properly initialized MySQL instance to run tests against. Usage: '. $(leeway run components/gitpod-db:init-testdb)'"
116
deps: []
117
script: |
118
export DB_HOST=${DB_HOST:-127.0.0.1}
119
leeway build components/gitpod-db/go:init-testdb
120
- name: db-test-env
121
description: "Creates a file with env vars necessary for running DB tests. The file delets itself after being sourced. Usage: '. $(leeway run components/gitpod-db:db-test-env)'"
122
deps: []
123
script: |
124
TMP="$(mktemp)"
125
echo '#!/bin/bash' > $TMP
126
echo 'export DB_ENCRYPTION_KEYS="[{\"name\":\"general\",\"version\":1,\"primary\":true,\"material\":\"5vRrp0H4oRgdkPnX1qQcS54Q0xggr6iyho42IQ1rO+c=\"}]";export DB_HOST=${DB_HOST:-127.0.0.1};export DB_PORT=23306;export DB_USER=root;export DB_PASSWORD=test;' >> $TMP
127
echo "rm -f $TMP" >> $TMP
128
echo $TMP
129
130