Sunday, 7 January 2018

Setup Jenkins: A continuous integration and continuous deployment toll on Ubuntu 14.04 machine for an Angular4 appication

How to setup jenkins in ubutu 14.04


SRC: https://vexxhost.com/resources/tutorials/how-to-install-configure-and-use-jenkins-on-ubuntu-14-04/

1) sudo apt-get update

2) Basic Web Server [Only if you want build to be server by a web-server]
apt-get install nginx
Check service status: service nginx status

3) Java Installation
sudo apt-get install openjdk-7-jdk
verify the installation: java –version

4) Jenkins Installation and Configuration
a) wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add –
b) sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
c) sudo apt-get install Jenkins

Default user name [jenkin]
Jenkins Continuous Integration Server is running with the pid 16997
Port: 8080

If you need to update the configurations of Jenkins as per your requirements, then you can find its configuration file under the `/etc/default/` directory and can make the changes.
root@ubuntu-14:~# vim /etc/default/Jenkins

5) Setup Jenkins
To use and configure Jenkins, visit the following address in your browser

a) http://your-ip-address:8080
b) 1. Click on `Manage Jenkins` and then choose the required parameter to start required configurations.
2.

jenkins  todos

master branch should be replace by develop  branch
git should be replaced by butbucket.


sudo usermod -a -G root jenkins
Then restart jenkins:

sudo service jenkins restart


https://codeforgeek.com/2016/04/continuous-integration-deployment-jenkins-node-js/

https://medium.com/nodejs-tips/jenkins-node-js-part-2-b499c280310a

forever: https://www.npmjs.com/package/forever


***************************

echo $PATH
node --version
forever --version
echo "Install modules"
npm install
echo "Stoping forever old process"
forever stop index.js
echo "Starting forever new process"
BUILD_ID=dontKillMe forever -a -1 myforever.log index.js &


https://stackoverflow.com/questions/30862532/forever-errors-with-babel-node
forever start -c node_modules/.bin/babel-node server.js
*****************************************************************

Here we tell Jenkins not the stop the newly forked child process as it’s execution is over. Using `BUILD_ID=dontKillMe` flag. As this process needs to be up and running even are the build is over. Do note & at the end, it used to make the command a background process, thus jenkins process will not wait for it and skip to next command, thus allow the build to be complete.

***************************

sudo nohup ng serve --disable-host-check --host 0.0.0.0 1>./log.txt 2>./err.txt &

sudo nohup ng serve --disable-host-check --host 0.0.0.0 1>./log.txt 2>./err.txt &


forever start -c node_modules/.bin/babel-node server.js

Problems left behind:

how to take git pull since that requirese username and password

how to trigger git code from bitbucket to jenkins

how to link with another branch then master

to test with a live running Angular application.

kill command fails when no application has been running

Problems solved
How to kill a process started with nohup on port # 4001
sudo kill `sudo lsof -t -i:4001`

how to provide password to sudo command
https://stackoverflow.com/questions/37603621/jenkins-sudo-no-tty-present-and-no-askpass-program-specified-with-nopasswd

# User privilege specification
root    ALL=(ALL:ALL) ALL
jenkins ALL=(ALL) NOPASSWD: ALL

cannot create ./log.txt: Permission denied
give it the permission manually, since jenkins creates its own user which might has permissions different from the ordinary user.




Process I will follow

echo $PATH
node --version
echo "Stoping forever old process"
sudo kill `sudo lsof -t -i:4200`
echo "Starting forever new process"
nohup ng serve --disable-host-check --host 0.0.0.0 1>./log.txt 2>./err.txt &

sudo kill `sudo lsof -t -i:4200`
sudo nohup ng serve --disable-host-check --host 0.0.0.0 1>./log.txt 2>./err.txt &

echo "Sudo_password" | sudo -S pwd

How to run mongod
sudo mongod --dbpath=/var/lib/mongodb


