简体   繁体   English

如何通过 ssh 将文件复制到 ec2? (CI/CD 使用 gitlab CI)

[英]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,现在可以做

  1. Build the Docker image构建 Docker 镜像
  2. Tag it properly正确标记
  3. Push it to ECR推送到 ECR
  4. SSH to EC2 instance SSH 到 EC2 实例
  5. Pull image to the EC2 instance拉取镜像到 EC2 实例

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.

相关问题 Gitlab CI/CD 使用 ssh / knownhosts 错误 - Gitlab CI/CD using ssh / knownhosts error 如何在 gitlab CI/CD 管道中启动新的 EC2 实例 - How to spin up a new EC2 instance within a gitlab CI/CD pipeline 如何制作一个简单的 GitLab Ci/CD gitlab-ci.yml 文件来构建 Angular 项目? - How to make a simple GitLab Ci/CD gitlab-ci.yml file to build an Angular project? 如何在 GitLab CI/CD 中集成 terraform - How to integrate terraform in GitLab CI/CD 使用 Bash 和 cURL 通过 CI/CD 管道进入时生成 GitLab 合并请求 - Generate GitLab Merge Request when a push comes in via CI/CD Pipeline using Bash and cURL 当 gitlab CI/CD 触发时,如何通过 git 而不是从预定义的变量获取提交标签 - How to get the commit TAGS, via git and not from predefined vars, when gitlab CI/CD triggers 如何从 gitlab/github 上的 gitlab-ci CI/CD 运行 curl 命令? - How to run curl commands from gitlab-ci CI/CD on gitlab/github? 将文件从 gitlab ci 复制到远程服务器 - Copy file to remote server from gitlab ci 如何将环境变量传递给 docker 在 gitlab ci cd 中运行 - How to pass environment variable to docker run in gitlab ci cd 如何在 GitLab CI/CD 中访问下一阶段的工件 - How to access artifacts in next stage in GitLab CI/CD
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM