Я установил действия Github для CI / CD, но я борюсь с подключением к базе данных.
Поскольку 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
Я получил эту ошибку в своих журналах:
![error](https://i.stack.imgur.com/9xW22.png)
Я видел, что переменные env установлены правильно:
![config](https://i.stack.imgur.com/muvez.png)
Я прочитал много ресурсов (по проблемам Github или Stackoverflow), но ни одна не решила мою проблема.
Заранее спасибо