angular - 如何使用 SSH 密钥将 Angular 生产版本部署到使用 bitbucket 管道的外部服务器?
问题描述
我们正在尝试使用 Bitbucket Pipelines 将基本的 Angular 应用程序部署到 Google Cloud 上的 VM,但不确定如何使用 SSH 密钥连接到服务器以复制构建文件。寻找示例但找不到。
我们可以使用 Putty/SSH 命令手动复制dist文件。
我们有来自 Google Cloud 虚拟机的公钥/私钥,并将它们添加到 Bitbucket Pipelines > SSH Keys
我们的 YML 脚本如下:
image: node:6.9.4
pipelines:
default:
- step:
caches:
- node
script: # Modify the commands below to build your repository.
- npm install
- npm install -g @angular/cli@1.6.4
- ng build --prod
- cd dist/
- ssh -i ???
解决方案
正如@Chris 所说,那篇文章是正确的起点。步骤是:
通过 UI 或运行 在 BitBucket 中添加 SSH 密钥
ssh-keygen
通过 UI更新已知主机。
通过将公钥添加到远程主机
cat ~/.ssh/my_ssh_key.pub | ssh username@remote_host "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod -R go= ~/.ssh && cat >> ~/.ssh/authorized_keys"
或通过
`ssh-copy-id -i my_ssh_key username@remote_host`
然后使用此命令复制文件(应该在您的脚本中):
scp username@remote_host:/path/to/file /path/to/destination
推荐阅读
- python - 有没有办法在不使用 for 循环的情况下从两个数组形成一个列表?
- reactjs - 每当我调用材料 ui 组件时,我都会收到 React 钩子错误
- php - 是否可以将 TinyMCE 文本编辑器集成到 Android 应用程序中?
- python - 使用python etree中的值对XML进行排序
- node.js - 更新到 npm v7 时,npm update 在我的应用程序中不起作用?
- javascript - 如何在 React Native 中实现交互式条形图?
- reactjs - 打字稿中的 Apexcharts 本地化
- c++ - C ++:更改while循环的迭代器的值是否安全?
- c - c中的星形金字塔程序
- redirect - 如何一键打开两个链接?