Reputation: 1617
I am new to git and need some help. My plan:
I use Atlassian Stash, I see that there is a way that I can fork from debs to www folder. And when I change something in debs directory, it will automatically push the changes to www folder. Is it true?
I want to make script that will automatically do the parts 4. 5. and 6.
What would be the best way to do it?
Upvotes: 0
Views: 229
Reputation: 76877
1) I have debs repository
Let's assume the url to this is [email protected]:user/debs.git
We are using the ssh
url, so that the whole pull process can be automated on the server. The ssh-keys
can be picked on their own by git
, unlike the username-password
which need to be provided everytime over https
connections, and ssh keys are much easier to setup than password caching.
This assumes you have your ssh keys setup already. Check out these posts on bitbucket and github to do the same.
2) I have docs repository
Let's assume the url to this is [email protected]:user/docs.git
3) I want fork from debs to
www
folder
This should be simple - go to your www location and use git clone to create a local copy of it.
cd www
git clone [email protected]:user/docs.git
FWIW, forking is not the right term here, it is relevant only to creating copies of the repo on bitbucket, github etc from one user account to another.
In case you want this clone to be named as www
, i.e., all code to be placed within the www
direcotry, and not within www/debs
directory, use
cd path_to_www_parent
git clone [email protected]:user/docs.git www
4) Add files from docs repository with modified names and directorys
If you need to change the file names everytime, I would suggest cloning the debs repo to some location, and renaming the files, and then moving them.
Otherwise, if the names and directory path of the files are the same as that in the git repo, you can directly add the docs repository as a git submodule within the debs
repository, or have it as a subtree within it.
I would recommend keeping the filenames etc same, so that your git repository is a working copy of the code, without needing any alterations on pull etc; that way it can be used directly as a submodule and we won't need to worry about that file renaming script.
5) Then I want to merge from debs folder and modified docs folder into www folder
We already took care of that in steps above, the ideal way to do this would be to have following structure in your case instead of manually playing around with code.
debs #can be the www folder as well
|_code_file_for_debs_1
|_code_file_for_debs_2
|_code_file_for_debs_3
.
.
|_docs #is a git submodule
6) In
webserver
I want to pull automatically www folder with cron to update the deb repository
Once you have added the modules in above fashion, a simple git pull will update them. The cron job could be a simple script like following
cd www
git pull
service apache2 graceful #assuming apache is webserver
And this can be scheduled as a job every 15 minutes like follow (open crontab using crontab -e
)
*/15 * * * * sh script.sh
or
*/15 * * * * cd www && git pull && service apache2 graceful
I use Atlassian Stash, I see that there is a way that I can fork from debs to www folder. And when I change something in debs directory, it will automatically push the changes to www folder. Is it true?
No, nothing will be automatically pushed. You will need to add the changed files using git add
, and then commit them, and then push them to your bitbucket/github repo. We can setup a bare repo on the server and start pushing to it, but that won't alter any other steps above. Check my answer on another question here to get a better understanding of setting up bare repos.
PS
While this setup should work, you should investigate using capistrano
or other such tools for deployments instead of relying completely on cron jobs to do the same for you. The advantage of cap
scripts is that they only have to run when you need to do a deploy, so your server is not wasting cpu cycles; you can deploy on multiple servers simultaneously; you can easily work around issues due to failed git pull
etc.
Upvotes: 1