[英]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.