简体   繁体   English

在 github 操作 yml 文件中创建一个 Minio(S3) 容器

[英]Creating a Minio(S3) container inside a github actions yml file

I am trying to create an Minio/S3 container so I can run my test suite as an action on github. I currently have the following:我正在尝试创建一个 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:
      ...

I have tried the following permutations to get the minio container to work but with no success:我尝试了以下排列来让 minio 容器工作但没有成功:

volumes:
  - ./data:/data

volumes:
  - ./:/data

volumes:
  - .:/data

volumes:
  - /data:/data

And I even tried:我什至尝试过:

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

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

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

And I have tried using the -v flag to mount volumes before the --entrypoint flag.我已经尝试使用-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" ...

In an attempt to get it to work.试图让它工作。 But unfortunately I get:但不幸的是我得到:

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

And I can't run the minio server without any argument:(而且我无法在没有任何参数的情况下运行minio server :(

TL;DR; TL; 博士;

There exists an ongoing GitHub Actions Community thread concerning the lack of support for setting jobs.<job_id>.services.<service_id>.command and this existing question is very similar to yours .有一个正在进行的 GitHub Actions 社区线程关于缺乏对设置jobs.<job_id>.services.<service_id>.command这个现有问题与您的非常相似


You could extend the official image as suggested by @ahasbini then build and push your docker image to a Docker Registry and use your own image in the GitHub Actions jobs.<job_id>.services.<service_id>.image .你可以扩展官方图片的建议通过@ahasbini然后生成并把你的docker image码头工人注册和使用自己的imageGitHub的操作jobs.<job_id>.services.<service_id>.image For example:例如:

The Dockerfile : Dockerfile

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

Note : you can use the lazybit/minio image I built for this answer.注意:您可以使用我为此答案构建的lazybit/minio图像。

The job.<job_id>.services.<service_id> spec: 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

Notes :注意事项

  1. The minio/minio images do not currently have a HEALTHCHECK instruction set ( docker inspect minio/minio:latest --format {{.Config.Healthcheck}} ) so we need to set the --health-cmd in the jobs.<job_id>.services.<service_id>.options to hit the services livenessProbe endpoint to make sure the service is running before we start running the jobs.<job_id>.steps minio/minio镜像目前没有HEALTHCHECK指令集( docker inspect minio/minio:latest --format {{.Config.Healthcheck}} )所以我们需要在jobs.<job_id>.services.<service_id>.options设置--health-cmd jobs.<job_id>.services.<service_id>.options服务livenessProbe端点,以确保该服务正在运行,我们开始运行前jobs.<job_id>.steps
  2. I had some issues connecting to the service by name so I set the minio endpoint to locahost:9000 , the GitHub Actions are run in a Kubernetes Pod , they share the same network namespace and are accessible via localhost我在按名称连接到服务时遇到了一些问题,因此我将minio端点设置为locahost:9000 ,GitHub 操作在Kubernetes Pod中运行, 它们共享相同的网络命名空间并可通过localhost访问
  3. Accessing encrypted secrets in the jobs.<job_id>.services.<service_id>.env and jobs.<job_id>.steps.<step_id>.run访问jobs.<job_id>.services.<service_id>.envjobs.<job_id>.steps.<step_id>.run 加密机密
  4. Mounting a local directory as the volume backing the minio service using the github context 's workspace使用github上下文workspace将本地目录挂载为支持minio服务的卷

GitHub Actions minio 服务

The error is complaining about the --entrypoint "minio server /data" , not about the volumes configuration.错误是抱怨--entrypoint "minio server /data" ,而不是volumes配置。 It seems to be looking for a file called minio server /data rather than executing the command in a shell.它似乎在寻找一个名为minio server /data的文件,而不是在 shell 中执行命令。 Here's a good explanation of how --entrypoint flag works, the reason is because --entrypoint requires a file (either a binary file or a script) to execute and not the command with arguments to run.这是对--entrypoint标志如何工作的一个很好的解释,原因是因为--entrypoint需要一个文件(二进制文件或脚本)来执行,而不是运行带有参数的命令。 It appears that this is quite difficult to overcome as seen here as well.看起来这也很难克服,如这里所见。

The only suggestion I would think of is to build on top of the minio/minio Docker image with the arguments set in the Dockerfile and upload it to DockerHub so you could use it as the image instead.我想到的唯一建议是使用minio/minio设置的参数在minio/minio Docker 镜像Dockerfile ,并将其上传到 DockerHub,以便您可以将其用作image

Below is a sample Dockerfile you could use:以下是您可以使用的示例Dockerfile

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

I don't recommend this solution, but want to leave it out there in case somebody else is banging their head against a brick wall and wants a quick but convoluted solution.我不推荐这个解决方案,但我想把它留在那里以防其他人用头撞砖墙并想要一个快速但复杂的解决方案。


In our workflow we added:在我们的工作流程中,我们添加了:

    services:
      minio:
        # fixme: let's not depend on external unofficial image
        image: lazybit/minio
        ports:
          - 9000:9000
        env:
          MINIO_ROOT_USER: accesskey
          MINIO_ROOT_PASSWORD: password
        options: --name=minio --health-cmd "curl http://localhost:9000/minio/health/live"
    steps:
      - run: wget https://dl.min.io/client/mc/release/linux-amd64/mc
      - run: chmod +x ./mc
      - run: ./mc alias set minio http://127.0.0.1:9000 accesskey password
      - run: ./mc mb --ignore-existing minio/MY_BUCKET

I used the unofficial lazybit/minio image as it was the offical one would not run.我使用了非官方的lazybit/minio 图像,因为它是无法运行的官方图像。

Basically, the github action create one image with all the other images "merged".基本上,github 动作创建一个图像,所有其他图像“合并”。 So we knew we coud access the minio service at http://localhost:9000 .所以我们知道我们可以在http://localhost:9000访问 minio 服务。 Alas, there is no easy way to set a default bucket via env variable, but we had to create the bucket via mc . las,没有简单的方法可以通过 env 变量设置默认存储桶,但我们必须通过mc创建存储桶。


A few gotchas:一些陷阱:

  • Minio uses endpoint over url in its config Minio 在其配置中使用endpoint超过url
  • minio requires your use_path_style_endpoint to be set to true minio 需要你的use_path_style_endpoint被设置为 true

In our case we used a laravel app so we had to define the filesystem config like this:在我们的例子中,我们使用了一个 laravel 应用程序,所以我们必须像这样定义文件系统配置:

<?php


$envUsingMinIo = ['local', 'testing-local'];
$usesMinIo = in_array(
    needle: env('APP_ENV'),
    haystack: $envUsingMinIo,
    strict: true
);

return [
    'disks' => [
        ...,
        's3' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION', 'eu-west-1'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
            // the below 'endpoint' url is actually used for minio:
            'endpoint' => env('AWS_URL'),
            // use older urls:
            'use_path_style_endpoint' => $usesMinIo,
        ],
    ],
];

It may differ for your client.您的客户可能会有所不同。

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

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