Eho*_*ret 5 docker docker-compose github-actions
我有一个用于 PR 的 GitHub Action 工作流程,其中包含一个执行一些 NET Core 虚拟测试的作业,这些测试需要 PostgreSQL + SQL Serve 的实例。
工作定义:
run-test:
needs: [lint-commit, lint-code]
strategy:
matrix:
os: [ubuntu-latest]
dotnet: [3.1.201]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Build the docker-compose stack
run: docker-compose --file "./MessingUp.Tests/docker-compose.yml" up --detach
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ matrix.dotnet }}
- name: Run Tests
run: dotnet test
Run Code Online (Sandbox Code Playgroud)
和 docker compose 文件,./MessingUp.Tests/docker-compose.yml:
version: "3.7"
services:
sqlserver:
image: mcr.microsoft.com/mssql/server:2019-CU3-ubuntu-18.04
restart: unless-stopped
environment:
- MSSQL_PID=Express
- ACCEPT_EULA=Y
- SA_PASSWORD=MyPassword!
ports:
- 1433:1433
postgres:
image: postgres:12.3-alpine
restart: unless-stopped
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
- POSTGRES_DB=postgres
- POSTGRES_USER=root
- POSTGRES_PASSWORD=root
command:
- postgres
- -c
- max_prepared_transactions=100
ports:
- 5432:5432
# Needed because the postgres container does not provide a health check
healthcheck:
test: pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
interval: 1m30s
timeout: 10s
retries: 3
start_period: 40s
Run Code Online (Sandbox Code Playgroud)
长话短说,上面的代码有效,我唯一的问题是我想知道如何使用docker-compose,以防我不仅使用ubuntu-latest:
os: [windows-latest, macos-latest, ubuntu-latest]
Run Code Online (Sandbox Code Playgroud)
因为在非 ubuntu 最新的操作系统中,它并没有真正起作用:
windows-latest:
Build the docker-compose stack15s
##[error]Process completed with exit code 1.
Run docker-compose --file "./MessingUp.Tests/docker-compose.yml" up --detach
Creating network "messinguptests_default" with the default driver
Pulling sqlserver (mcr.microsoft.com/mssql/server:2019-CU3-ubuntu-18.04)...
2019-CU3-ubuntu-18.04: Pulling from mssql/server
image operating system "linux" cannot be used on this platform
##[error]Process completed with exit code 1.
Run Code Online (Sandbox Code Playgroud)
macos-latest:
Build the docker-compose stack0s
##[error]Process completed with exit code 127.
Run docker-compose --file "./MessingUp.Tests/docker-compose.yml" up --detach
/Users/runner/runners/2.169.1/work/_temp/ccb3e6a1-fc89-4099-9bf2-2f4ca4bb1fb8.sh: line 1: docker-compose: command not found
##[error]Process completed with exit code 127.
Run Code Online (Sandbox Code Playgroud)
使用时输出ubuntu-latest:
Build the docker-compose stack43s
Run docker-compose --file "./MessingUp.Tests/docker-compose.yml" up --detach
Creating network "messinguptests_default" with the default driver
Pulling sqlserver (mcr.microsoft.com/mssql/server:2019-CU3-ubuntu-18.04)...
2019-CU3-ubuntu-18.04: Pulling from mssql/server
Digest: sha256:e064843673f08f22192c044ffa6a594b0670a3eb3f9ff7568dd7a65a698fc4d6
Status: Downloaded newer image for mcr.microsoft.com/mssql/server:2019-CU3-ubuntu-18.04
Pulling postgres (postgres:12.3-alpine)...
12.3-alpine: Pulling from library/postgres
Digest: sha256:bd975ce4ddb0cf271a3c0132afaa16894ccdbadd0a1e81aa5d1b12727bb43779
Status: Downloaded newer image for postgres:12.3-alpine
Creating messinguptests_sqlserver_1 ...
Creating messinguptests_postgres_1 ...
Creating messinguptests_sqlserver_1 ... done
Creating messinguptests_postgres_1 ... done
Run Code Online (Sandbox Code Playgroud)
我看到两个不同的问题,为什么docker-compose命令在windows-latest和上失败mac-os。
windows-latestrunner 使用Windows 容器作为 Docker 后端引擎,并且您尝试使用基于 Linux 的映像 ( mcr.microsoft.com/mssql/server:2019-CU3-ubuntu-18.04) 与 Windows 后端不兼容。这就是出现错误消息的原因:
\n\n\n拉取 sqlserver (mcr.microsoft.com/mssql/server:2019-CU3-ubuntu-18.04)...\n2019-CU3-ubuntu-18.04: 从 mssql/server 拉取\n无法在操作系统“linux”上使用映像这个平台\n\n
如果您访问专用于所用映像的 DockerHub 页面,您可以阅读:
\n\n\nLinux 上的 Microsoft SQL Server for Docker Engine的官方映像。
\n
您应该使用与 Windows 容器后端兼容的不同映像,以便让容器在windows-latest. 目前,有两个官方镜像兼容Windows容器后端:
上述两个 DockerHub 页面都提到:
\n\n\n适用于Windows 容器的 Microsoft SQL Server Express 。
\n
考虑到这一点,您应该在跑步者上使用其中之一windows-latest来使docker-compose命令正常工作。
您可以在此处阅读有关 Docker 中的 SQLServer 的更多信息。
\n说到macos-latest跑步者,这种情况下的错误消息略有不同:
\n\n\n/Users/runner/runners/2.169.1/work/_temp/ccb3e6a1-fc89-4099-9bf2-2f4ca4bb1fb8.sh:第 1 行:docker-compose:找不到命令\n\n
没有docker-compose安装二进制文件,因此无法找到它。如果您看到GitHub Actions 虚拟环境页面,您可以探索每个运行器上包含的软件。两者都包含,ubuntu-latest并且windows-latest已经docker-compose包含命令但不包含macos-latest. 由于一些许可问题,它不包含它。您必须使用以下命令自行安装该命令brew:
[...]\nruns-on: macOS-latest\nsteps:\n - name: Install docker\n run: |\n brew install docker docker-machine docker-compose\n sudo docker \xe2\x80\x93version\n[...]\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
943 次 |
| 最近记录: |