【问题标题】:Creating a Minio(S3) container inside a github actions yml file在 github 操作 yml 文件中创建 Minio(S3) 容器
【发布时间】:2021-01-09 20:52:38
【问题描述】:

我正在尝试创建一个 Minio/S3 容器,以便我可以在 github 上将我的测试套件作为操作运行。我目前有以下:

name: Run Tests
on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-18.04

    services:
      postgres:
        ...

      minio:
        image: minio/minio
        volumes:
          - /data
        ports:
          - 9000:9000
        env:
          MINIO_ACCESS_KEY: minio
          MINIO_SECRET_KEY: minio123
        options: --entrypoint "minio server /data" --health-cmd "curl -f http://localhost:9000/minio/health/live" --health-interval 10s --health-timeout 5s --health-retries 5

    steps:
      ...

我尝试了以下排列以使 minio 容器工作但没有成功:

volumes:
  - ./data:/data

volumes:
  - ./:/data

volumes:
  - .:/data

volumes:
  - /data:/data

我什至尝试过:

options: --entrypoint "mkdir /data; minio server /data" ...

options: --entrypoint "minio server /tmp" ...

options: --entrypoint ["minio server", "/tmp"] ...

我已经尝试使用-v 标志在--entrypoint 标志之前挂载卷。

options: -v /s3_data:/data --entrypoint "minio server /data" ...

options: -v ${{ github.workspace }}/s3_data:/data --entrypoint "minio server /data" ...

options: -v ${{ github.workspace }}/s3_data:/data:rw --entrypoint "minio server /data" ...

试图让它工作。但不幸的是我得到:

starting container process caused: exec: "minio server /data": stat minio server /data: no such file or directory: unknown

而且我不能在没有任何参数的情况下运行minio server :(

【问题讨论】:

  • 容器内需要挂载什么?是 GitHub 存储库中的目录吗?

标签: docker yaml containers github-actions minio


【解决方案1】:

TL;DR;

There exists an ongoing GitHub Actions Community thread 关于不支持设置jobs.<job_id>.services.<service_id>.commandthis existing question is very similar to yours.


You could extend the official image 按照@ahasbini 的建议,然后构建并将您的docker image 推送到Docker Registry,并在GitHub Actions jobs.<job_id>.services.<service_id>.image 中使用您自己的image。例如:

Dockerfile:

FROM minio/minio
CMD ["server", "/data", "--address=0.0.0.0:9000"]

注意:您可以使用我为此答案构建的lazybit/minio 图像。

job.<job_id>.services.<service_id> 规范:

jobs:
  ...
  minio:
    name: minio
    runs-on: ubuntu-latest
    services:
      minio:
        image: lazybit/minio
        ports:
          - 9000:9000
        env:
          MINIO_ACCESS_KEY: ${{ secrets.MINIO_ACCESS_KEY }}
          MINIO_SECRET_KEY: ${{ secrets.MINIO_SECRET_KEY }}
        volumes:
          - ${{ github.workspace }}/data:/data
        options: --name=minio --health-cmd "curl http://localhost:9000/minio/health/live"
    steps:
      - run: pip3 install minio
      - run: |
            python3 - <<'EOF'
            from minio import Minio
            from minio.error import ResponseError

            try:
                minio = Minio(
                    'localhost:9000',
                    access_key='${{ secrets.MINIO_ACCESS_KEY }}',
                    secret_key='${{ secrets.MINIO_SECRET_KEY }}',
                    secure=False
                )
            except Exception as ex:
                raise

            minio.make_bucket('foo')
            minio.make_bucket('bar')
            print(f'{minio.list_buckets()}')
            EOF

注意事项

  1. minio/minio 图像当前没有HEALTHCHECK 指令集(docker inspect minio/minio:latest --format {{.Config.Healthcheck}}),因此我们需要在jobs.&lt;job_id&gt;.services.&lt;service_id&gt;.options 中设置--health-cmd 以点击the services livenessProbe endpoint 以确保服务在之前运行我们开始运行jobs.&lt;job_id&gt;.steps
  2. 我在按名称连接到服务时遇到了一些问题,因此我将minio 端点设置为locahost:9000,GitHub 操作在Kubernetes Podthey share the same network namespace and are accessible via localhost 中运行
  3. jobs.&lt;job_id&gt;.services.&lt;service_id&gt;.envjobs.&lt;job_id&gt;.steps.&lt;step_id&gt;.run 中访问encrypted secrets
  4. 使用github contextworkspace 安装本地目录作为支持minio 服务的卷

【讨论】:

【解决方案2】:

错误是抱怨--entrypoint "minio server /data",而不是volumes 配置。它似乎在寻找一个名为 minio server /data 的文件,而不是在 shell 中执行命令。这是good explanation--entrypoint 标志如何工作的--entrypoint,原因是--entrypoint 需要一个文件(二进制文件或脚本)来执行,而不是带有参数的命令才能运行。正如here 所见,这似乎很难克服。

我能想到的唯一建议是在 minio/minio Docker 映像之上构建并使用 Dockerfile 中设置的参数并将其上传到 DockerHub,以便您可以将其用作 image

以下是您可以使用的示例Dockerfile

FROM minio/minio
ENTRYPOINT ["/usr/bin/docker-entrypoint.sh", "minio", "server", "/data"]

【讨论】:

    猜你喜欢
    • 2021-11-22
    • 1970-01-01
    • 1970-01-01
    • 2022-11-11
    • 1970-01-01
    • 2020-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多