Exercise 6:
Module Name: Implementation of CICD with Java and open source stack
Write a build script to build the application using a build automation tool like Maven. Create a folder
structure that will run the build script and invoke the various software development build stages. This
script should invoke the static analysis tool and unit test cases and deploy the application to a web
application server like Tomcat.
What is Maven
Maven is a powerful project management tool that is based on POM (project object model). It is
used for projects build, dependency and documentation. It simplifies the build process like ANT.
But it is too much advanced than ANT.
In short terms we can tell maven is a tool that can be used for building and managing any Java-
based project. maven make the day-to-day work of Java developers easier and generally help with
the comprehension of any Java-based project.
What maven does
Maven does a lot of helpful task like
1. We can easily build a project using maven.
2. We can add jars and other dependencies of the project easily using the help of maven.
3. Maven provides project information (log document, dependency list, unit test reports etc.)
4. Maven is very helpful for a project while updating central repository of JARs and other
dependencies.
5. With the help of Maven we can build any number of projects into output types like the JAR,
WAR etc without doing any scripting.
6. Using maven we can easily integrate our project with source control system (such as
Subversion or Git).
How maven works?
Core Concepts of Maven:
1. POM Files: Project Object Model(POM) Files are XML file that contains information related to
the project and configuration information such as dependencies, source directory, plugin, goals
etc. used by Maven to build the project. When you should execute a maven command you give
maven a POM file to execute the commands. Maven reads pom.xml file to accomplish its
configuration and operations.
2. Dependencies and Repositories: Dependencies are external Java libraries required for
Project and repositories are directories of packaged JAR files. The local repository is just a
directory on your machine hard drive. If the dependencies are not found in the local Maven
repository, Maven downloads them from a central Maven repository and puts them in your local
repository.
3. Build Life Cycles, Phases and Goals: A build life cycle consists of a sequence of build
phases, and each build phase consists of a sequence of goals. Maven command is the name
of a build lifecycle, phase or goal. If a lifecycle is requested executed by giving maven
command, all build phases in that life cycle are executed also. If a build phase is requested
executed, all build phases before it in the defined sequence are executed too.
4. Build Profiles: Build profiles a set of configuration values which allows you to build your
project using different configurations. For example, you may need to build your project for your
local computer, for development and test. To enable different builds you can add different build
profiles to your POM files using its profiles elements and are triggered in the variety of ways.
5. Build Plugins: Build plugins are used to perform specific goal. you can add a plugin to the
POM file. Maven has some standard plugins you can use, and you can also implement your
own in Java.
Installation process of Maven
The installation of Maven includes following Steps:
1. Verify that your system has java installed or not. if not then install java (Link for Java
Installation )
2. Check java Environmental variable is set or not. if not then set java environmental variable.(link
to install java and setting environmental variable )
3. Download maven (Link)
4. Unpack your maven zip at any place in your system.
5. Add the bin directory of the created directory apache-maven-3.5.3(it depends upon your
installation version) to the PATH environment variable and system variable.
6. open cmd and run mvn -v command. If it print following lines of code then installation
completed.
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-
25T01:19:05+05:30)
Maven home: C:\apache-maven-3.5.3\bin\..
Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_151\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
Maven pom.xml file
POM means Project Object Model is key to operate Maven. Maven reads pom.xml file to
accomplish its configuration and operations. It is an XML file that contains information related to
the project and configuration information such as dependencies, source directory, plugin, goals
etc. used by Maven to build the project.
The sample of pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId> com.project.loggerapi </groupId>
<artifactId>LoggerApi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- Add typical dependencies for a web
application -->
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j<
/groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.0</version>
</dependency>
</dependencies>
</project>
Elements used for Creating pom.xml file
1. project- It is the root element of the pom.xml file.
2. modelVersion- modelversion means what version of the POM model you are using. Use
version 4.0.0 for maven 2 and maven 3.
3. groupId- groupId means the id for the project group. It is unique and Most often you will use a
group ID which is similar to the root Java package name of the project like we used the groupId
com.project.loggerapi.
4. artifactId- artifactId used to give name of the project you are building.in our example name of
our project is LoggerApi.
5. version- version element contains the version number of the project. If your project has been
released in different versions then it is useful to give version of your project.
Other Elements of Pom.xml file
1. dependencies- dependencies element is used to defines a list of dependency of project.
2. dependency- dependency defines a dependency and used inside dependencies tag. Each
dependency is described by its groupId, artifactId and version.
3. name- this element is used to give name to our maven project.
4. scope- this element used to define scope for this maven project that can be compile, runtime,
test, provided system etc.
5. packaging- packaging element is used to packaging our project to output types like JAR, WAR
etc.
Maven Repository
Maven repositories are directories of packaged JAR files with some metadata. The metadata are
POM files related to the projects each packaged JAR file belongs to, including what external
dependencies each packaged JAR has. This metadata enables Maven to download dependencies
of your dependencies recursively until all dependencies are download and put into your local
machine.
Maven has three types of repository :
1. Local repository
2. Central repository
3. Remote repository
Maven searches for dependencies in this repositories. First maven searches in Local repository
then Central repository then Remote repository if Remote repository specified in the POM.
1. Local repository- A local repository is a directory on the machine of developer. This repository
contains all the dependencies Maven downloads. Maven only needs to download the
dependencies once, even if multiple projects depends on them (e.g. ODBC).
By default, maven local repository is user_home/m2 directory.
example – C:\Users\asingh\.m2
2. Central repository- The central Maven repository is created Maven community. Maven looks
in this central repository for any dependencies needed but not found in your local repository.
Maven then downloads these dependencies into your local repository.
3. Remote repository- remote repository is a repository on a web server from which Maven can
download dependencies.it often used for hosting projects internal to organization. Maven then
downloads these dependencies into your local repository.
Practical Application Of Maven
When working on a java project and that project contains a lot of dependencies, builds,
requirement, then handling all those things manually is very difficult and tiresome. Thus using
some tool which can do these works is very helpful.
Maven is such a build management tool which can do all the things like adding dependencies,
managing the classpath to project, generating war and jar file automatically and many other things.
Pros and Cons of using Maven
Pros:
1. Maven can add all the dependencies required for the project automatically by reading pom file.
2. One can easily build their project to jar, war etc. as per their requirements using Maven.
3. Maven makes easy to start project in different environments and one doesn’t needs to handle
the dependencies injection, builds, processing, etc.
4. Adding a new dependency is very easy. One has to just write the dependency code in pom file.
Cons:
5. Maven needs the maven installation in the system for working and maven plugin for the ide.
6. If the maven code for an existing dependency is not available, then one cannot add that
dependency using maven.
When should someone use Maven
One can use the Maven Build Tool in the following condition:
7. When there are a lot of dependencies for the project. Then it is easy to handle those
dependencies using maven.
8. When dependency version update frequently. Then one has to only update version ID in pom
file to update dependencies.
9. Continuous builds, integration, and testing can be easily handled by using maven.
10. When one needs an easy way to Generating documentation from the source code, Compiling
source code, Packaging compiled code into JAR files or ZIP files.
Exercise 7:
Module Name: Implementation of CICD with Java and open source stack
Configure the Jenkins tool with the required paths, path variables, users and pipeline views.
Jenkins has the most optimal product community and set of really useful plugins that suits
most of your software projects: you can build software, deploy software, websites, portals
to various places (e.g including AWS, DigitalOcean, bare metal servers) or to run unit tests.
It can be integrated with communication tools of your choice, like Slack, HipChat or email.
If you haven't had a chance to try Jenkins earlier, feel free to use the tutorial below to get
started.
Manual installation
In order to install Jenkins, we will need:
Unix system. I would recommend a Debian-based machine, like Ubuntu server LTS
Java runtime environment installed. I usually use Java 8
Get base Jenkins setup
Install necessary plugins
Put everything behind your web server.
Install Java
The easiest way to install Java is through the apt-get package manager:
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
Once you added ppa above, you can install java with the following command:
sudo apt-get install oracle-java8-installer
Get base Jenkins Setup
You will need to execute a series of the following commands, namely: add the Jenkins
signing key, register Jenkins apt sources, update package lists, and install Jenkins
package.
wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add
-
sudo echo deb http://pkg.jenkins-ci.org/debian binary/ >
/etc/apt/sources.list.d/jenkins.list
sudo apt-get update
sudo apt-get install jenkins
By default, it will install the base Jenkins setup, which is insecure. You will need to go to
the host where your Jenkins is installed, for example: http://jenkins-host:8080/.
Navigate to Manage Jenkins (on the left) and choose the "Configure Global Security" item
on the page loaded.
Now look below on the Matrix-based security (select it, if it is not selected previously), and
make sure Anonymous only has the "Read" right under the View group.
Click Save at the bottom of the page. After the page reloads, you'll see a login form, but
simply ignore that and
go to the home page (like, for example, http://jenkins-host:8080/). You'll see this signup
form, and the first signed up account will be the administrator.
The Power of Plugins
Jenkins would not be so powerful without plugins. Usually, I install these plugins by default:
Bitbucket:
The BitBucket plugin is designed to offer integration between BitBucket and
Jenkins. BitBucket offers a Jenkins hook, but this one just triggers a build for a
specific job on commit, nothing more. The BitBucket plugin, like the GitHub plugin,
uses the POST hook payload to check which job has to get triggered based on the
changed repository/branch.
Plugin URL: https://wiki.jenkins-ci.org/display/JENKINS/BitBucket+Plugin
bitbucket-pullrequest-builder :
This plugin builds pull requests from Bitbucket.org. This is a must-have plugin if you
perform QA deploy for each submitted pull request.
Plugin
URL: https://wiki.jenkins-ci.org/display/JENKINS/Bitbucket+pullrequest+builder+plug
in
build-pipeline-plugin :
This plugin provides a Build Pipeline View of upstream and downstream connected
jobs that typically form a build pipeline. In addition, it offers the ability to define
manual triggers for jobs that require intervention prior to execution, e.g. an approval
process outside of Jenkins. Provides nice visualization of the paths & flows.
Plugin URL: https://wiki.jenkins-ci.org/display/JENKINS/Build+Pipeline+Plugin
copyartifact:
Adds a build step to copy artifacts from another project. The plugin lets you specify
which build to copy artifacts from (e.g. the last successful/stable build, by build
number, or by a build parameter). You can also control the copying process by
filtering the files being copied, specifying a destination directory within the target
project, etc.
Plugin URL: https://wiki.jenkins-ci.org/display/JENKINS/Copy+Artifact+Plugin
credentials:
Adds a build step to copy artifacts from another project. The plugin lets you specify
which build to copy artifacts from (e.g. the last successful/stable build, by build
number, or by a build parameter). You can also control the copying process by
filtering the files being copied, specifying a destination directory within the target
project, etc.
Plugin URL: https://wiki.jenkins-ci.org/display/JENKINS/Credentials+Plugin
delivery-pipeline-plugin :
Visualisation of Delivery/Build Pipelines, renders pipelines based on
upstream/downstream jobs. When using Jenkins as a build server it is now possible
with the Delivery Pipeline Plugin to visualise one or more Delivery Pipelines in the
same view even in full screen.
Plugin URL: https://wiki.jenkins-ci.org/display/JENKINS/Delivery+Pipeline+Plugin
environment-script:
Environment Script Plugin allows you to have a script run after SCM checkout,
before the build. If the script fails (exit code isn't zero), the build is marked as failed.
Any output on standard out is parsed as environment variables that are applied to
the build. It supports "override syntax" to append paths to PATH-like variables.
Plugin URL: https://wiki.jenkins-ci.org/display/JENKINS/Environment+Script+Plugin
git:
Supports popular git version control system
ghprb:
This plugin builds pull requests in GitHub. It's another must-have plugin if your
software development life cycle includes deploying pull requests to PR environment
to test.
Plugin
URL: https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugi
n
greenballs: The funniest plugin - changes Jenkins to use green balls instead of
blue for successful builds.
Plugin URL: https://wiki.jenkins-ci.org/display/JENKINS/Green+Balls
hipchat:
This plugin allows your team to setup build notifications to be sent to HipChat
rooms.To enable notifications, add "HipChat Notifications" as a post-build step.
Plugin URL: https://wiki.jenkins-ci.org/display/JENKINS/HipChat+Plugin
junit:
Allows JUnit-format test results to be published. Note: number of tools, including
Karma, PhpUNIT & other tools allow to publish test results in a JUnit format. Thus,
this is a must-have plugin for unit test flows.
Plugin URL: https://wiki.jenkins-ci.org/display/JENKINS/JUnit+Plugin
matrix-auth:
Offers matrix-based security authorization strategies (global and per-project). This is
quite handy if you have shared build server across several teams.
Plugin
URL: https://wiki.jenkins-ci.org/display/JENKINS/Matrix+Authorization+Strategy+Plu
gin
parameterized-trigger :
This plugin lets you trigger new builds when your build has completed, with various
ways of specifying parameters for the new build.
You can add multiple configurations: each has a list of projects to trigger, a
condition for when to trigger them (based on the result of the current build), and a
parameters section.
Plugin
URL: https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Trigger+Plugin
rebuild:
This plays nice with the parameterized-trigger plugin. The plug-in allows the user to
rebuild a parametrized build without entering the parameters again.
Plugin URL: https://wiki.jenkins-ci.org/display/JENKINS/Rebuild+Plugin
ssh: You can use the SSH Plugin to run shell commands on a remote machine via
ssh.
Plugin URL: https://wiki.jenkins-ci.org/display/JENKINS/SSH+plugin
s3: Allows uploading artifacts to S3 with multiple options.
Plugin URL: https://wiki.jenkins-ci.org/display/JENKINS/S3+Plugin
throttle-concurrents:
This plugin allows for throttling the number of concurrent builds of a project running
per node or globally.
Unfortunately, this is also a must-have plugin for Node (0.10-0.12) projects with
NPM - two concurrent npm installs often fail.
Plugin
URL: https://wiki.jenkins-ci.org/display/JENKINS/Throttle+Concurrent+Builds+Plugin
Plugins are installed using Plugin manager on a Manage Jenkins Section.
Putting Jenkins Behind a Web Server
Usually I hide Jenkins behind nginx. A typical configuration looks like the one below:
server {
listen 443 ssl;
server_name jenkins.vagrant.dev;
ssl_certificate /etc/nginx/jenkins_selfsigned.crt;
ssl_certificate_key /etc/nginx/jenkins_selfsigned.key
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_connect_timeout 150;
proxy_send_timeout 100;
proxy_read_timeout 100;
}}
Automated installation
Do I install Jenkins manually each time? Of course not, I do it often for my customers.
With ansible, and sa-box-jenkins role new Jenkins installation can be deployed while you
drink your coffee.
Let's prepare a basic bootstrap project that can be used by you in the future.
It includes following files:
bootstrap.sh - installs ansible alongside with dependencies.
init.sh - initializes 3rd party dependencies
.projmodules - fully compatible with .gitmodules git syntax, specifies list of the
dependencies
that will be used by the playbook.
In particular, it includes ansible- by default developer_recipes (repository with set of
handy deployment recipes)
and ansible role called sa-box-bootstrap responsible for box securing steps
(assuming you plan to put Jenkins on remote hosts).
[submodule "public/ansible_developer_recipes"]
path = public/ansible_developer_recipes
url = [email protected]:Voronenko/ansible-developer_recipes.git
[submodule "roles/sa-box-bootstrap"]
path = roles/sa-box-bootstrap
url = [email protected]:softasap/sa-box-bootstrap.git
[submodule "roles/sa-box-jenkins"]
path = roles/sa-box-jenkins
url = [email protected]:softasap/sa-box-jenkins.git
hosts - list here the initial box credentials that were provided to you for the server.
Note: jenkins-bootstrap assumes you have the fresh box with root access only. If
your box already secured, adjust credentials appropriately
[jenkins-bootstrap]
jenkins_bootstrap ansible_ssh_host=192.168.0.17 ansible_ssh_user=yourrootuser
ansible_ssh_pass=yourpassword
[jenkins]
jenkins ansible_ssh_host=192.168.0.17 ansible_ssh_user=jenkins
jenkins_vars.yml - set here specific environment overrides, like your preferred
deploy user name and keys.
jenkins_bootstrap.yml - First step - box securing. Creates jenkins user, and secures
the box using sa-box-bootstrap role.
See more details about the sa-box-bootstrap role
In order, to override params for sa-box-bootstrap - pass the parameters like in the
example below:
- hosts: all
vars_files:
- ./jenkins_vars.yml
roles:
- {
role: "sa-box-bootstrap",
root_dir: "{{playbook_dir}}/public/ansible_developer_recipes",
deploy_user: "{{jenkins_user}}",
deploy_user_keys: "{{jenkins_authorized_keys}}"
jenkins.yml provisioning script that configures jenkins with set of plugins and users.
jenkins_vars.yml configuration options for jenkins deployment.
setup_jenkins.sh shell script that invokes deployment in two steps: initial box
bootstraping & jenkins setup
#!/bin/sh
ansible-playbook jenkins_bootstrap.yml --limit jenkins_bootstrap
ansible-playbook jenkins.yml --limit jenkins
Configuration Options for Automated Installation
You need to override:
jenkins_authorized_keys (this is list of the keys, that allow you to login to Jenkins
box under Jenkins)
jenkins_domain - your agency domain
jenkins_host - name of the Jenkins host (Site will be bound to
jenkins_host.jenkins_domain)
java_version - your Java choice (6,7,8 supported)
jenkins_user: jenkins
jenkins_authorized_keys:
- "{{playbook_dir}}/components/files/ssh/vyacheslav.pub"
jenkins_domain: "vagrant.dev"
jenkins_host: "jenkins"
java_version: 8
-jenkins_users list of users with passwords to create. Admin and deploy are required
users.
Admin is used to manage instance, deploy is used to access the artifacts via deployment
scripts.
If you won't override passwords, the default one will be used (per role), which is not the
best, for public deployments.
jenkins_users:
- {
name: "Admin",
password: "AAAdmin",
email: "no-reply@localhost"
- {
name: "deploy",
password: "DeDeDeDeploy",
email: "no-reply@localhost"
jenkins_plugins Your choice of plugins to install. By default:
jenkins_plugins:
- bitbucket # https://wiki.jenkins-ci.org/display/JENKINS/BitBucket+Plugin
- bitbucket-pullrequest-builder
- build-pipeline-plugin
- copyartifact # https://wiki.jenkins-ci.org/display/JENKINS/Copy+Artifact+Plugin
- credentials # https://wiki.jenkins-ci.org/display/JENKINS/Credentials+Plugin
- delivery-pipeline-plugin #
https://wiki.jenkins-ci.org/display/JENKINS/Delivery+Pipeline+Plugin
- environment-script #
https://wiki.jenkins-ci.org/display/JENKINS/Environment+Script+Plugin
- git
- ghprb #
https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin
- greenballs # https://wiki.jenkins-ci.org/display/JENKINS/Green+Balls
- hipchat # https://wiki.jenkins-ci.org/display/JENKINS/HipChat+Plugin
- junit # https://wiki.jenkins-ci.org/display/JENKINS/JUnit+Plugin
- matrix-auth #
https://wiki.jenkins-ci.org/display/JENKINS/Matrix+Authorization+Strategy+Plugin
- matrix-project
#https://wiki.jenkins-ci.org/display/JENKINS/Matrix+Project+Plugin
- parameterized-trigger
#https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Trigger+Plugin
- rebuild # https://wiki.jenkins-ci.org/display/JENKINS/Rebuild+Plugin
- ssh
- s3 # https://wiki.jenkins-ci.org/display/JENKINS/S3+Plugin
- throttle-concurrents
#https://wiki.jenkins-ci.org/display/JENKINS/Throttle+Concurrent+Builds+Plugin
The Code in Action
You can download this template code from this repository. In order to use it - fork it, adjust parameters to your needs, and use.
Running is as simple as ./setup_jenkins.sh
Note: don’t write highlighted data i.e red colour
Exercise 8:
Module name: Implementation of CICD with Java and open source stack
Configure the Jenkins pipeline to call the build script jobs and configure to run it whenever
there is a change made to an application in the version control system. Make a change to
the background color of the landing page of the web application and check if the
configured pipeline runs.
There are six steps to building a pipeline with Jenkins. But, before you begin those six steps,
make sure you have the following in your system.
Java Development Kit
Knowledge to execute some basic Linux commands
The steps to build CI/CD pipeline with Jenkins are:
1. Download Jenkins
Download Jenkins from the Jenkins downloads page ‘https://www.jenkins.io/download/’.
Download the file ‘Generic Java package (.war)’.
2. Execute Jenkins as a Java binary
Open the terminal window and enter cd <your path>.
Use the command java –jar ./Jenkins. war to run the WAR file.
3. Create a Jenkins Job
Open the web browser and open localhost:8080.
The Jenkins dashboard opens creates new jobs there.
4. Create a Pipeline Job
Select and define what Jenkins job that is to be created.
Select Pipeline, give it a name and click OK.
Scroll down and find the pipeline section.
Either directly write a pipeline script or retrieve the Jenkins file from SCM (Source Code
Management).
5. Configure and Execute a Pipeline Job With a Direct Script
Choose Pipeline script as the Destination and paste the Jenkins file content in the Script from the
GitHub.
Click on Save to keep the changes.
Now click on the Build Now to process the build.
To check the output, click on any stage and click Log; a message will appear on the screen.
6. Configure and Execute a Pipeline With SCM
Copy the GitHub repository URL by clicking on Clone or download.
Now, click on Configure to modify the existing job.
Scroll to the Advanced Project Options setting and select Pipeline script from the SCM option.
Paste the GitHub repository URL here.
Type Jenkinsfile in the Script, and then click on the Save button.
Next, click on Build Now to execute the job again.
There will be an additional stage, in this case, i.e., Declaration: Checkout SCM.
Click on any stage and click on Log.
After you have grasped all the essential steps to build a CI/CD pipeline using Jenkins, a hands-on
demonstration will serve as the icing on the cake.
Demo - To Build a CI/CD Pipeline With Jenkins
Go to your Jenkins Portal:
Click on ‘Create a job’.
In the item name dialog box, you may enter the ‘pipeline’.
Select the pipeline job type in the list below.
Click on OK.
A configuration related to the pipeline opens on the screen.
Scroll down on that page.
There in the dialog box, choose GitHub+Maven.
Some steps will appear on the screen. The next step is to integrate the Jenkins file into the
Version Control system.
So, to do that, you must:
Select ‘Pipeline script from SCM’.
Then in the SCM dialog box, select Git.
‘Jenkins file’ is the name of the Script.
Add the Git repository URL.
You can add the credentials if any.
The credentials can be added with the help of the ‘Add’ option.
Then save the configuration
A page now appears on the screen that gives you various options like ‘Build Now’, ‘Delete
Pipeline’, ‘Configure’, etc.
Click on the Build Now option.
The pipeline will start downloading. The checkout will be visible on the screen and you can see
the build being complete on the screen.
You can go to the console output option to check the log that is taking place.
You will soon be able to see that all the segments of the pipeline are completed. The artifact will
be present to download. The war file can be downloaded using that link.
The entire process helps us understand how the whole Pipeline is configured. Using similar types
of steps, different kinds of automation pipelines can be configured.
Using CI/ CD Pipelines and IndexedDB for a jQuery UI Web Application
Using a simple PostgreSQL database, we’ll be storing some client-side data in IndexedDB
storage. This technique can be a convenient and robust solution for storing some data in the
browser.
Using IndexedDB is a much better alternative to the Document Object Model (DOM) for storing
and querying client-side data because of how easy it is to manage and query data. Let’s get
started with our project.
Creating a New Project
First, create a new directory for our project in a new directory and run this command:
git init
You should see something like the following:
$ mkdir jquery-ui-pipeline-demo $ cd jquery-ui-pipeline-demo $ bin/pipeline create
The “Pipeline create” command lets you specify the template where your code will be built and
tested. This method is like how a knitter uses yarn but in our case, we’re using the web toolbelt
instead of the yarn.
The only difference is that you won’t need to use your own build environment to run tests. The
web toolbelt will do this for you automatically.
That’s all you need to do to create a new project.
Building a jQuery UI Web App Using a Pipeline
To use the pipeline to build your sample app, we will open a new terminal window and type:
$ bin/pipeline build
This command will take a while because it’s building and testing the app on our local
development machine.
After the build process is complete, you can see that the completed project is stored in our
index.html file. We can use these files in other apps or even deploy the app to a server to test it
out.