【发布时间】:2020-11-04 13:57:17
【问题描述】:
我正在尝试使用 GitHub Actions 为我的测试启动 Postgres 容器。我有一个名为 build.sh 的脚本,当通过 GitHub 操作调用 npm run build 时会调用该脚本。该脚本调用restore-schema.sh(如下所示)。
这里的问题是当restore-schema.sh 运行时,我不断收到Error: no such container: postgres。 GitHub 操作将容器命名为任意字符串。有没有办法可以在图像上运行 docker exec 或以某种方式命名 GitHub 操作正在创建的 postgres 容器?我已经查看了这两个文档,但无济于事。
我应该怎么做?我注意到在 Docker run ps 屏幕截图中,它显示了命令 docker-entrypoint.sh。我应该改用这个吗?我是否在 .github/workflows/ 中指定 Dockerfile?
我尝试包含尽可能多的相关信息 - 如果您需要任何其他信息,请发表评论。
来自 GitHub Actions 的屏幕截图
build.sh
#!/bin/sh
# Import core db schema
./.deploy/postgres/restore-schema.sh
.deploy/postgres/restore-schema.sh
#!/bin/sh
docker exec -it postgres psql \
--username postgres \
--password dev \
coredb < .deploy/postgres/db-schema.sql
.github/workflows/test-api-gateway.yml
name: API Gateway CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master, develop ]
jobs:
build:
runs-on: ubuntu-latest
services: # Serivce containers to run with `container-job`
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_USER: postgres
POSTGRES_DB: coredb
POSTGRES_PASSWORD: dev
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
strategy:
matrix:
node-version: [14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: docker ps
- run: chmod +x build.sh .deploy/postgres/restore-schema.sh
- run: npm ci
- run: npm run build --if-present
- run: npm test
【问题讨论】:
标签: docker github-actions