Continuous delivery of react app with Jenkins and Docker

Evheniy Bystrov
HackerNoon.com
7 min readFeb 18, 2018

--

It’s the second part of article — React app from scratch. I’ll show you how to create a CD process to make your app better from scratch.

Before we start I’ll put useful links.

First part of article:

Other my article — how to start using Docker:

If your project is open source — you can use Travis CI. You just need to create .travis.yml like this:

And see result:

But I want to show you how to create CI/CD environment from scratch.

We will use Jenkins with Docker. Jenkins has official image on docker hub.

All configs you can find on github: https://github.com/evheniy/react-app/tree/master/jenkins

Jenkins

To run Jenkins using official image from docker hub we need to run next command:

But we need to store our data if we need to update image or restart container. So we need to map volume to host machine:

We will use docker not only for running Jenkins. With docker we can run docker registry and we can test and create images for our react app.

Registry

To run docker registry using docker image on docker hub run:

To push a new image to registry use next commands:

Docker compose

To run registry with Jenkins I’ll use docker-compose.

But before I’ll create Dockerfile for Jenkins. We need it for running docker inside docker.

And put:

Here I use latest image of Jenkins and run it as root.

Now we are ready to use docker-compose.

Let’s create docker-compose file for running Jenkins and docker repository in one command:

And one more. As we need to run docker inside docker we need to add more volumes. But first run command:

And put next code:

To run it use

And to stop:

To bring everything down (with volumes):

Or if you want to remove docker images:

So let’s run it and configure Jenkins to use pipeline.

Open http://localhost:8080/:

To see the password just run (we need it only once):

And enter it on page:

And as it’s our first run we see configuration page:

I choose the second point and check next plugins:

Click install and wait:

If you check directory we have a lot of Jenkins files:

After you need to create a new user:

And that’s all. Jenkins is ready.

Next we need to create a new build. You can make it from start page:

On first step we need to enter name and choose type of our build configurations:

I use multibranch pipeline configuration.

Next we need to configure our build (name, access to github)

And some other configs like cleaning and scanning time.

As I made it for react-app I use the same github repo (https://github.com/evheniy/react-app)

And after Jenkins scans it

Configs

Next step is creating Jenkinsfile, Dockerfile, Dockerfile.test and save it on github:

Dockerfile

Dockerfile.test

And after rescanning Jenkins checks it:

And logs:

We see a lot of interesting information.

Now we can check that our image stored in our registry. Run command:

Now you can run this image on production server.

In this article I created docker compose file for running Jenkins and Docker registry. I created Jenkinsfile and Dockerfile for testing and releasing our app.

In next articles I’ll show how to use SSR, modular structure, webpack optimization, chaos monkey, testing and code coverage…

--

--

Evheniy Bystrov
HackerNoon.com

I can help with IT infrastructure (AWS), apps (Node.js + React) and teams.