rzcodes
rzcodes
rzcodes
2 posts
Don't wanna be here? Send us removal request.
rzcodes · 9 years ago
Text
git #2 - deploying while git push
Syncing your local copy of your project toward your ftp or sftp storage can be hard sometimes, but using pre-push hooks in git can somehow even make it easier. If you are ready to push your changes toward to your gitrepo, that usually also means it's ready to deploy (that's why we are using different branches during the developing sessions). So consider this as a hook for pushing or merging to master branch for example.
As to do that, first we have to define a script called pre-push in your git repo's hooks folder, as the folling:
cd /path/to/your/repository/.git/hooks
then create the file itself:
vi pre-push
It's going to be a bash script, so not to forget define it as:
#!/bin/sh
To upload the modified files, or the whole folder itself, we are going to use the ftp command.
In the script we have to define the credentials to the server, to be able to set up the connection:
#!/bin/sh HOST='yourhost' USER='youruser' PASSWD='userpass' LOCALPATH='path/to/your/local/project' FILE=*.* DIR='path/to/your/remote/folder'ftp -n $HOST <<EOF quote USER $USER quote PASS $PASSWD cd $DIR lcd $LOCALPATH put $FILE quit exit; EOF
Do not forget to make the pre-push script executable
chmod +x /path/to/your/repository/.git/hooks/pre-push
Please note, that if you are server host provied you ssh connection, consider using scp instead of ftp, as it's more secure. Also note, that using any integration tool for deploying, for example jenkins is the right method, consider this way as a playing method. Now, when you are pushing to your git repo, the files going to be send to your ftp storage.
0 notes
rzcodes · 9 years ago
Text
git #1 - syncing mysql to gitrepo
Developing webapplications often comes with using MySql. Not to mention git, where most of the developers stores their codes. Developing on localhost, with self hosted MySql can make it hard to keep it up with your database, which can casue tough times if you have some differency in your databases when deploying the application itself to public internet. So as to avoid any inconsistencies between your test database and your deployed one, here’s some little git trick, do make it easier to maintain the process of the developing.
As to automate the dumping process of your local database, I am using git hooks. To set up your git hooks, first navigate yourself to your project's git folder.
Create a file called pre-commit in your git's hooks folder:
/path/to/your/repo/.git/hooks/pre-commit
Once we are at the right spot, we have to define our dumping script as a pre commit:
#!/bin/bash mysqldump -u [mysql user] -p[mysql password] --skip-extended-insert [database] > /path/to/your/repo/[database].sql cd /path/to/your/repo git add [database].sql
In these lines we are telling the git, to dump our database to our git repo, and add it to be comitted.
Okay, if we are done, we have to make this script as executable. To do this:
chmod +x /path/to/your/repo/.git/hooks/pre-commit
One more important thng is missing: to write the post-merge script.
We are going to tell the system to restore the MySQL dump to the local database for the latest changes. To create our post-merge script.
Create a file called post-merge in your git's hooks folder:
/path/to/your/repo/.git/hooks/post-merge
and add the following lines:
#!/bin/bash mysql -u [mysql user] -p[mysql password] [database] < /path/to/your/repo/[database].sql
Please take care of both in the mysqldump and mysql commands, there is no space between the -p and the password.
then make it executable as well:
chmod +x /path/to/your/repo/.git/hooks/post-merge
0 notes