-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathBUILD.yaml
128 lines (128 loc) · 5.1 KB
/
BUILD.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
packages:
- name: lib
type: yarn
srcs:
- "src/**/*.ts"
- .eslintrc
- package.json
- mocha.opts
deps:
- :dbtest
- components/gitpod-protocol:lib
config:
packaging: library
yarnLock: ${coreYarnLockBase}/yarn.lock
tsconfig: tsconfig.json
dontTest: true
- name: latest-migration
type: generic
srcs:
- "src/typeorm/migration/*.ts"
- "scripts/generate-latest-migration.sh"
config:
dontTest: false
commands:
- ["sh", "-c", "scripts/generate-latest-migration.sh > latest-migration.txt"]
test:
- ["scripts/generate-latest-migration.sh", "test"]
- ["sh", "-c", "rm -rf src"]
- ["sh", "-c", "rm -rf scripts"]
- name: migrations
type: yarn
srcs:
- "src/**/*.ts"
- .eslintrc
- package.json
deps:
- components/gitpod-protocol:lib
config:
dontTest: true
packaging: offline-mirror
yarnLock: ${coreYarnLockBase}/yarn.lock
tsconfig: tsconfig.json
- name: dbtest
type: yarn
srcs:
- "src/**/*.ts"
- .eslintrc
- package.json
- mocha.opts
deps:
- :dbtest-init
- components/gitpod-protocol:lib
config:
packaging: library
yarnLock: ${coreYarnLockBase}/yarn.lock
tsconfig: tsconfig.json
commands:
test: ["yarn", "db-test"]
build: ["yarn", "build"]
- name: dbtest-init
type: generic
srcs:
- package.json
- hack/*.sql
deps:
- :migrations
- install/installer/pkg/components/database/incluster/init:init-scripts
env:
- DB_PORT=23306
- DB_USER=root
- DB_PASSWORD=test
- DB_ENCRYPTION_KEYS=[{"name":"general","version":1,"primary":true,"material":"5vRrp0H4oRgdkPnX1qQcS54Q0xggr6iyho42IQ1rO+c="}]
ephemeral: true
config:
commands:
# Check if a DB is present. If not: start one and wait until it's up
# Note: In CI there is a DB running as sidecar; in workspaces we're starting it once.
# Re-use of the instance because of the init scripts (cmp. next step).
# (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.
- ["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)"]
# Apply the DB initialization scripts (re-creates the "gitpod" DB if already there)
- ["mkdir", "-p", "init-scripts"]
- ["sh", "-c", "find . -name \"*.sql\" | sort | xargs -I file cp file init-scripts"]
- ["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"]
# Run DB migrations
- ["sh", "-c", "mkdir -p mig; cd mig; ../components-gitpod-db--migrations/install.sh"]
# migrate 'migrations'
- ["yarn", "--cwd", "mig/node_modules/@gitpod/gitpod-db", "run", "migrate-migrations"]
# Run actual migrations
- ["yarn", "--cwd", "mig/node_modules/@gitpod/gitpod-db", "typeorm", "migrations:run"]
# Clean out package to not bload the build artifact
- ["rm", "-rf", "mig"]
- name: docker
type: docker
srcs:
- migrate.sh
- migrate_gcp.sh
- typeorm.sh
- typeorm_gcp.sh
deps:
- :migrations
argdeps:
- imageRepoBase
config:
buildArgs:
VERSION: ${version}
dockerfile: leeway.Dockerfile
metadata:
helm-component: dbMigrations
image:
- ${imageRepoBase}/db-migrations:${version}
- ${imageRepoBase}/db-migrations:commit-${__git_commit}
scripts:
- name: init-testdb
description: "Starts a properly initialized MySQL instance to run tests against. Usage: '. $(leeway run components/gitpod-db:init-testdb)'"
deps: []
script: |
export DB_HOST=${DB_HOST:-127.0.0.1}
leeway build components/gitpod-db/go:init-testdb
- name: db-test-env
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)'"
deps: []
script: |
TMP="$(mktemp)"
echo '#!/bin/bash' > $TMP
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
echo "rm -f $TMP" >> $TMP
echo $TMP