在 GitHub Action 中,如何覆盖服务的入口点?

2024-02-25

我需要在 GitHub 操作中定义一个服务,并通过向其添加参数来覆盖其入口点。我怎样才能做到这一点?

这是我正在尝试翻译的一个可以运行的 docker-compose。

version: '2'
services:
  config:
    build: .
    links:
      - etcd

  etcd:
    image: microbox/etcd:2.1.1
    entrypoint: "etcd --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://0.0.0.0:2379"
    hostname: etcd
    container_name: build_etcd
    expose:
        - 2379

这是我的操作以及我最初认为它是如何工作的......

name: Node CI
on: [push]
jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [12.x]

    services:
      etcd:
        image: microbox/etcd:2.1.1
        options: --entrypoint 'etcd --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://0.0.0.0:2379'

    steps:
      ...

然而,在初始化容器时,它会崩溃,因为它运行的命令不正确......

/usr/bin/docker create --name 1062a703242743a29bbcfda9fc19c823_microboxetcd211_3767cc --label 488dfb --network github_network_244f1c7676b8488e99c66694d06a21f2 --network-alias etcd --entrypoint 'etcd --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://0.0.0.0:2379' -e GITHUB_ACTIONS=true microbox/etcd:2.1.1

错误是unknown flag: --listen-client-urls

我想其实应该是这样的……

/usr/bin/docker create --name 1062a703242743a29bbcfda9fc19c823_microboxetcd211_3767cc --label 488dfb --network github_network_244f1c7676b8488e99c66694d06a21f2 --network-alias etcd --entrypoint etcd -e GITHUB_ACTIONS=true microbox/etcd:2.1.1 --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://0.0.0.0:2379

有什么想法可以在 GitHub Action Service 定义中使用传递给可执行文件的参数来覆盖入口点吗?


据我所知,这是不可能的。

最简单的方法是使用入口点覆盖运行 docker create 命令,并将其参数作为构建步骤。像这样的事情:

name: Node CI
on: [push]
jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      ...
      - run: docker create --name build_etcd --network-alias etcd --entrypoint etcd microbox/etcd:2.1.1 --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://0.0.0.0:237
      ...

然而,我最终要做的就是构建并运行 docker-compose.yml,我已经知道它是工作流程中的一个步骤。这是 docker-compose。

version: '3'
services:
  config:
    build: .
    links:
      - etcd

  etcd:
    image: microbox/etcd:2.1.1
    entrypoint: "etcd --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://0.0.0.0:2379"
    hostname: etcd
    container_name: build_etcd
    expose:
        - 2379

以下是相关步骤:

steps:
    - uses: actions/checkout@v2
    - name: Build
      run: docker-compose build --pull --force-rm config
    - name: Test
      run: docker-compose run --rm config test
    ...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 GitHub Action 中,如何覆盖服务的入口点? 的相关文章

随机推荐