System Setup helped you install everything on your system.
Now its time to configure it to make it usable. We’ll create a demo application and test our connectivity in this exercise. We’ll start with setting up git. Then we’ll set up JBossDevStudio. Then we’ll set up Openshift. We’ll set up mercurial later when that comes. At the end of this exercise, we’ll have a configured development environment with all components talking in real time to each other.
If you already have a id_rsa key, and you have never used it in github, then use that key and skip step 1 and 2 and jump straight to step 3. If you are using your id_rsa key in another github account, then follow step 2 before going to step 3. If you plan to have multiple keys for different sites, then it is strongly suggested NOT to have a file with the default name ‘id_rsa’. Most websites try to automatically look for that file before they search for anything else and would fail if the signatures do not match. If you do plan to have separate keys for different sites, create keys with names like id_rsa_github, id_rsa_openshift, id_rsa_mercurial, id_dsa_gmail, id_dsa_general etc. After the end of this exercise, you should be able to run only Step 14 for your daily life changes.
Secure you ssh environment. Your /etc/ssh/sshd_config should have at least the following settings. (You should have multiple terminals logged in before you restart your system to ensure that you do not completely lose access to your machine. You need to do
sudo service sshd restart
to reflect your changes).
# Logging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
LogLevel VERBOSE
# Authentication:
LoginGraceTime 15s
PermitRootLogin yes
StrictModes yes
MaxAuthTries 2
MaxSessions 10
# set RSA and pubkey Auth to yes
RSAAuthentication yes
PubkeyAuthentication yes
# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication no
PermitEmptyPasswords no
#PasswordAuthentication yes
# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
Create the ssh keys.
mv ~/.ssh ~/.ssh_backup
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -C "sayantan" -p -o -a 1000
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod a-rwx *
chmod a-rwx *.*
chmod u+rw *
chmod u+rw *.*
ssh-add -D
ssh-add ~/.ssh/id_rsa
If you have multiple Github accounts, follow this guide to set up:
// The following is done only if you already have a github account elsewhere
ssh-keygen -R github.com
// This will create a backup file of /home/user/.ssh/known_hosts into known_hosts.old file. You can switch between the files as you switch between your github accounts
Upload the public key
Copy content of the public key from ~/.ssh/id_rsa.pub and paste it in
https://github.com/settings/ssh/ for Github
https://openshift.redhat.com/app/console/keys/new for OpenShift
If the account doesn’t recognise your keys then mail me your public key id_rsa.pub and I’ll add it to the project repo. Make sure that you do not share your private key with anybody. If you are new to this, consider it this way, your private key is your key and your public key is your lock. So when you attach the public key to the project repo, its like renting a room in an apartment and putting your lock on the door. The key is still with you, so that only you can pass through the door to access the room in the apartment. If you share your private key with someone, even they can access your room without your permission.
In Windows, with GitBash I found I had to copy my ~/.ssh/id_rsa file to Program Files\Git\.ssh\id_rsa
Goto Github.
In Repositories you contribute to (At right hand side), Click on ID
In right hand side, you should be able to see the SSH Clone url. Copy that.
In Terminal type
cd ~
mkdir repo
cd repo
git init
git clone git@github.com:ID/playground.git
ls -lrt
git status
git add -vf --all
git commit -m ‘Initialization by Sayantan’
git branch sayantan
git checkout sayantan
git status
git log
git show
git stage
vim playground/testSayantan.html
1 !DOCTYPE html
2 <html>
3 <head>
4 <title>This is a test page by Sayantan</title>
5 </head>
6 <body>
7 Howdy Sayantan.
8 </body>
9 </html>
10
git add .
git commit -m ‘First commit sayantan’
git log
git checkout master
git log
git merge sayantan
git log
git branch -d sayantan // you can recreate a deleted branch later
// Note: Do not modify the same file in a branch and master simultaneously. This confuses git and debugging gets a little painful. If you want to verify two different versions of a file, create two separate branches, test your changes and then merge the branch that you like.
// Now you know how to maintain a repo. It time to upload the changes on the cloud.
git remote add playground git@github.com:ID/playground.git
git remote -v
git push playground master
If you get an ERROR like this:
0 master % git push playground master
Warning: Permanently added the RSA host key for IP address '23.35.22.31' to the list of known hosts.
ERROR: Permission to ID/id.git denied to Sayantan.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
// Then you did not add your public key. Do that.
// Check you have set up the system properly.
ssh -T -ai ~/.ssh/id_rsa git@github.com
// If this doesn’t show any error, then do this and send the output to me
ssh -Tvvv -ai ~/.ssh/id_rsa_fed git@github.com
//If you get an output like this. Provide your password at prompt
0 master % ssh -T -ai ~/.ssh/id_rsa_fed git@github.com
Agent admitted failure to sign using the key.
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
git push playground master
// If things still fail. That can be because there are existing ssh keys. Delete your ~/.ssh folder (after backing it up) and then redo all steps.
At this point, you have successfully set up and tested your ssh and github connectivity. Now, its time to rock’n’roll.
Open terminal and type the following:
cd ~
cd repo
git clone ssh://123456789abcda@id-sayantan.rhcloud.com/~/git/id.git/
cd id
git remote add github git@github.com:ID/ci.git
git remote -v
// If the output to the previous command does not include the openshift repo at origin, then add it
git remote add origin ssh://123456abcda@id-sayantan.rhcloud.com/~/git/id.git
git pull origin master
nano ./src/main/webapp/index.html
// Scroll down and just below <li>Sayantan</li>, add your own name as contributor
//save the file
git add .
git commit -m ‘1st commit bt sayantan’
git push github master
// Go to github and see if your changes are there
git push origin master
you should get the output ending with
Found 127.0.0.1:8080 listening port
Found 127.0.0.1:9990 listening port
/var/lib/openshift/123456abcda/wildfly/standalone/deployments /var/lib/openshift/123456abcda/wildfly
/var/lib/openshift/123456abcda/wildfly
CLIENT_MESSAGE: Artifacts deployed: ./ROOT.war
-------------------------
Git Post-Receive Result: success
Activation status: success
Deployment completed with status: success
This was the hard way of doing things. You won’t have to type these codes all the time. This was done once to set things up and make sure that everything is working correctly. So, lets check out the easy way.
Now open JBossDevStudio
Click File -> Import -> Openshift Application -> Provide your Openshift username and password -> Next -> Browse -> sayantan.rhcloud.com -> id -> OK -> Next -> Keep the first two checkboxes checked and the last one unchecked -> Next -> Use Default Clone Destination -> SSH Keys Wizard -> Make sure your ssh key is there, if not, then Add Existing or New -> SSH2 Preferences -> Make sure your key is listed in private keys, or type it -> Apply -> OK -> Finish -> Yes -> Put your password -> OK
OR
If the above process gives some authentication errors even after adding your keys properly, then something is wrong with git permissions. that happens when you work as a regular user and git is installed as an administrator. such problems can be fixed by using chown in MAC and linux but not in windows.
open your terminal and pass the following commands, one by one,
cd
mkdir myrepo
cd myrepo
git clone git@github.com:ci
after this, you should have an updated copy of the project in your folder
Now open JBossDevStudio
Click File->Import
Click General -> Existing projects into workspace
click browse then go to the root folder of your project. That is ~/myrepo
Click finish. you are done.
you might have some issues with compilation errors becuase our jdk versions are different. but that's fine. i'll walk you through it.
You can perform similar steps to configure your IntelliJ Idea IDE.
From now on, whenever you are going to start working, before you start the IDE, open a terminal and issue the commands. this will make sure that you are working with the latest copy that includes other contributors changes.
cd
cd ~/myrepo
cd ci
git pull origin master
git pull ci master
and after you are done with your work and you have closed the IDE.
Then ALWAYS open a terminal and issue the following commands. this will make sure that your changes are committed and everybody is able to work with the latest updated copy:
cd
cd ~/myrepo
cd ci
git add .
git commit -m 'your favorite commit message '
git push origin master
git push ci master
Congratulations! You have successfully cloned the project.
GoTo: id -> src -> main -> webapp -> index.html
At the bottom of the page, Click source.
Scroll down to the bottom of the page.
type <li>yourname</li> just below <li>Sayantan Ghosh</li>
Save the page by pressing Ctrl +S
Right Click id. Team -> Commit
Check all boxes
Under commit message type a helpful message.
Click Commit and Push
Your output should be ending as follows:
Found 127.0.0.1:8080 listening port
Found 127.0.0.1:9990 listening port
/var/lib/openshift/123456abcda/wildfly/standalone/deployments /var/lib/openshift/123456abcda/wildfly
/var/lib/openshift/123456abcda/wildfly
CLIENT_MESSAGE: Artifacts deployed: ./ROOT.war
-------------------------
Git Post-Receive Result: success
Activation status: success
Deployment completed with status: success
Finalising configuration. If all other steps have ran successfully then your have tested everything. Upto this point, you have set up ssh on your system, connected to the project repo and connected to the Openshift repo.
From now on, only the following steps would be needed.
When you access the repo manually, then always pull first before making any changes, test your changes in your respective branch before making on master and always remember to commit your changes before you go.
git pull origin master
git branch sayantan
// make your changes
git merge sayantan
git commit -m ‘commit comment’
git push github master
git push origin master
When you access the repo via JBossDevStudio, then
Right Click on id project and click Refresh.
Right Click on id project > Team > Pull
// Make your changes
// Save your changes
// Test your changes locally
Right Click on id project > Team > Commit
// select the files you wish to push for commit
// provide a helpful commit message
// always “add signed off by” or else I’ll remove your changes.
Press Commit and Push.
All Done. Rize or Die.