node.js - Github Actions - 未处理的拒绝 SequelizeConnectionError:启动数据包中未指定 PostgreSQL 用户名
问题描述
我为 CI/CD 设置了一个 Github 操作,但我在数据库连接方面遇到了困难。
由于 sequelize 允许指定另一个数据库 url(使用“use_env_variable”选项),我像这样更新了我的配置:
{
"test": {
"dialect": "postgres",
"schema": "exercises_library",
"logging": false,
"use_env_variable": "DATABASE_URL"
},
"production": {
"dialect": "postgres",
"schema": "exercises_library",
"logging": false,
"use_env_variable": "DATABASE_URL"
}
}
所以我在 Github Actions 中编写了我的工作流程:
name: Source Code CI/CD
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
ci:
runs-on: ubuntu-latest
container:
image: node:12
services:
# More explanation about that here :
# https://github.com/actions/example-services/blob/master/.github/workflows/postgres-service.yml
postgres:
image: postgres:12-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: jy95
POSTGRES_DB: sourcecode
ports: ["5432:5432"]
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: jy95
POSTGRES_DB: sourcecode
# use postgres for the host here because we have specified a container for the job.
# If we were running the job on the VM this would be localhost
POSTGRES_HOST: postgres
steps:
- uses: actions/checkout@v2
- name: Set DB Port
env:
POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }}
run: |
echo "::set-env name=POSTGRES_PORT::$POSTGRES_PORT"
- name: Install
run: |
npm install -g npm@latest
npm install -g codecov
npm ci
- name: Tests
env:
DATABASE_URL: '${{ env.POSTGRES_HOST }}://${{ env.POSTGRES_USER}}:${{env.POSTGRES_PASSWORD}}:${{env.POSTGRES_PORT}}/${{env.POSTGRES_DB}}'
run: |
npm test
- name: Upload code coverage
run: |
npx codecov
cd:
runs-on: ubuntu-latest
needs: ci
steps:
- uses: actions/checkout@v2
- name: Docker login
run: docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASSWORD }}
- name: Build
run: docker build -t sourcecode_api .
- name: Tags
run: |
docker tag sourcecode_api ${{ secrets.DOCKER_USER }}/sourcecode_api:${{ github.sha }}
docker tag sourcecode_api ${{ secrets.DOCKER_USER }}/sourcecode_api:latest
- name: Push
run: |
docker push ${{ secrets.DOCKER_USER }}/sourcecode_api:${{ github.sha }}
docker push ${{ secrets.DOCKER_USER }}/sourcecode_api:latest
我的日志中出现此错误:
我看到 env 变量设置正确:
我已经阅读了很多资源(关于 Github 问题或 Stackoverflow),但没有一个能解决我的问题。
提前致谢
解决方案
这是我的错字 - 如果它可以帮助任何人:
DATABASE_URL: 'postgresql://${{ env.POSTGRES_USER }}:${{ env.POSTGRES_PASSWORD }}@${{ env.POSTGRES_HOST }}:${{env.POSTGRES_PORT}}/${{env.POSTGRES_DB}}'
推荐阅读
- javascript - 在 cPanel 文件管理器中打开 public_html 中的 zip 后网站出现 403 错误
- node.js - MongooseError: operation `.deleteOne()`, `.deleteMany()`, 在我的不和谐机器人启动时。猫鼬 v5.12.14
- php - MySQL:按第二列排序——如果不为空——同时保持第一列顺序
- wordpress - WordPress插件在网站关闭时将电子邮件发送到特定的电子邮件地址?
- python - 如何在隐身模式下默认打开 Jupyter Notebook (Chrome)
- javascript - 电子邮件主题应根据单元格值更改
- python - 使用 api 获取自定义字段 ID 时如何使用凭据
- reactjs - 在 React 中使用带有地图的模拟数据制作多个提要
- javascript - 如何在 JavaScript 或 Node.js 中生成 MD5 密码字符串哈希?
- awk - awk 是二维数组还是类似于存储值的东西?