简体   繁体   English

GitHub 操作:如何在 Windows 或 macOS 上运行“服务”?

[英]GitHub Actions: How to run `services` on Windows or macOS?

I want to test a CLI that should connect to PostgreSQL and MySQL servers using GitHub Actions, on all platforms if possible: Linux, Windows and macOS. I want to test a CLI that should connect to PostgreSQL and MySQL servers using GitHub Actions, on all platforms if possible: Linux, Windows and macOS.

I found instructions on how to run a Postgres service and how to run a MySQL service and combined these into a workflow :我找到了有关如何运行 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] }}

But this only seems to work on Linux, not Windows or macOS, see the results of the action on GitHub:但这似乎只适用于 Linux,而不是 Windows 或 macOS,请参阅 GitHub 上的操作结果:

Windows fails during Initialize Containers with ##[error]Container operation is only supported on Linux , macOS even during Set up job with ##[error]File not found: 'docker' . Windows 在Initialize Containers期间失败##[error]Container operation is only supported on Linux , macOS 即使在使用##[error]File not found: 'docker' Set up job期间也是如此。

GitHub Actions services docs do not mention that this will only work on Linux, but I also do not know much about containers or Docker so might be missing something obvious. GitHub Actions services文档没有提到这仅适用于 Linux,但我对容器或 Docker 也不太了解,因此可能会遗漏一些明显的东西。

(It is not important that MySQL and PostgreSQL run on the same operating system by the way - they only have to be accessible by the main job.) (顺便说一句,MySQL 和 PostgreSQL 在同一操作系统上运行并不重要——它们只需要由主作业访问。)

Is it possible to run MySQL and PostgreSQL for GitHub Actions using Windows and macOS?是否可以使用 Windows 和 macOS 为 GitHub 操作运行 MySQL 和 PostgreSQL 操作?
If not, what is the best workaround here?如果没有,这里最好的解决方法是什么?

Well, normally it's supported only on Linux.好吧,通常它仅在 Linux 上受支持。 I was wondering if it would be supported in other VMs, so I ask Github.我想知道其他虚拟机是否支持它,所以我问 Github。 Here the answer:这里是答案:

Currently, Docker container actions can only execute in the GitHub-hosted Linux environment, and is not supported on other environments (such as Windows and MacOS).目前,Docker 容器动作只能在 GitHub 托管的 Linux 环境中执行,其他环境(如 Windows 和 MacOS)不支持。

More details please reference here: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/about-actions#types- ...更多细节请参考这里: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/about-actions#types- ...

We notice that some other users also had reported the same question, we had reported this as a feature request to the appropriate engineering team.我们注意到其他一些用户也报告了相同的问题,我们已将此作为功能请求报告给相应的工程团队。

Ref: https://github.community/参考: https://github.community/

I'm not sure that it's possible yet.我不确定这是否可能。 I know that container actions only work on Linux virtual machines at the moment, as you can see from the documentation here.我知道容器操作目前仅适用于 Linux 虚拟机,正如您从此处的文档中看到的那样。

https://help.github.com/en/articles/about-actions#types-of-actions https://help.github.com/en/articles/about-actions#types-of-actions

services are using containers, so it would make sense that it doesn't work on Windows and MacOS yet. services正在使用容器,所以它在 Windows 和 MacOS 上不起作用是有道理的。

An alternative workaround is to use an external database of course.当然,另一种解决方法是使用外部数据库。

A simple way to do this might be the free tiers of Heroku's offering:一个简单的方法可能是 Heroku 提供的免费层:

They all give you tiny space and limits, but in my case this will probably be enough for now.它们都给你很小的空间和限制,但就我而言,这可能就足够了。

For MySQL, I found a (temporary[1]) workaround: 对于 MySQL,我找到了一个(临时 [1])解决方法:

Per Software in virtual environments for GitHub Actions I learned that all operating systems currently have a local installation of MySQL 5.7 running on port 3306 with credentials root:root . GitHub 操作的虚拟环境中的每个软件我了解到,所有操作系统当前都在本地安装了 MySQL 5.7,在端口 3306 上运行,凭据为root:root You can use this MySQL instance in your jobs.您可以在作业中使用此 MySQL 实例。

Unfortunately for me PostgreSQL is not installed.对我来说不幸的是 PostgreSQL 没有安装。

[1] I recall reading a product manager of GitHub Actions telling people that the installed software might change and especially the databases might go away soon unfortunately (can't recall or find the link though, somewhere in GitHub Community, GitHub Actions) [1] I recall reading a product manager of GitHub Actions telling people that the installed software might change and especially the databases might go away soon unfortunately (can't recall or find the link though, somewhere in GitHub Community, GitHub Actions)

Turns out the MySQL credentials root:root also only work on Linux, I could not find working ones for Windows and macOS.原来 MySQL 凭证root:root也只适用于 Linux,我找不到适用于 Windows 和 macOS 的凭证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM