Docker and Jenkins

The idea : Make all your Build with Jenkins on always the same environment : controlled, stable ..

What we will do :

  • Jenkins run a docker container
  • Jenkins run a temp slave in the container
  • The build is done on the slave container and jenkins take the result of the build (logs, metadata, artifacts)
  • Whent the build is done the container is killed

Install Docker

Install Jenkins

Pull a debian image

Prepare a dockerfile

FROM wheezy64:wheezy

RUN apt-get install -y openssh-server openjdk-7-jre-headless
RUN useradd -m -s /bin/bash jenkins
RUN echo jenkins:jenkins | chpasswd
RUN mkdir -p /var/run/sshd
EXPOSE 22
CMD /usr/sbin/sshd -D

Build a jenkins image
docker build -t wheezy_jenkins:jenkins .

We can test by running the container and connect with ssh
$ jenkins=$(docker run -d -p 0.0.0.0:2222:22 -t -i wheezy_jenkins:jenkins)

$ ssh jenkins@localhost -p 2222

Whe exit from the ssh session
exit

Then kill the container
docker kill $jenkins

Then delete the container
docker rm $jenkins

Now we will configure jenkins

install the docker plugin on jenkins (cf our post to know how to install plugin :jenkins_pluging )

configure jenkins : cloud and had your docker container

create an item

then compute

mobydock

devops.pm father

More Posts - Website

Follow Me:
TwitterFacebook

Jhipster on docker

LINUX UBUNTU

 

Pull the JHipster Docker image:

sudo docker pull jdubois/jhipster-docker

Create a « jhipster » folder in your home directory:

mkdir ~/jhipster

Run The docker image, with the following options:

  • The Docker « /jhipster » folder is shared to the local « ~/jhipster » folder
  • Forward all ports exposed by docker (8080 for Tomcat, 3000 for BrowserSync from the « grunt serve » task, 3001 for the BrowserSync UI, and 22 for SSHD). In the following example we forward the container 22 port to the host 4022 port, to prevent some port conflicts:

sudo docker run -v ~/jhipster:/jhipster -p 8080:8080 -p 3000:3000 -p 3001:3001 -p 4022:22 -t jdubois/jhipster-docker

 

 

SSH configuration

You can now connect to your docker container with SSH. You can connect as « root/jhipster » or as « jhipster/jhipster », and we recommand you use the « jhipster » user as some of the tool used are not meant to be run by the root user.

Start by adding your SSH public key to the Docker container:

cat ~/.ssh/id_rsa.pub | ssh -p 4022 jhipster@localhost 'mkdir ~/.ssh && cat >> ~/.ssh/authorized_keys'

You can now connect to the Docker container:

ssh -p 4022 jhipster@localhost

Your first project

You can then go to the /jhipster directory in your container, and start building your app inside Docker:

cd /jhipster
yo jhipster

If the following exception occurs, you need to change the owner of the /jhipster directory. See next step.

...
? (13/13) Would you like to use the Compass CSS Authoring Framework?: No

/usr/lib/node_modules/generator-jhipster/node_modules/yeoman-generator/node_modules/mkdirp/index.js:89
throw err0;
^
Error: EACCES, permission denied '/jhipster/src'
at Object.fs.mkdirSync (fs.js:653:18)
at sync (/usr/lib/node_modules/generator-jhipster/node_modules/yeoman-generator/node_modules/mkdirp/index.js:70:13)
at sync (/usr/lib/node_modules/generator-jhipster/node_modules/yeoman-generator/node_modules/mkdirp/index.js:76:24)
at Function.sync (/usr/lib/node_modules/generator-jhipster/node_modules/yeoman-generator/node_modules/mkdirp/index.js:76:24)
at JhipsterGenerator.app (/usr/lib/node_modules/generator-jhipster/app/index.js:419:10)
at /usr/lib/node_modules/generator-jhipster/node_modules/yeoman-generator/lib/base.js:387:14
at processImmediate [as _immediateCallback] (timers.js:345:15)

You need to fix the jhipster folder to give the « jhipster » user ownership of the directory:

ssh -p 4022 jhipster@localhost
sudo chown jhipster /jhipster

Once your application is created, you can run all the normal grunt/bower/maven commands, for example:

mvn spring-boot:run

Congratulations! You’ve launched your JHipster app inside Docker!

On your host machine, you should be able to :

  • Access the running application at http://localhost:8080
  • Get all the generated files inside your shared folder

As the generated files are in your shared folder, they will not be deleted if you stop your Docker container. However, if you don’t want Docker to keep downloading all the Maven and NPM dependencies every time you start the container, you should commit its state.

mobydock

devops.pm father

More Posts - Website

Follow Me:
TwitterFacebook

Secure your github access with SSH

Generating SSH keys

Step 1 – Check for existing SSH keys.

