Gitlab 在 docker 镜像中运行阶段

时间:2021-04-28 06:30:43

标签: docker gitlab continuous-integration gitlab-ci

我是 GitLab 的新手,我正在尝试设置 CI 管道,我想在其中运行并从 docker 映像内部对脚本进行 terraform 处理,以确保我已经安装并构建了所有必要的基础映像。

目前,我对官方文档进行了一些调查的 CI 管道如下所示:

 stages:
  - terraform:check

.base-terraform:
  image:
    name: "hashicorp/terraform"
    entrypoint: [""]

  before_script:
    - export GOOGLE_APPLICATION_CREDENTIALS=${GOOGLE_APPLICATION_CREDENTIALS}
    - terraform version

tf-fmt:
  stage: terraform:check
  extends: .base-terraform
  script:
    - make fmt
  needs: []

使用上面的 YAML 文件,它会下载我不想要的最新版本的 Terraform(>=0.15),而且我还需要其他依赖项,例如 make 等。所以我在想是否有我可以构建自己的自定义映像使用的任何方式分阶段扩展,以便 CI/CD 运行所需的所有依赖项。

我的 DockerFile 看起来像:

FROM python:3.7-slim

RUN apt-get update && apt-get install -y curl git-core curl build-essential openssl libssl-dev unzip wget

RUN wget -O terraform.zip https://releases.hashicorp.com/terraform/0.13.0/terraform_0.13.0_linux_amd64.zip && \
    unzip terraform.zip  && \
    mv terraform /usr/local/bin/

RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.17.0/bin/linux/amd64/kubectl && \
    chmod +x ./kubectl &&  \
    mv ./kubectl /usr/local/bin/kubectl

WORKDIR /src

COPY . .

我的想法是否正确?或者在 gitlab 中有更简单的方法吗?我使用 buildkite 完成了这样的任务,因为我在过去的经验中使用 buildkite 作为我的 CI 工具。

0 个答案:

没有答案