[英]Github Workflow Actions And EC2: Error Loading Key Invalid Format
I am trying to set up CI for my nodejs server.我正在尝试为我的 nodejs 服务器设置 CI。 I would like to use github actions to ssh into my ec2 instance, where I can then git clone/pull my updated repo.
我想使用 github 操作 ssh 到我的 ec2 实例,然后我可以在那里 git clone/pull 我更新的 repo。
I can ssh into my ec2 instance on my local machine w no issues.我可以在我的本地机器上通过 ssh 进入我的 ec2 实例,没有问题。 I just do something like: "ssh -i keypar.pem username@some-ip.region.compute.amazonaws.com" and it connects.
我只是做一些类似的事情:“ssh -i keypar.pem username@some-ip.region.compute.amazonaws.com”并连接。 However, I can't seem to get a connection working on the worflow/actions script.
但是,我似乎无法在 worflow/actions 脚本上建立连接。 Here is what I have in my workflow yml file:
这是我的工作流 yml 文件中的内容:
name: CI名称:CI
on: [push]在:[推]
jobs: build:工作:构建:
runs-on: ubuntu-latest
steps:
- name: Connect
env:
DEPLOY_KEY: ${{ secrets.EC2 }}
run: |
eval `ssh-agent`
ssh-add - <<< "${DEPLOY_KEY}"
ssh ec2-user@ec2-instance-ip-here.us-east-2.compute.amazonaws.com
This script gets me the error "Error loading key "(stdin)": invalid format" .这个脚本让我得到错误"Error loading key "(stdin)": invalid format" 。 Also when I look at the deploy key section under repo settings, it says the key has never been used.
此外,当我查看 repo 设置下的部署密钥部分时,它说该密钥从未被使用过。
(Obviously I would need to install, clone, and perform other steps in addition to what is listed above.) (显然,除了上面列出的步骤之外,我还需要安装、克隆和执行其他步骤。)
In summary:总之:
1 how to I fix the invalid format error? 1 如何修复无效格式错误?
2 how do I load and reference the key pair? 2 如何加载和引用密钥对?
There is a better way to perform SSH commands in a EC2:有一种更好的方法可以在 EC2 中执行 SSH 命令:
name: CI
on: [push, pull_request]
jobs:
# test:
# ...
deploy:
name: "Deploy to staging"
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
# needs: test
steps:
- name: Configure SSH
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/staging.key
chmod 600 ~/.ssh/staging.key
cat >>~/.ssh/config <<END
Host staging
HostName $SSH_HOST
User $SSH_USER
IdentityFile ~/.ssh/staging.key
StrictHostKeyChecking no
END
env:
SSH_USER: ${{ secrets.STAGING_SSH_USER }}
SSH_KEY: ${{ secrets.STAGING_SSH_KEY }}
SSH_HOST: ${{ secrets.STAGING_SSH_HOST }}
- name: Stop the server
run: ssh staging 'sudo systemctl stop my-application'
- name: Check out the source
run: ssh staging 'cd my-application && git fetch && git reset --hard origin/master'
- name: Start the server
if: ${{ always() }}
run: ssh staging 'sudo systemctl start my-application'
Credit: GitHub Actions: How to run SSH commands (without third-party actions)信用: GitHub 操作:如何运行 SSH 命令(没有第三方操作)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.