我将在AWS的gitlab中进行CI / CD。我的网站包含一个Postgresql数据库。
问题1:但是我不知道如何找到数据库主机。有人说主机名是localhost,但我对此表示怀疑,因为我已经将网站部署到了AWS。应该是弹性IP吗?
我的.gitlab-ci.yml文件如下:
image: node:latest
stages:
- testing
variables:
POSTGRES_DB: firstdb
POSTGRES_USER: johndoe
POSTGRES_PASSWORD: 1234
POSTGRES_HOST: //I don't know
testing:
services:
- postgres:latest
before_script:
- npm install -g yarn
- yarn install
- yarn knex migrate:latest --env testing
stage: testing
script:
- yarn jest
问题2:另外,我是否应该相应地更改knex.ts的开发,测试和生产的数据库配置,以使其与.gitlab-ci.yml保持一致?
我的knex文件如下:
import * as dotenv from 'dotenv';
dotenv.config();
module.exports = {
development: {
client: 'postgresql',
connection: {
database: process.env.DB_NAME , //should I type actual data?
user: process.env.DB_USERNAME ,
password: process.env.DB_PASSWORD
},
pool: {
min: 2,
max: 10
},
migrations: {
tableName: 'knex_migrations'
}
},
testing:{
client: 'postgresql',
connection: {
host: process.env.POSTGRES_HOST ,//should I type actual data?
database: process.env.POSTGRES_DB ,
user: process.env.POSTGRES_USER ,
password: process.env.POSTGRES_PASSWORD
},
pool: {
min: 2,
max: 10
},
migrations: {
tableName: 'knex_migrations'
}
},
production: {
client: "postgresql",
connection: {
database: process.env.DB_NAME ,//should I type actual data?
user: process.env.DB_USERNAME ,
password: process.env.DB_PASSWORD
},
pool: {
min: 2,
max: 10
},
migrations: {
tableName: "knex_migrations"
}
}
};
非常感谢。 :)
答案 0 :(得分:0)
主机名是postgres
。主机名是从映像名称派生的。
在这里解释: https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#how-services-are-linked-to-the-job