[英]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.