Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Thu May 17, 2012 4:38 am 
Offline
Junior Member

Joined: Sun May 13, 2012 10:02 am
Posts: 20
Hi,

I’ve been working hard on my stackscript this week and I have been making some progress with some help as well. This is the bit I am confused about. I would like to import my code from my private bitbucket git repo to my server automatically in the stackscript.

Firstly, I found this code in other peoples stackscripts. Then in this code, there was further code to grab the source from github:

Code:
cd /home/$USERNAME/
sudo -u $USERNAME wget "https://raw.github.com/gist/1210041/6f04294a6b80a6bf8d79a3530823d9449b8dee41/create_project.sh"
sudo -u $USERNAME chmod +x create_project.sh


What is the point of this create_project.sh? I just don’t get why we would want to fetch a script, to fetch the code, rather than just fetching the code to start with.

Secondly, if I want to clone my git repo to my server I was planning to use the following code:

Code:
cd /home/$USERNAME/
git branch live
git clone https://James@bitbucket.org/James/mywork.git
git push live


Now, again please appreciate this stuff is way over my head and I’m just trying to stumble through like an idiot to get this working. Could anyone offer me some advice as to the correct way to do this.

Regards,

James


Top
   
 Post subject:
PostPosted: Thu May 17, 2012 4:54 am 
Offline
Senior Newbie

Joined: Thu Mar 04, 2010 2:42 pm
Posts: 5
Code:
GIT_URL=http://user:pass@bitbucket.org/user/repo.git
GIT_DEST=/home/whatever


if [ ! -d "$GIT_DEST" ]; then
        git clone "$GIT_URL" "$GIT_DEST"
else
        git --git-dir="$GIT_DEST/.git" pull origin master
fi


Stackscripts run as root on the linode being deployed, so no need to do any sort of sudoing. All that snippet does is check if the destination directory exists - if it does, it does a git pull to update (shouldnt really happen with a stackscript unless you run it more than once after the linode has been booted for the first time), otherwise it performs a clone on the repo.

As for the first point, there's no real reason to pull a script rather than doing it directly in the stackscript - if you need to bundle a load of different pieces of "bootstrap" code together, so it isn't just stuff that can simply fit in a single bash script in the stackscript manager, then obviously it's smarter to add it to a git repo and just clone it in the stackscript, then run it directly that way.


Top
   
 Post subject:
PostPosted: Thu May 17, 2012 5:21 am 
Offline
Junior Member

Joined: Sun May 13, 2012 10:02 am
Posts: 20
That you for the reply, that was really helpful. I did have another question. There seemed to be a way to do it without putting the password in the URL by adding a trusted SSH key. Does this method offer any advantages?

http://confluence.atlassian.com/display ... +bitbucket


Top
   
 Post subject:
PostPosted: Thu May 17, 2012 6:22 am 
Offline
Junior Member

Joined: Sun May 13, 2012 10:02 am
Posts: 20
Code:
# <UDF name="bitbucket_username" Label="BitBucket Username" />
# <UDF name="bitbucket_password" Label="BitBucket Password" />
# <UDF name="bitbucket_repository" Label="BitBucket Repository" />

GIT_URL=http://"BITBUCKET_USERNAME":"BITBUCKET_PASSWORD”@bitbucket.org/user/"BITBUCKET_REPOSITORY".git
GIT_DEST=/home/whatever


if [ ! -d "$GIT_DEST" ]; then
        git clone "$GIT_URL" "$GIT_DEST"
else
        git --git-dir="$GIT_DEST/.git" pull origin master
fi


Using the helpful code given to me by Maz, I created the following which allows you to put in your username, password, and repository when you deloy your server. I havent had chance to test this yet, but I want to release my entire stackscript on here so it will hopefully help others.


Top
   
 Post subject:
PostPosted: Thu May 17, 2012 6:54 am 
Offline
Senior Newbie

Joined: Thu Mar 04, 2010 2:42 pm
Posts: 5
You've got some wierd utf-8 double quote character in there, bash might throw a fit about it.

