[英]Confused with github action and ec2
This is my github actions flow:这是我的 github 操作流程:
---
name: build and push image to aws ecr
on:
push:
branches: [ main ]
jobs:
build-and-push:
name: Build and push to ecr
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
...
deploy:
needs: build-and-push
name: deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Login ec2
env:
PRIVATE_KEY: ${{ secrets.EC2_SSH_KEY }}
HOSTNAME: ${{ secrets.HOST_DNS }}
USER_NAME: ${{ secrets.USERNAME }}
run: |
echo "$PRIVATE_KEY" > private_key && chmod 600 private_key
ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME}
ls
touch helloworld.txt
I wonder that I'm connected to the EC2 instance or not.我想知道我是否已连接到 EC2 实例。 This is my result after actions, it's list all file of my project.
这是我采取行动后的结果,它列出了我项目的所有文件。 I think I didn't ssh to EC2 successfull becuase I just create EC2 instance and it's empty.
我想我没有成功将 ssh 连接到 EC2,因为我只是创建了 EC2 实例并且它是空的。
Run echo "$PRIVATE_KEY" > private_key && chmod 600 private_key
Pseudo-terminal will not be allocated because stdin is not a terminal.
Warning: Permanently added '***,18.181.220.91' (ECDSA) to the list of known hosts.
Dockerfile
README.md
docker-compose.yml
nest-cli.json
package-lock.json
package.json
private_key
src
test
tsconfig.build.json
tsconfig.json
This is my command to ssh ec2 from client: ssh -i "home-key.pem" ec2-user@ec2-18-181-220-91.ap-northeast-1.compute.amazonaws.com这是我从客户端到 ssh ec2 的命令:ssh -i "home-key.pem" ec2-user@ec2-18-181-220-91.ap-northeast-1.compute.amazonaws.com
If i didn't connnect to EC2 instance, how I do it with github?如果我没有连接到 EC2 实例,我如何使用 github 进行连接?
Thanks for your attention.感谢您的关注。
I wonder that I'm connected to the EC2 instance or not.
我想知道我是否已连接到 EC2 实例。
In your SSH commands, add a hostname -a
one: it will display the name of the machine you are on.在您的 SSH 命令中,添加一个
hostname -a
one:它将显示您所在机器的名称。
That being said, you could use actions/ssh-execute-commands
to execute those same commands:也就是说,您可以使用
actions/ssh-execute-commands
来执行相同的命令:
- name: Execute SSH commmands on remote server
uses: JimCronqvist/action-ssh@master
env:
PRIVATE_KEY: ${{ secrets.EC2_SSH_KEY }}
HOSTNAME: ${{ secrets.HOST_DNS }}
USER_NAME: ${{ secrets.USERNAME }}
with:
hosts: '${USER_NAME}@${HOSTNAME}'
privateKey: ${{ secrets.PRIVATE_KEY }}
debug: false
command: |
ls -lah
hostname -a
whoami
touch helloworld.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.