GitHub Actions:如何在Windows或macOS上运行“services”?

8

我想测试一个CLI,它应该使用GitHub Actions连接到PostgreSQL和MySQL服务器,并在所有平台上进行测试:Linux、Windows和macOS。

我在如何运行Postgres service如何运行MySQL service中找到了说明,并将它们组合成了工作流程

name: Test
on: [push]

jobs:

    init_flow:
        name: 'Run MySQL and Postgres on ${{ matrix.os }}'
        runs-on: ${{ matrix.os }}
        strategy:
            fail-fast: false
            matrix:
                os: [ubuntu-latest, windows-latest, macOS-latest]

        # via https://github.com/actions/example-services/blob/master/.github/workflows/postgres-service.yml
        services:
            postgres:
                image: postgres:10.8
                env:
                    POSTGRES_USER: postgres
                    POSTGRES_PASSWORD: postgres
                    POSTGRES_DB: postgres
                ports:
                # will assign a random free host port
                - 5432/tcp
                # needed because the postgres container does not provide a healthcheck
                options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
            mysql:
                image: mysql:5.7
                env:
                    MYSQL_ROOT_PASSWORD: root
                ports:
                - 3306
                options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

        steps:
            - uses: actions/checkout@v1
            - run: node -v
              env:
                # use localhost for the host here because we are running the job on the VM.
                # If we were running the job on in a container this would be postgres
                POSTGRES_HOST: localhost
                POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }} # get randomly assigned published port
                MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}

但这似乎只在Linux上有效,而在Windows或macOS上并不起作用,请参见GitHub上的操作结果:Windows在执行“Initialize Containers”时失败,并显示“##[error]Container operation is only supported on Linux”,而macOS在执行“Set up job”时失败,并显示“##[error]File not found: 'docker'”。GitHub Actions的服务文档没有提到这只能在Linux上运行,但我也不太了解容器或Docker,可能会遗漏一些显而易见的东西。(顺便说一句,MySQL和PostgreSQL不必在同一操作系统上运行-它们只需可被主任务访问即可。)
是否有可能使用Windows和macOS在GitHub Actions中运行MySQL和PostgreSQL?如果不能,最佳解决方法是什么?
4个回答

8

通常情况下,Docker只支持在Linux环境下运行。我想知道它是否会在其他虚拟机上受到支持,所以我向Github提出了问题。这里是答案:

目前,Docker容器操作仅可以在GitHub托管的Linux环境中执行,并不支持其他环境(例如Windows和MacOS)。

更多详细信息请参考此处:https://help.github.com/en/actions/automating-your-workflow-with-github-actions/about-actions#types-...

我们注意到一些其他用户也报告了相同的问题,我们已向适当的工程团队报告此问题作为功能请求。

参考资料:https://github.community/


2

这真是太遗憾了。有什么办法可以解决这个问题吗?(也许可以在不同的并行Linux作业中运行这些容器,并从Windows / macOS或类似系统中访问它们?) - janpio
我想不出解决方法。你可能需要再等一会儿,直到它退出 beta 版本。根据这份文档,Docker 和 Docker Compose 似乎可以在 Linux 和 Windows 上使用,但在 MacOS 上不行。https://help.github.com/en/articles/software-in-virtual-environments-for-github-actions - peterevans
Windows上的Docker运行程序只能运行Windows容器 :( - Seyf

2
一个替代方法是使用外部数据库。
一个简单的方法是使用Heroku免费的服务:
- 对于Postgres,可以使用Heroku Postgres。 - 对于MySQL,可以使用ClearDBJawsDB插件。
它们都提供了一些空间和限制,但在我的情况下,现在这可能已经足够了。

0

对于MySQL,我找到了一个(临时的[1])解决方法:

根据GitHub Actions虚拟环境中的软件,我了解到所有操作系统当前都在3306端口上运行具有凭证root:root的本地安装的MySQL 5.7。您可以在作业中使用此MySQL实例。

不幸的是,对于我来说,未安装PostgreSQL。

[1] 我记得读到GitHub Actions产品经理告诉人们,安装的软件可能会变化,尤其是数据库可能很快消失(但无法回忆或找到该链接,可能在GitHub社区、GitHub Actions某处)

结果发现MySQL凭证root:root仅适用于Linux,我找不到Windows和macOS的有效凭证。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接