ls -al ~/.ssh
# Lists the files in your .ssh directory, if they exist
Check the directory listing to see if you already have a public SSH key. By default, the filenames of the public keys are one of the following:

id_dsa.pub
id_ecdsa.pub
id_ed25519.pub
id_rsa.pub

If you see an existing public and private key pair listed (for example id_rsa.pub and id_rsa) that you would like to use to connect to GitHub, you can skip Step 2 and go straight to Step 3.

Step 2 – Generate a new ssh key

ssh-keygen -t rsa -b 4096 -C "email@email.com"
it will ask you

Generating public/private rsa key pair.
Enter file in which to save the key (/home/jjz109/.ssh/id_rsa):

keep default and just press ENTER

you ‘ll have

Created directory '/xxxxx/.ssh'.
Enter passphrase (empty for no passphrase):

Choose a secure phrase

then

Your identification has been saved in /xxxxxx/.ssh/id_rsa.
Your public key has been saved in /xxxxx/.ssh/id_rsa.pub.
The key fingerprint is:
xx:xx:xx:xx:.............xx:xx email@email.com
The key's randomart image is:
+--[ RSA 4096]----+
| xxxxxx |
| xxxxxxxx |
|xxxxxxxxxxx |
|xx xxx xx |
| * * xx |
|. xxxx |
|..xxx |
|. xxx |
| |
+-----------------+

Step 3 – Add this key to the agent

Be sure ssh agent is running in background
$ eval "$(ssh-agent -s)"

It will give you the PID

Add your SSH key to the ssh-agent:
$ ssh-add ~/.ssh/id_rsa

The result should be : identity added xxxxxxxxxxxx

Step 4 – Add the SSH key to your account

install xclip with apt-get :
sudo apt-get install xclip

xclip -sel clip < ~/.ssh/id_rsa.pub
this will copy your key to the clipboard

Connect to your github account and go in SETTING
select SSH Key
Choose Add key
Past the key you have in your clipboard
SAVE

That’s done

Step 5 – Test the connection
ssh -T git@github.com
This will ask you the passphrase after you said yes to the first question

If the username in the message is yours, you’ve successfully set up your SSH key!

mobydock

devops.pm father

More Posts - Website

Follow Me:
TwitterFacebook

Starting with Git and Github on ubuntu

github

1 – Install Git
sudo apt-get install git

2 – Create a github account on GITHUB

3 – configure your git on your linux
git config --global user.name "user_name" where user_name is your github login
git config --global user.email "email" where email is your email used on github

Before the next step I will propose you to see our post about using SSH beetwin git and github

Here is the post :GIT GITHUB and SSH

 

4 – Create a local repository
Create a folder in your system. This will serve as a local repository which will later be pushed onto the GitHub website.
Use the following command: git init devops_pm_rep

 

On github you can try to fork an existing project , for example

https://github.com/jjz109/jhipster_example

Connected you can clic on the fork button to add this project to your account

When your github account is ok , you can create a local clone on your computer by using git
On github, on the right you’ll find a https clone url field. Copy the link.
something like  : https://github.com/xxxxxxxx/jhipster_example.git
in a terminal:
git clone https://github.com/xxxxxxxx/jhipster_example.git where xxxxis your user-name
It should do:

Clonage dans 'jhipster_example'...
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), done.
Vérification de la connectivité... fait.

You can now ask git to sync your clone with the original repository (orignal is not your fork but the project you forked)

copy the url to the original project. in the example :
https://github.com/jjz109/jhipster_example.git

in your terminal : go to the repository where you put your git clone

cd $home
ls
cd xxxxxx

when you find your .git
git remote -v will show your repositories

git remote add upstream https://github.com/jjz109/jhipster_example.git
wil add this upstream

Now, you can keep your fork synced with the upstream repository with a few Git commands
Sync a fork of a repository to keep it up-to-date with the upstream repository


git fetch upstream
# remote: Counting objects: 75, done.
# remote: Compressing objects: 100% (53/53), done.
# remote: Total 62 (delta 27), reused 44 (delta 9)
# Unpacking objects: 100% (62/62), done.
# From https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY
# * [new branch] master -> upstream/master

Fetch the branches and their respective commits from the upstream repository. Commits to master will be stored in a local branch, upstream/master

Check out your fork’s local master branch


$ git checkout master
# Switched to branch 'master'

Merge the changes from upstream/master into your local master branch. This brings your fork’s master branch into sync with the upstream repository, without losing your local changes.
$ git merge upstream/master

Syncing your fork only updates your local copy of the repository. To update your fork on GitHub, you must push your changes.

Pushing to a remote

Use git push to push your local branch to a remote repository.

The git push command takes two arguments:

A remote name, for example, origin
A branch name, for example, master

For example:

git push

As an example, you usually run git push origin master to push your local changes to your online repository.

 

ENJOY !

mobydock

devops.pm father

More Posts - Website

Follow Me:
TwitterFacebook