SRCS:
How to setup
https://vexxhost.com/resources/tutorials/how-to-install-configure-and-use-jenkins-on-ubuntu-14-04/
Link bitcuket as well: https://medium.com/nodejs-tips/jenkins-node-js-part-2-b499c280310a
how to use sudo in jenkins
WOrked: https://stackoverflow.com/questions/37603621/jenkins-sudo-no-tty-present-and-no-askpass-program-specified-with-nopasswd
Not worked for me: https://stackoverflow.com/questions/21659637/how-to-fix-sudo-no-tty-present-and-no-askpass-program-specified-error/24648413#24648413
Link bitbucket to jenkins
https://medium.com/nodejs-tips/jenkins-node-js-part-2-b499c280310a

Install Genymotion: A simulator tool for react-native applications and other mobile application in Ubuntu 14.04


Install genymotion
1) Download bin file
https://www.genymotion.com/fun-zone/

2) Give it executeable permissions
chmod +x genymotion-2.1.0_x64.bin

3) cd genymotion
4) ./genymotion

this will run the genymotion but it needs virtual box...

5) Download the virtual box from here...


https://www.virtualbox.org/wiki/Linux_Downloads

download linux for 64 bits or 32 based on OS

sudo dpkg -i /path/to/deb/file followed by sudo apt-get install -f .



