-
Notifications
You must be signed in to change notification settings - Fork 0
/
postgres.tests.cloudbuild.yaml
88 lines (81 loc) · 2.92 KB
/
postgres.tests.cloudbuild.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
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
steps:
- id: Install dependencies
name: python:3.11
dir: retrieval_service
script: pip install -r requirements.txt -r requirements-test.txt --user
- id: Create database
name: postgres
secretEnv:
- DB_USER # Use built-in env vars for database connection
- DB_PASS
script: |
#!/usr/bin/env bash
export PGUSER=$DB_USER
export PGPASSWORD=$DB_PASS
echo "SELECT 'CREATE DATABASE ${_DATABASE_NAME}' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '${_DATABASE_NAME}')\gexec" | psql -h ${_DATABASE_HOST}
psql -h ${_DATABASE_HOST} -d ${_DATABASE_NAME} -c 'CREATE EXTENSION IF NOT EXISTS vector;'
- id: Update config
name: python:3.11
dir: retrieval_service
secretEnv:
- DB_USER
- DB_PASS
script: |
#!/usr/bin/env bash
# Create config
cp example-config.yml config.yml
sed -i "s/127.0.0.1/${_DATABASE_HOST}/g" config.yml
sed -i "s/my_database/${_DATABASE_NAME}/g" config.yml
sed -i "s/my-user/$$DB_USER/g" config.yml
sed -i "s/my-password/$$DB_PASS/g" config.yml
- id: Run Alloy DB integration tests
name: python:3.11
dir: retrieval_service
env: # Set env var expected by tests
- "DB_NAME=${_DATABASE_NAME}"
- "DB_HOST=${_DATABASE_HOST}"
secretEnv:
- DB_USER
- DB_PASS
script: |
#!/usr/bin/env bash
python -m pytest --cov=datastore.providers.postgres --cov-config=coverage/.postgres-coveragerc datastore/providers/postgres_test.py
- id: Clean database
name: postgres
secretEnv:
- DB_USER
- DB_PASS
script: |
#!/usr/bin/env bash
export PGUSER=$DB_USER
export PGPASSWORD=$DB_PASS
psql -h ${_DATABASE_HOST} -c "DROP DATABASE IF EXISTS ${_DATABASE_NAME};"
substitutions:
_DATABASE_NAME: test_${SHORT_SHA}
_DATABASE_USER: postgres
_DATABASE_HOST: 127.0.0.1
availableSecrets:
secretManager:
- versionName: projects/$PROJECT_ID/secrets/alloy_db_user/versions/latest
env: DB_USER
- versionName: projects/$PROJECT_ID/secrets/alloy_db_pass/versions/latest
env: DB_PASS
options:
automapSubstitutions: true
substitutionOption: 'ALLOW_LOOSE'
dynamic_substitutions: true
pool:
name: projects/$PROJECT_ID/locations/us-central1/workerPools/alloy-private-pool # Necessary for VPC network connection