简体   繁体   English

如何使用 Github Actions 以 RSA 密钥作为构建参数构建 docker 镜像

[英]How to build a docker image with RSA key as build argument using Github Actions

I am trying to build a docker image using github actions on ubuntu-latest.我正在尝试在 ubuntu-latest 上使用 github 操作构建一个 docker 镜像。 The docker image needs to receive an RSA KEY by build arg. docker 镜像需要通过 build arg 接收一个 RSA KEY。

Although building the image in my macos machine works without any problem, I am facing the following error when building in github actions.虽然在我的 macos 机器上构建图像没有任何问题,但在 github 操作中构建时我面临以下错误。

The keys are being stored as ENV variables and the command I am using is the following:密钥被存储为 ENV 变量,我使用的命令如下:

docker build --build-arg user_private_rsa=$USER_PRIVATE_RSA . docker build --build-arg user_private_rsa=$USER_PRIVATE_RSA 。 -t auth-service -t 认证服务

Using the above command builds the image successfully on mac, but when using this gihub action, I have no luck at all.使用上面的命令在 mac 上成功构建了图像,但是当使用这个 gihub 操作时,我完全没有运气。

on:
  push:
    branches: [ master ]
jobs:
  build-deploy:
    name: Build docker image
    runs-on: ubuntu-latest
  build-push-ecr:
    name: Build docker image and push to ecr
    runs-on: ubuntu-latest
    steps:  
      - name: Checkout
        uses: actions/checkout@v2
      - run: docker build --build-arg user_private_rsa=$USER_PRIVATE_RSA . -t auth-service
      - name: Build image
        env:
          USER_PRIVATE_RSA: ${{ secrets.USER_PRIVATE_RSA }}

bad flag syntax: -----END See 'docker build --help'.错误的标志语法:-----END 请参阅“docker build --help”。

The error occurs because executing docker build in github actions, ends up being a multiline command.发生错误是因为在 github 操作中执行 docker build 最终成为多行命令。

Has anyone faced a similar problem and can help me fix it?有没有人遇到过类似的问题,可以帮我解决吗? Thank you very much!非常感谢!

您应该引用该变量,即--build-arg user_private_rsa="$USER_PRIVATE_RSA"否则--build-arg user_private_rsa="$USER_PRIVATE_RSA"在第一个空格之后选择任何内容作为自己的选项。

如果有人遇到类似的问题,我通过将 rsa 密钥作为 base64 字符串传递来解决它,因为 docker 需要一个单行命令。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用 GitHub 操作构建 Docker 映像 - Unable to Build Docker Image Using GitHub Actions 使用 GitHub Actions 构建 Docker 镜像:没有这样的文件或目录 - Build Docker image using GitHub Actions: No such file or directory 如何保存 Github Actions docker 图像的构建结果 - How can I save the build result of the Github Actions docker image 使用 docker/build-push-action 在 GitHub Actions 中本地构建 docker 镜像 - Build docker image locally in GitHub Actions using docker/build-push-action 如何使用未提交的本地证书文件构建具有 GitHub 操作的 Docker 映像 - How to build an Docker image with GitHub actions using uncommited local certificate files 如何使用 GitHub 操作实现多级 Docker 构建? - How to implement a multistage Docker build with GitHub Actions? Github 操作使用 maven 构建 jar 并用于 docker 镜像构建 - Github actions build jar with maven and use for docker image building Github 操作:推送 gradle 任务构建的 docker 映像 - Github Actions: Push docker image build by gradle task How to build Docker Image using Docker or docker-compose from a Private Github Repo or Github Enterprise repo? - How to build Docker Image using Docker or docker-compose from a Private Github Repo or Github Enterprise repo? 您如何构建 docker 映像并将其用作 GitHub 操作中下一个作业的容器? - How do you build a docker image and use it as the container for the next job in GitHub actions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM