gpt4 book ai didi

continuous-integration - Concourse - 构建 docker 镜像时上一步缺少版本

转载 作者:行者123 更新时间:2023-12-05 08:03:28 24 4
gpt4 key购买 nike

目标:为运行 JUnit 测试、打包、构建 docker 镜像并最终将该镜像推送到 Amazon Elastic Container Registry 的 spring boot 应用程序构建持续集成管道。

我构建的管道能够运行 maven 测试阶段,运行 maven 包,但是在执行构建 docker 镜像的任务时会报错。

下面是管道的屏幕截图。

concourse pipeline

如您所见,构建和推送作业部分失败。下面是构建和推送作业中包含的任务的屏幕截图。

buil-and-push-tasks-list

我们看到错误上一步缺少版本。

我的流水线是这样的

resources:
- name: session-management-service-repo
type: git
icon: github
source:
branch: develop
uri: ((source_url))
username: ((myusername))
password: ((mypassowrd)

- name: ecr-docker-reg
type: registry-image
icon: docker
source:
aws_access_key_id: ((access_key_id))
aws_secret_access_key: ((secret_access_key))
aws_region: ((region))
repository: srm-session-management-service
tag: latest

resource_types:
- name: registry-image
type: docker-image
source:
repository: registry:5000/srm/registry-image-resource
insecure_registries:
- registry:5000

jobs:
- name: test
public: true
plan:
- get: session-management-service-repo
trigger: true
- task: mvn-test-task
file: session-management-service-repo/ci/tasks/maven-test.yml

- name: build-and-push
public: true
serial: true
plan:
- get: session-management-service-repo
trigger: true
passed: [test]
- task: mvn-package-task
file: session-management-service-repo/ci/tasks/maven-package.yml
- task: build-image-task
privileged: true # oci-build-task must run in a privileged container
file: session-management-service-repo/ci/tasks/build-image.yml
- put: ecr-docker-reg
params: {image: image/image.tar}

我在这里构建了一个自定义资源类型,它是从 concourse/registry-image-resource 扩展而来的。基本上,我想在资源中包含一些证书,以便在我在代理后面运行时将图像上传到 ECR 时不会遇到任何问题。因此,此自定义资源的 docker 文件如下所示。我从这个 dockerfile 构建图像,并将图像推送到运行 concourse 的同一台服务器上,因此在私有(private) docker 注册表中。稍后在管道中,如您所见,我从自定义 docker 注册表中提取此资源类型...检查资源部分中的 ecr-docker-reg。 (这就是我想要做的。)

FROM concourse/registry-image-resource

ARG HTTP_PROXY=http://username:password@myhost:port
ARG HTTPS_PROXY=http://username:password@myhost:port
ARG NO_PROXY=localhost,*.myhost.com,127.0.0.1,.myhost.com

ENV http_proxy=${HTTP_PROXY}
ENV https_proxy=${HTTPS_PROXY}
ENV no_proxy=${NO_PROXY}
ENV HTTP_PROXY=${HTTP_PROXY}
ENV HTTPS_PROXY=${HTTPS_PROXY}
ENV NO_PROXY=${NO_PROXY}

COPY certificates/Cert-CA-bundle.crt /etc/pki/tls/certs/ca-bundle.crt

#RUN apk update && apk add --no-cache curl

maven 打包任务和附带的脚本如下所示

---
platform: linux
image_resource:
type: docker-image
source:
repository: maven
inputs:
- name: session-management-service-repo
run:
path: /bin/sh
args: ["./session-management-service-repo/ci/scripts/maven-package.sh"]
outputs:
- name: session-management-service-repo-out

maven打包脚本

#!/bin/bash

set -e
mvn -version
cd session-management-service-repo
cp -f ci/assets/maven/settings.xml /usr/share/maven/conf/settings.xml
mvn clean package -DskipTests=true
cp -a * ../session-management-service-repo-out

构建镜像任务看起来像这样

---
platform: linux
image_resource:
type: registry-image
source:
repository: concourse/oci-build-task
inputs:
- name: session-management-service-repo-out
outputs:
- name: image
params:
CONTEXT: session-management-service-repo-out
run:
path: build

注意:这里要注意的一件事是,当我使用我的自定义资源类型时,我开始遇到这个错误。在使用我的自定义资源类型之前,我没有遇到这个“上一步缺少版本”错误,而是像下面这样的东西,我只是在推送 docker 图像时才得到,而不是在构建图像时,所以我能够成功地构建图像。但正如您所见,这是证书错误,因此我决定使用包含所需证书的自定义资源类型。

selected worker: 1b0fd33bcd2b
WARN[0000] ECR integration is experimental and untested
ERRO[0000] failed to authenticate to ECR: RequestError: send request failed
caused by: Post "https://api.ecr.eu-central-1.amazonaws.com/": x509: certificate signed by unknown authority
ERRO[0000] cannot authenticate with ECR

我在使用自定义资源类型之前的管道几乎相似,只是它不包含 resource_types 部分

resources:
- name: session-management-service-repo
type: git
icon: github
source:
branch: develop
uri: ((source_url))
username: ((myusername))
password: ((mypassword))

- name: ecr-docker-reg
type: registry-image
icon: docker
source:
aws_access_key_id: ((access_key))
aws_secret_access_key: ((secret_access_key))
aws_region: ((region))
repository: srm-session-management-service
tag: latest

jobs:
- name: test
public: true
plan:
- get: session-management-service-repo
trigger: true
- task: mvn-test-task
file: session-management-service-repo/ci/tasks/maven-test.yml

- name: build-and-push
public: true
serial: true
plan:
- get: session-management-service-repo
trigger: true
passed: [test]
- task: mvn-package-task
file: session-management-service-repo/ci/tasks/maven-package.yml
- task: build-image-task
privileged: true # oci-build-task must run in a privileged container
file: session-management-service-repo/ci/tasks/build-image.yml
- put: ecr-docker-reg
params: {image: image/image.tar}

我无法弄清楚我错过了什么或哪里出错了。任何建议将不胜感激。谢谢

最佳答案

尝试在此处使用 version 属性而不是 tag:

 - name: ecr-docker-reg
type: registry-image
icon: docker
source:
aws_access_key_id: ((access_key_id))
aws_secret_access_key: ((secret_access_key))
aws_region: ((region))
repository: srm-session-management-service
**version: latest**

关于continuous-integration - Concourse - 构建 docker 镜像时上一步缺少版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72971640/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com