【发布时间】:2018-12-09 14:50:41
【问题描述】:
我正在管理一个 NodeJS 云函数存储库,它执行一些数据库操作,例如“userExists”等,并希望针对我的 Google Cloud SQL 数据库进行集成测试。为了在本地执行此操作,我在特定端口上启动代理应用程序,然后将 Knex 配置为使用此端口。
但是,我还想使用 Azure Pipelines 为此设置 CI/CD。 Google 允许将代理下载为 docker 映像,我已经这样做了。我已经为其提供了服务帐户密钥,并成功启动了它,但是,当我运行我的测试时,它们仍然无法连接到代理。
我的管道 YAML 文件中处理代理和运行测试的部分如下所示:
- script: |
docker run -d \
-v 'qa-key.json':/config \
-p 127.0.0.1:5432:5432 \
gcr.io/cloudsql-docker/gce-proxy:1.12 /cloud_sql_proxy \
-instances=$(DBInstanceConnectionName)=tcp:0.0.0.0:5432 -credential_file=/config
displayName: 'Run GCP Proxy'
- task: Npm@1
displayName: 'Run Tests'
inputs:
command: custom
customCommand: 'test'
运行测试的test 命令可用。配置 knex 的函数如下所示:
const connectKnex = () => {
const config = {
user: 'my_user',
password: 'my_users_password',
database: 'my_db',
port: 5432
}
return knex({
client: 'pg',
connection: config
});
}
我认为我的问题是因为运行代理的任务在测试运行后不再执行,但我不知道如何验证/修复这个问题。
【问题讨论】:
标签: node.js google-cloud-platform yaml azure-pipelines knex.js