ISSUES IN GENYMOTION
1) `CXXABI_1.3.8' not found (required by genymotion player
issue while starting device
SOL:
https://stackoverflow.com/questions/37817792/how-to-fix-genymotion-in-linux-elementaryos-with-error-cxxabi-1-3-8-not-found/37817981
Execute the following 5 steps to solve it:

LD_LIBRARY_PATH=/usr/local/lib64/:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.9 g++-4.9

Install watchman in Ubuntu 14.04

Install watchman:-

SRC: https://facebook.github.io/watchman/docs/install.html
Helper links:
https://stackoverflow.com/questions/33592197/how-to-install-facebook-watchman-on-ubuntu
https://www.howtoinstall.co/en/ubuntu/trusty/inotify-tools
Installing from source
You can use these steps below to get watchman built. You will need autoconf, automake and libtool (or glibtool on OS X). You may optionally build watchman without pcre and python support (see configuration options below). For python support, you will need setuptools and may need to install a python-dev or python-devel package. To build the C++ client library you will need to install libfolly.

See below for some more information on options to configure your build.

$ git clone https://github.com/facebook/watchman.git
$ cd watchman
$ git checkout v4.9.0  # the latest stable release
$ ./autogen.sh [Issue1,2]
$ ./configure
$ make [Issue3]
$ sudo make install

ISSUE1: your system lacks libtoolize

SOLUTION1: sudo apt-get install libtool
https://github.com/facebook/watchman/issues/486

ISSUE2: After resolving issue#1, try run ./autogen.sh then it returns "aclocal: command not found"
SOLUTION1: [https://stackoverflow.com/questions/33592197/how-to-install-facebook-watchman-on-ubuntu]
   a) sudo apt-get install automake  <<<<  contains autoheader, ...
   b) sudo apt-get install autoconf

ISSUE3: fatal error: Python.h: No such file or directory
SOLUTION1: a) sudo apt-get install python-dev
[https://stackoverflow.com/questions/37297472/cant-find-python-h-file-while-installing-watchman]  

Setup react-native in Ubuntu 14.04

https://facebook.github.io/react-native/docs/getting-started.html

1) Install build tools
sudo apt-get install -y build-essential

2) Install react-native cli
npm install -g react-native-cli

3)Install android studio - From: https://developer.android.com/studio/install.html

download android studio
go to path to bin
./studio.sh

3B) setup android stdio
Choose a "Custom" setup when prompted to select an installation type. Make sure the boxes next to all of the following are checked:

Android SDK
Android SDK Platform
Android Virtual Device
Then, click "Next" to install all of these components.

If the checkboxes are grayed out, you will have a chance to install these components later on.

3c) Install required JDK
download the sdk for android 6.0 marshmallo

The SDK Manager can also be found within the settings-> Android Studio "Preferences" dialog, under Appearance & Behavior → System Settings → Android SDK.

make sure the following items are all checked:

Google APIs
Android SDK Platform 23
Intel x86 Atom_64 System Image
Google APIs Intel x86 Atom_64 System Image

Next, select the "SDK Tools" tab and check the box next to "Show Package Details" here as well. Look for and expand the "Android SDK Build-Tools" entry, then make sure that 23.0.1 is selected.

Finally, click "Apply" to download and install the Android SDK and related build tools.


4) . Configure the ANDROID_HOME environment variable
The React Native tools require some environment variables to be set up in order to build apps with native code.

Add the following lines to your $HOME/.bash_profile config file:

export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools

<But in my case, path was this>
/opt/android-sdk-linux
export ANDROID_HOME=/opt/android-sdk-linux
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools

Running the app on device


1) Enable Debugging over USB
Settings → About phone

2A) sudo apt-get install android-tools-adb

2B) Enter this command: lsusb, this should output something like this:
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 22b8:2e76 Motorola PCS
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

These lines represent the USB devices currently connected to your machine.

You want the line that represents your phone. If you're in doubt, try unplugging your phone and running the command again:


2C) echo SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", MODE="0666", GROUP="plugdev" | sudo tee /etc/udev/rules.d/51-android-usb.rules
-Make sure that you replace 22b8 with the identifier you get in the above command.
echo SUBSYSTEM=="usb", ATTR{idVendor}=="2717", MODE="0666", GROUP="plugdev" | sudo tee /etc/udev/rules.d/51-android-usb.rules
2717

3) react-native run-android

4) Add the hostname in device
Dev settings -> Debug server host and port for device
Enter the computer's ip address and port.
192.168.0.1:8081

5) react-native start

6) Clear the app from RAM and re-open

7) Here goes your app, :)


Create unsignesh apk
http://bitstopixels.blogspot.in/2017/05/installing-react-native-unsigned-debug.html



*********

ISSUES  I GOT


ISSUE1 running react-native run-android
Exception in thread "main" javax.net.ssl.SSLException: java.security.ProviderException: java.security.InvalidKeyException: EC parameters error


SOL1: Install JDK 8 or above.
https://askubuntu.com/questions/464755/how-to-install-openjdk-8-on-14-04-lts
Original Message
If you really want to use OpenJDK, you have to compile from source. There is not still any PPA for OpenJDK.

It has been requested at https://bugs.launchpad.net/ubuntu/+bug/1297065

I recommend you to use Webup8 Oracle Java8 Installer

sudo add-apt-repository ppa:webupd8team/java -y
sudo apt-get update
sudo apt-get install oracle-java8-installer
To automatically set up the Java 8 environment variables

sudo apt-get install oracle-java8-set-default
Check it

java -version
So you have to wait to use OpenJDK8


SOL2:
:-JAVA_HOME path variable was not installed.
https://github.com/facebook/react-native/issues/14091
export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64"
export PATH=$JAVA_HOME/bin:$PATH




Issue2:- creating react-native run-android from git project, that is already created...
ERROR: Android project not found. Maybe run react-native android first?
SOLUTION: run: react-native upgrade
- https://stackoverflow.com/questions/43723958/react-native-android-project-not-found-maybe-run-react-native-android-first

Issue3:  ERROR  watch /home/shubham/shubham/shubham/projects/react-native/awesomeProject/node_modules/lodash._reevaluate ENOSPC
SOLUTION1: install watchman

Issue4:-
All these above steps work well but when I ran with react-native-camera, the app build used to hand when I ran "react-native run-android" like this:
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...
File /home/shubham/.android/repositories.cfg could not be loaded.
Checking the license for package Android SDK Platform 25 in /opt/android-sdk-linux/licenses
License for package Android SDK Platform 25 accepted.
Preparing "Install Android SDK Platform 25".
> Configuring > 3/3 projects
Solution1:
Could be due to build-tools verion 25, installing sdk-build tools [25.0.2, 27.0.2,23.0.1], Android sdk platform-tools, android sdk tools solved this problem.
If not, please try installing all sdk-build tools for version 25.x.x to 27.x.x

ISSUE5: Watchman crawl failed. Retrying once with node crawler.
SOLUTION1:
Try running these commands
echo 999999 | sudo tee -a /proc/sys/fs/inotify/max_user_watches
echo 999999 | sudo tee -a /proc/sys/fs/inotify/max_queued_events
echo 999999 | sudo tee -a /proc/sys/fs/inotify/max_user_instances
SOLUTION2:
If solution1 does not work, try shutdown webpack by this command:
watchman shutdown-server

****************************************************************************************************************
****************************************************************************************************************