php小编草莓为您介绍如何使用 Docker 容器中的私有存储库进行身份验证。Docker 是一种流行的容器化平台,能够帮助开发人员在不同的环境中快速部署和运行应用程序。然而,对于一些敏感的应用程序或者私有的代码库,我们可能需要对容器中的存储库进行身份验证,以确保只有授权的人员可以访问。本文将向您展示如何设置和使用私有存储库的身份验证,以保护您的敏感数据和代码。
问题内容
我有一个 git 存储库,它是一个私有存储库,我需要能够对其进行身份验证,并能够在运行时在 container build
视角中查看它。有关一些背景信息,我有一个 github 工作流程,用于构建容器映像并将其发布到 ghcr.io
注册表。但是,因为我的包依赖的存储库是私有的,所以它不起作用。现在它可以在本地运行,我考虑过更改存储 github 身份验证的方式以允许我访问它,但我想知道是否有人知道更好的方法让我访问私有存储库。 p>
以下是发布到 ghcr.io
注册表的 github 操作:
name: docker dataeng_github_metrics # run workflow on tags starting with v (eg. v2, v1.2.0) on: push: branches: [ "master" ] paths: - ./data_pipelines/dataeng_github_metrics/* pull_request: branches: [ "master" ] jobs: deploy: runs-on: ubuntu-latest steps: - name: checkout code uses: actions/checkout@v1 - name: login to github container registry uses: docker/login-action@v1 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.ghcr_registry_token }} - name: set up docker buildx uses: docker/setup-buildx-action@v2 - name: build and push docker image uses: docker/build-push-action@v3 with: context: ./data_pipelines/dataeng_github_metrics/ file: ./data_pipelines/dataeng_github_metrics/dockerfile push: true # will only build if this is not here tags: | ghcr.io/mirantis/dataeng_github_metrics:latest # todo: i cannot use dataeng as public and need to change the way gitconfig is used in the dockerfile for authentication secrets: | token=${{ secrets.automation_pat}}
这是 dockerfile
:
############### # cache image # ############### arg go_image=golang:1.17.3-alpine3.14 arg base_image=alpine:3.14.2 from ${go_image} as cache # add the keys arg github_id env github_id=$github_id arg github_token env github_token=$github_token # install git run apk add git # todo: encrypt the github_id and github_token # make git configuration run git config \ --global \ url."https://${github_id}:${github_token}@github.com/".insteadof \ "https://github.com/" workdir /src copy go.mod go.sum /src/ run go mod download ############## # base image # ############## from cache as dataeng_github_metrics copy . /bin workdir /bin # setup git terminal prompt & go build run go build . ############### # final image # ############### from ${base_image} copy --from=dataeng_github_metrics /bin/dataeng_github_metrics bin/ entrypoint [ "bin/dataeng_github_metrics" ]
我认为让我困惑的重要部分是这个,但想知道是否有更好的方法来实现它:
# make git configuration run git config \ --global \ url."https://${github_id}:${github_token}@github.com/".insteadof \ "https://github.com/"
如何访问私有存储库并避免工作流程中出现以下错误:
#14 9.438 remote: Repository not found. #14 9.438 fatal: Authentication failed for 'https://github.com/Mirantis/dataeng/' ------ Dockerfile:26 -------------------- 24 | WORKDIR /src 25 | COPY go.mod go.sum /src/ 26 | >>> RUN go mod download 27 | 28 | ############## -------------------- ERROR: failed to solve: process "/bin/sh -c go mod download" did not complete successfully: exit code: 1 Error: buildx failed with: ERROR: failed to solve: process "/bin/sh -c go mod download" did not complete successfully: exit code: 1
解决方法
在 dockerfile
中,为了使用操作传递的密钥(称为 token
中,为了使用操作传递的密钥(称为 token
),您应该按以下方式运行:
RUN --mount=type=secret,id=TOKEN \ echo "machine github.com login x password $(head -n 1 /run/secrets/TOKEN)" > ~/.netrc && \ git config \ --global \ url."https://${GITHUB_ID}:${TOKEN}@github.com/".insteadOf \ "https://github.com/"
记得将 github_id
也传递给 dockerfile
以上是如何使用 Docker 容器中的私有存储库进行身份验证的详细内容。更多信息请关注PHP中文网其他相关文章!

Golang更适合高并发任务,而Python在灵活性上更有优势。1.Golang通过goroutine和channel高效处理并发。2.Python依赖threading和asyncio,受GIL影响,但提供多种并发方式。选择应基于具体需求。

Golang和C 在性能上的差异主要体现在内存管理、编译优化和运行时效率等方面。1)Golang的垃圾回收机制方便但可能影响性能,2)C 的手动内存管理和编译器优化在递归计算中表现更为高效。

selectgolangforhighpperformanceandcorrency,ifealforBackendServicesSandNetwork程序; selectpypypythonforrapiddevelopment,dataScience和machinelearningDuetoitsverserverserverserversator versator anderticality andextility andextentensivelibraries。

Golang和Python各有优势:Golang适合高性能和并发编程,Python适用于数据科学和Web开发。 Golang以其并发模型和高效性能着称,Python则以简洁语法和丰富库生态系统着称。

Golang和Python分别在哪些方面更易用和学习曲线更平缓?Golang更适合高并发和高性能需求,学习曲线对有C语言背景的开发者较平缓。Python更适合数据科学和快速原型设计,学习曲线对初学者非常平缓。

Golang和C 在性能竞赛中的表现各有优势:1)Golang适合高并发和快速开发,2)C 提供更高性能和细粒度控制。选择应基于项目需求和团队技术栈。

Golang适合快速开发和并发编程,而C 更适合需要极致性能和底层控制的项目。1)Golang的并发模型通过goroutine和channel简化并发编程。2)C 的模板编程提供泛型代码和性能优化。3)Golang的垃圾回收方便但可能影响性能,C 的内存管理复杂但控制精细。

GoimpactsdevelopmentPositationalityThroughSpeed,效率和模拟性。1)速度:gocompilesquicklyandrunseff,ifealforlargeprojects.2)效率:效率:ITScomprehenSevestAndArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdEcceSteral Depentencies,增强开发的简单性:3)SimpleflovelmentIcties:3)简单性。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

WebStorm Mac版
好用的JavaScript开发工具

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中