You probably also want to UDF the GIT_DEST, and replace /user/ in the git url with BITBUCKET_USERNAME (as long as your bitbucket username is the same as the repo owner).

Fwiw I'm using something very similar in a stackscript to deploy using puppet - keep your configuration in git / bitbucket, clone it to the server on provision and then run puppet to apply the config - works pretty excellently.

As for ssh key auth, you can use it, but it would require you to download the private SSH key that has access to your repo before doing the git clone, which means you'd need to have it somewhere publically accessible (or passworded) and it basically achieves nothing - you still need some sort of authentication at some point using a username and password to grab it.

As long as the bitbucket username / password are UDF fields rather than hardcoded, security-wise it's about as much as you can do.


Top
   
 Post subject:
PostPosted: Thu May 17, 2012 7:02 am 
Offline
Junior Member

Joined: Sun May 13, 2012 10:02 am
Posts: 20
Code:
# <UDF name="bitbucket_username" Label="BitBucket Username" /> 
# <UDF name="bitbucket_password" Label="BitBucket Password" />
# <UDF name="bitbucket_repository" Label="BitBucket Repository" />
# <UDF name="git_destination" Label="GIT Deployment Destination" default="/home/whatever" />

GIT_URL=http://"BITBUCKET_USERNAME":"BITBUCKET_PASSWORD"@bitbucket.org/"BITBUCKET_USERNAME"/"BITBUCKET_REPOSITORY".git

if [ ! -d "GIT_DESTINATION" ]; then
        git clone "$GIT_URL" "GIT_DESTINATION"
else
        git --git-dir="$GIT_DEST/.git" pull origin master
fi


Would this work? I removed git_dest equate and put it in as a UDF varaible. I also found and removed the double quote and also changed the user field, thanks for spotting those.


Top
   
 Post subject:
PostPosted: Thu May 17, 2012 11:28 am 
Offline
Senior Newbie

Joined: Thu Mar 04, 2010 2:42 pm
Posts: 5
Spadez wrote:
Code:
# <UDF name="bitbucket_username" Label="BitBucket Username" /> 
# <UDF name="bitbucket_password" Label="BitBucket Password" />
# <UDF name="bitbucket_repository" Label="BitBucket Repository" />
# <UDF name="git_destination" Label="GIT Deployment Destination" default="/home/whatever" />

GIT_URL=http://"BITBUCKET_USERNAME":"BITBUCKET_PASSWORD"@bitbucket.org/"BITBUCKET_USERNAME"/"BITBUCKET_REPOSITORY".git

if [ ! -d "GIT_DESTINATION" ]; then
        git clone "$GIT_URL" "GIT_DESTINATION"
else
        git --git-dir="$GIT_DEST/.git" pull origin master
fi


Would this work? I removed git_dest equate and put it in as a UDF varaible. I also found and removed the double quote and also changed the user field, thanks for spotting those.


Everywhere you use an environment variable it needs a $:

Code:
# <UDF name="bitbucket_username" Label="BitBucket Username" /> 
# <UDF name="bitbucket_password" Label="BitBucket Password" />
# <UDF name="bitbucket_repository" Label="BitBucket Repository" />
# <UDF name="git_destination" Label="GIT Deployment Destination" default="/home/whatever" />

GIT_URL="http://$BITBUCKET_USERNAME:$BITBUCKET_PASSWORD@bitbucket.org/$BITBUCKET_USERNAME/$BITBUCKET_REPOSITORY.git"

if [ ! -d "$GIT_DESTINATION" ]; then
        git clone "$GIT_URL" "$GIT_DESTINATION"
else
        git --git-dir="$GIT_DEST/.git" pull origin master
fi


Top
   
 Post subject:
PostPosted: Thu May 17, 2012 11:35 am 
Offline
Junior Member

Joined: Sun May 13, 2012 10:02 am
Posts: 20
Ah, thank you.


Top
   
 Post subject:
PostPosted: Mon May 21, 2012 7:11 am 
Offline
Junior Member

Joined: Sun May 13, 2012 10:02 am
Posts: 20
Can you use "https" instead of "http"? for secuirty purposes?

My concern with this method is that I would be sending my username and password over http.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group