简体   繁体   English

在容器中运行步骤时,Github Actions工作流程失败

[英]Github Actions workflow fails when running steps in a container

I've just started setting up a Github-actions workflow for one of project.I attempted to run the workflow steps inside a container with this workflow definition: 我刚刚开始为其中一个项目设置Github-actions工作流,我尝试使用以下工作流定义在容器内运行工作流步骤:

  name: TMT-Charts-CI

  on:
    push:
      branches:
        - master
        - actions-ci

  jobs:
    build:
      runs-on: ubuntu-latest
      container:
        image: docker://alpine/helm:2.13.0

      steps:
      - name: Checkout Code
        uses: actions/checkout@v1

      - name: Validate and Upload Chart to Chart Museum
        run: |
          echo "Hello, world!"
          export PAGER=$(git diff-tree --no-commit-id --name-only -r HEAD)
          echo "Changed Components are  => $PAGER"
          export COMPONENT="NOTSET"
          for CHANGE in $PAGER; do ENV_DIR=${CHANGE%%/*}; done
          for CHANGE in $PAGER; do if [[ "$CHANGE" != .* ]] && [[ "$ENV_DIR" == "${CHANGE%%/*}" ]]; then export COMPONENT="$CHANGE"; elif [[ "$CHANGE" == .* ]]; then echo "Not a Valid Dir for Helm Chart" ; else echo "Only one component per PR should be changed" && exit 1; fi; done
          if [ "$COMPONENT" == "NOTSET" ]; then echo "No component is changed!" && exit 1;  fi
          echo "Initializing Component => $COMPONENT"
          echo $COMPONENT | cut -f1 -d"/"
          export COMPONENT_DIR="${COMPONENT%%/*}"
          echo "Changed Dir => $COMPONENT_DIR"
          cd $COMPONENT_DIR
          echo "Install Helm and Upload Chart If Exists"
          curl -L https://git.io/get_helm.sh | bash
          helm init --client-only

But Workflow fails stating the container stopped due immediately. 但是工作流无法说明容器已立即停止。

错误说明

I have tried many images including "alpine:3.8" image described in official documentation, but container stops. 我尝试了许多图像,包括官方文档中描述的“ alpine:3.8”图像,但是容器停止了。

According to Workflow syntax for GitHub Actions , in the Container section: "A container to run any steps in a job that don't already specify a container." 根据GitHub Actions的工作流语法 ,在“容器”部分中:“一个容器,用于运行作业中尚未指定容器的任何步骤。” My assumption is that the container would be started and the steps would be run inside the Docker container. 我的假设是容器将启动,并且步骤将在Docker容器内运行。

We can achieve this my making custom docker images, Actually Github runners somehow stops the running container after executing the entrypoint command, I made docker image with entrypoint the make container alive, so container doesn't die after start. 我们可以通过制作自定义docker映像来实现这一点,实际上Github运行程序在执行entrypoint命令后以某种方式停止了正在运行的容器,我使带有入口点的docker映像使make容器处于活动状态,因此容器在启动后不会死亡。

Here is the custom Dockerfile ( https://github.com/rizwan937/Helm-Image ) You can publish this image to dockerhub and use it in workflow file like 这是自定义的Dockerfile( https://github.com/rizwan937/Helm-Image )您可以将该图像发布到dockerhub并在工作流文件中使用,例如

 container:
   image: docker://rizwan937/helm

You can add this entrypoint to any docker image so that It remains alive for further steps execution. 您可以将此入口点添加到任何Docker映像,以便它保持活动状态以便进一步执行步骤。

This is a temporary solution, if anyone have better one, let me know. 这是一个临时解决方案,如果有人有更好的解决方案,请告诉我。

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

相关问题 Github 将容器推送到 Github 容器注册表的操作工作流程失败并显示“未经身份验证” - Github Actions workflow for pushing a container to Github Container Registry fails with "unauthenticated" Github actions 在容器中运行步骤 - Github actions run steps in container Github 操作工作流到 docker 容器环境 - Github actions workflow to docker container environment 在私有 docker 容器中运行整个 GitHub 操作工作流作业 - Run entire GitHub Actions workflow job in private docker container 当我使用私有容器时,GitHub Actions flutter-action 作业失败 - GitHub Actions flutter-action job fails when I use a private container 使用 GitHub 操作在自定义 docker 容器内运行步骤时出现问题 - Problem running steps inside custom docker container using GitHub Action Github 操作中的手动工作流触发器 - Manual workflow triggers in Github Actions 如何在 GitHub Actions 中失败时重新运行 docker 容器,但工作流仍然通过? - How to rerun a docker container on failure in GitHub Actions, but still have the workflow pass? github 工作流程:连接到 docker 容器时出现“ECONNREFUSED 127.0.0.1:***”错误 - github workflow: “ECONNREFUSED 127.0.0.1:***” error when connecting to docker container 将 docker 图像推送到 ECR 时,Github 操作失败 - Github actions fails when pushing docker image to ECR
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM