Github Actions - 创建一个快速运行的操作

4
我正在创建一个 Github Docker 容器动作,它涉及许多依赖项,包括 Python、Node.js、PyPI 包和 npm 包。为了加快动作速度,我将很多依赖项的安装从入口点移到了 Dockerfile 中。现在我的动作运行得非常快,但每次构建动作需要花费很长时间。
有没有一种方法可以预先构建该动作,或者我需要将自己的动作 Docker 镜像发布到某个仓库,并从我的自定义镜像中提供?以下是我的 Dockerfile 供参考。
FROM python:3

LABEL "com.github.actions.name"="kedro-action"
LABEL "com.github.actions.description"="A Github Action to run kedro commands"
LABEL "com.github.actions.icon"="it-branch"
LABEL "com.github.actions.color"="black"

LABEL "repository"="http://github.com/WaylonWalker/kedro-action"
LABEL "maintainer"="Waylon Walker <waylon@waylonwalker.com>"

RUN apt-get update
RUN apt-get install -y jq

ENV PYENV_ROOT /root/.pyenv
ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH
RUN curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash

### INSTALL PYTHON ###
RUN pyenv install 3.7.6
RUN pyenv global 3.7.6
RUN python -m pip install --upgrade pip
RUN pip install kedro
RUN pip install kedro-viz

### INSTALL NODEJS ###
RUN apt-get install curl -y
RUN curl -sL https://deb.nodesource.com/setup_11.x | bash -
RUN apt-get install nodejs -y

### CLONE KEDRO-STATIC-VIZ ###
RUN mkdir ~/build_dir && cd ~/build_dir
RUN git clone https://github.com/WaylonWalker/kedro-static-viz.git
RUN cd kedro-static-viz
RUN npm install -g gatsby-cli
RUN cd kedro-static-viz && npm install && npm audit fix


ADD entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
1个回答

1
你可以预先构建 Docker 镜像,然后在 action.yml 文件中指定预构建的镜像,而不是 Dockerfile。请参阅文档 此处
这是我其中一个操作的示例,它已经 预构建在此
runs:
  using: 'docker'
  image: 'docker://peterevans/dockerhub-description:2.1.0'

请务必这样做!Github让人们发布图像而不是Dockerfiles的方式非常不清晰,这让我感到非常恼火。还有一件小事。您应该定期重新构建镜像,以获取最新的操作系统包,以修复安全漏洞。 - Michael Parker

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接