[英]How to copy a file to ec2 via ssh? (CI/CD using gitlab CI)
So I have set up ci/cd using gitlab and is now able to do所以我已经使用 gitlab 设置了 ci/cd,现在可以做
However, I still need to run the docker image for it to be complete.但是,我仍然需要运行 docker 图像才能完成。
Right now, I am using the --env_file to specify the env_file for that container, but I still have to create the env file manually on the ec2 instance first.现在,我正在使用 --env_file 为该容器指定 env_file,但我仍然必须先在 ec2 实例上手动创建 env 文件。
Is there a way for me to just copy and replace the.env file I have in my repository to the ec2 instance, so it can be updated from that file instead of having to redo it every time there's a change?有没有一种方法可以让我将存储库中的 .env 文件复制并替换到 ec2 实例,这样它就可以从该文件更新,而不必在每次发生更改时都重做?
You can use scp <path-to-env-file> <ec2-user@><ec2-address>:<path-to-docker-directory>
.您可以使用
scp <path-to-env-file> <ec2-user@><ec2-address>:<path-to-docker-directory>
。
Another solution: You could also build Ansible Playbook and execute all of your steps.另一个解决方案:您还可以构建 Ansible 剧本并执行所有步骤。 You would need to write your steps in form of ansible tasks or roles, then target the correct host.
您需要以 ansible 任务或角色的形式编写步骤,然后定位正确的主机。 For example steps from 1->3 are excuted locally, and 5->7 (where 6 is copying.env file and 7 is starting the docker container) to be remotely (on EC2 instance) executed.
例如,从 1->3 的步骤在本地执行,5->7(其中 6 是 copying.env 文件,7 是启动 docker 容器)远程(在 EC2 实例上)执行。 More on this: https://www.redhat.com/en/topics/automation/what-is-an-ansible-playbook#:~:text=Ansible%20Playbooks%20are%20lists%20of,as%20which%20user%20executes%20it .
更多相关信息: https://www.redhat.com/en/topics/automation/what-is-an-ansible-playbook#:~:text=Ansible%20Playbooks%20are%20lists%20of,as%20which%20user %20 执行 %20it 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.