将Docker映像变量从Makefile传递到.gitlab-ci.yaml文件中

问题描述 投票:0回答:1

我已经使用makefile中的脚本定义和构建了docker镜像,并希望将这些镜像作为参数传递到我的gitlab-ci中,以进行进一步的分析。这两个文件都位于gitlab的同一项目存储库中。

这是我的代码:

Makefile

DOCKER_REGISTRY := registry-link
DOCKER_RELEASE_REPO := repo-name
DOCKER_RELEASE_IMAGE1 := ${DOCKER_REGISTRY}/${DOCKER_RELEASE_REPO}/${DOCKER_IMAGE_NAME1}
DOCKER_RELEASE_IMAGE2 := ${DOCKER_REGISTRY}/${DOCKER_RELEASE_REPO}/${DOCKER_IMAGE_NAME2}

tag: .next-version
    $(eval TAG := v$(shell cat .next-version))

release: tag
    docker build --rm -t ${DOCKER_RELEASE_IMAGE1}:${TAG} -f 1.Dockerfile .
    docker build --rm -t ${DOCKER_RELEASE_IMAGE2}:${TAG} -f 2.Dockerfile .
    docker push ${DOCKER_RELEASE_IMAGE1}:${TAG}
    docker push ${DOCKER_RELEASE_IMAGE2}:${TAG}

.gitlab-ci.yaml

stages:
  - release
  - lint

docker:release:
  stage: release
  script:
    - make release

lint:docker-image
  stage: lint
  image: image-link
  script:
    - /src/lint.sh $DOCKER_RELEASE_IMAGE1
    - /src/lint.sh $DOCKER_RELEASE_IMAGE2

lint.sh

docker pull $1

...checks against $1, image parameter passed...

我将如何去做?

docker makefile gitlab gitlab-ci
1个回答
0
投票

您可以存档variables文件并在下一个管道作业中将其来源。

更新为makefile

...
release: tag
    <docker build and push commands>
    echo "export DOCKER_RELEASE_IMAGE1=${DOCKER_RELEASE_IMAGE1}:${TAG};" >> variables
    echo "export DOCKER_RELEASE_IMAGE2=${DOCKER_RELEASE_IMAGE2}:${TAG};" >> variables

更新为.gitlab-ci.yaml

docker:release:
  ...
  artifacts:
    paths:
      - variables

lint:docker-image
  ...
  script:
    - source variables
    - <your lint commands>
© www.soinside.com 2019 - 2024. All rights reserved.