简体   繁体   中英

using shell script to automate git commits and ssh apache server deployments?

I'm trying to figure out how I go about automating this process using a script.

I don't know what I'd use, or how to go about it. I'm looking to get pointed in the right direction.

In git :

git commit -am "my commit"
git pull origin my_branch
git push origin my_branch
git archive --format zip --output /c/git/(environment)_(date)_(commithash).zip my_branch
scp (environment)_(date)_(hash).zip root@12.3.4.56:/var/www/html-(domain)
password123

In apache : ( usually i putty in... )

root
password123
cd /var/www/html-(domain)/(environment)
unzip ../(environment)_(date)_(commithash).zip
n
n
A
cd ..
cp -pr (environment) (environment)_(date)_(commithash)
exit

To explain whats going on, I am pushing my latest commit, SCPing to apache server docroot, deploying, and making backup with commit hash.

You can either use a shell script as you plan to -- just save the commands you want to run (one per line) in a file, add #!/bin/bash at the top, make it executable with chmod +x myscript.sh (the .sh file extension is not required) and then run it with ./myscript.sh .

You may find it easier to use scaffolding that specifically assists with deployment. A nice-looking one of these systems (that I have yet to try) that uses shell scripts is deliver .

You are taking the first step toward Continuous Integration .

I use Jenkins which I set up to do:

  • git pull origin master
  • run unit tests
  • deploy code
  • run db deployments
  • update ticket system with success/fail

There are lots of extensions and tools as well, works with any language, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM