Automating Git pull process on a ec2 ubuntu instances

二次信任 提交于 2019-12-10 11:03:49

问题


I am running a couple of ubuntu ec2 instances, I want to run an automation script which will pull the code from Github whenever a new instance is booted from the AMI. The thing is presently I am sshing to the server and run the command git pull origin master and it will ask for password key.

How do I automate this process? So after booting the new instance from a AMI this script should:

  • Run
  • Pull the code and also the submodule
  • Create couple of files and configure it

Please help me to achieve it.

Thanks


回答1:


This will probably take some time and configuring, but this might set you on the right path.

First, setup your ssh keys, so that you can automatically pull from a repo, without a password. Outlined here: https://help.github.com/articles/generating-ssh-keys

Next, create a startup script to issue the 'pull' command from Github. Here: https://help.ubuntu.com/community/UbuntuBootupHowto

Then save your AMI, When you start a new EC2 AMI, the script should run, pulling in your Github changes.

Also to note, make sure gits remote path is using SSH, if it is HTTPS, it will ALWAYS ask for a password.




回答2:


Your best best would be to utilize the fact the Ubuntu utilizes CloudInit within its canonical image.

Using CloudInit, you can pass scripts (i.e. shell scripts) to execute at various start up stages as EC2 user-data.

It would be very easy for your to make your GIT command line sequence execute from such a script. He is link to documentation, which includes examples.

https://help.ubuntu.com/community/CloudInit




回答3:


Create a user-password access to your ubuntu instance. Replicate this particular instance if you need multiple. Now you are free of the key access. If you need to automate a process in that instance cron it or send the script via ssh to that instance and let the cron to find and run it.



来源:https://stackoverflow.com/questions/13915465/automating-git-pull-process-on-a-ec2-ubuntu-instances

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!