ReactJS App on Oracle Kubernetes Engine with Travis CI and GitHub – DZone Web Dev | xxxReactJS App on Oracle Kubernetes Engine with Travis CI and GitHub – DZone Web Dev – xxx
菜单

ReactJS App on Oracle Kubernetes Engine with Travis CI and GitHub – DZone Web Dev

二月 13, 2020 - MorningStar

Over a million developers have joined DZone.

{{announcement.body}}

{{announcement.title}}

Let’s be friends:

1024)” dc-slot=”ads.sl1.slot(articles[0], 0)” tags=”ads.sl1.tags(articles[0], 0)” size=”ads.sl1.size(articles[0], 0)” style=”border:0px;”>
1 && !articles[0].partner.isSponsoringArticle && (width > 1024)” dc-slot=”ads.sb2.slot(articles[0], 0)” tags=”ads.sb2.tags(articles[0], 0)” size=”ads.sb2.size(articles[0], 0)”>

ReactJS App on Oracle Kubernetes Engine with Travis CI and GitHub

DZone ‘s Guide to

ReactJS App on Oracle Kubernetes Engine with Travis CI and GitHub

In this article, we discuss how to deploy a React application on an Oracle Kubernetes Engine with Travic CI and GitHub.

ReactJS App on Oracle Kubernetes Engine with Travis CI and GitHub - DZone Web Dev by

CORE ·

Mar. 23, 20 · Web Dev Zone ·

Free Resource

Join the DZone community and get the full member experience.

Join For Free

Introduction

This article demonstrates the steps required to host a Node application with Oracle Kubernetes Engine (OKE) using Travis Continuous Integration Server. Travis CI is very tightly coupled with GitHub, so any public repository created by you will be visible automatically in Travis. 

This is a development/sample code demo only. You need to optimize the code (given in this article) or write extra code to make it production-quality. You can access the sample code used in this article from here: https://github.com/kumarsirish/sample-travis-oke.

Prerequisites

  1. You should have an account in Oracle Cloud Infrastructure (OCI) and should have access to Developer Services, like Oracle Container Registry (OCIR) and OKE. Get an account from https://www.oracle.com/index.html if you don’t have one.
  2. You should have an OKE cluster configured and running (https://www.oracle.com/webfolder/technetwork/tutorials/obe/oci/oke-full/index.html).
  3. You should have OCI CLI installed (https://oracle.github.io/learning-library/oci-library/DevOps/OCI_CLI/OCI_CLI_HOL.html).
  4. You should have an account in GitHub. 
  5. You should have registered on Travis.
  6. JavaScript runtime environment Node.js is installed in your development environment (https://nodejs.org/en/).

Pipeline Overview

Any check-in in the GitHub project code will trigger an automated build in Travis, which will create the project image and push it to the OCIR. In the deployment step of the build, the image will be pulled from OCIR and deployment to OKE.

ReactJS App on Oracle Kubernetes Engine with Travis CI and GitHub - DZone Web Dev

Pipeline workflow

GitHub and Travis can be configured for the feature branch-based builds or master branch-based builds. Any branch when merged with master automatically triggers a build in Travis.

Bootstrap the ReactJS Project

Bootstrap ReactJS sample-travis-oke project.

Shell

 

x

 

1

$ npx create-react-app sample-travis-oke 

2

$ cd sample-travis-oke 

3

# Change src/App.js for any custom message

4

# Run optimized build

5

$ npm run build

6

$ npm install -g serve

7

# ReactJS Apps can be hosted by Nginx or lightweight "serve" Application. For this tutorial we will be using nginx server but to check the created application you can run "serve" command below to verify the application.

8

$ serve -s build

Containerize the Project

The project will be containerized, along with the following tools:

  • OCI CLI.
  • kubectl command.

Make sure that you have OCI tenancy’s COMPARTMENT_ID value, and I am assuming that your development environment is behind the corporate firewall so set variables HTTP_PROXY and NPM_REGISTRY accordingly.

Below is a sample Dockerfile, which creates the application and also deploys it to the OKE.  
Create the Dockerfile in project directory root.

Dockerfile

 

xxxxxxxxxx
1

38

 

1

$ npx create-react-app sample-travis-oke 

0

2

$ npx create-react-app sample-travis-oke 

1

3

$ npx create-react-app sample-travis-oke 

2

4

$ npx create-react-app sample-travis-oke 

3

5

$ npx create-react-app sample-travis-oke 

4

6

$ npx create-react-app sample-travis-oke 

5

7

$ npx create-react-app sample-travis-oke 

6

8

$ npx create-react-app sample-travis-oke 

7

9

$ npx create-react-app sample-travis-oke 

8

10

$ npx create-react-app sample-travis-oke 

9

11

$ cd sample-travis-oke 

0

12

$ cd sample-travis-oke 

1

13

$ cd sample-travis-oke 

2

14

$ cd sample-travis-oke 

3

15

$ cd sample-travis-oke 

4

16

$ cd sample-travis-oke 

5

17

$ cd sample-travis-oke 

6

18

$ cd sample-travis-oke 

7

19

$ cd sample-travis-oke 

8

20

$ cd sample-travis-oke 

9

21

# Change src/App.js for any custom message

0

22

# Change src/App.js for any custom message

1

23

# Change src/App.js for any custom message

2

24

# Change src/App.js for any custom message

3

25

# Change src/App.js for any custom message

4

26

# Change src/App.js for any custom message

5

27

# Change src/App.js for any custom message

6

28

# Change src/App.js for any custom message

7

29

# Change src/App.js for any custom message

8

30

# Change src/App.js for any custom message

9

31

# Run optimized build

0

32

# Run optimized build

1

33

# Run optimized build

2

34

# Run optimized build

3

35

# Run optimized build

4

36

# Run optimized build

5

37

# Run optimized build

6

38

# Run optimized build

7

Verify that the image is getting built with the following command:

Shell

 

# Run optimized build

8

1

 

1

# Run optimized build

9

2

$ npm run build

0

Verify the Container locally using the below command:

Shell

 

$ npm run build

1

1

 

1

$ npm run build

2

2

$ npm run build

3

The application should now be up and running. Access the application at port 3000 of localhost (http://localhost:3000)

Push to GitHub

This step is required to integrate the project with Travis CI. Create the project repository "sample-travis-oke" in GitHub and push the existing code to this repository.

Shell

 

$ npm run build

4

1

 

1

$ npm run build

5

2

$ npm run build

6

3

$ npm run build

7

4

$ npm run build

8

5

$ npm run build

9

6

$ npm install -g serve

0

7

$ npm install -g serve

1

Feel free to check out GitHub’s information page for more details: https://help.github.com/en/github/importing-your-projects-to-github/adding-an-existing-project-to-github-using-the-command-line

Setup Travis CI

Lets set up Continuous Integration in Travis CI for this project. Here is what we require from Travis:

  1. Build to kick off automatically whenever code is merged-in into the "master" branch.
  2. Build should create the Docker image and push the Docker image to the OCI container registry (OCIR).
  3. Pull the image from OCIR and push to OCI OKE (Oracle Kubernetes Engine).

To do all these, first, you need to login with Travis CI with your GitHub account. This way, all your GitHub public repositories will automatically be visible on Travis. You can check the newly created sample-travis-oke repository from https://travis-ci.org/account/repositories. Click on "Sync account" and refresh the page if you do not see the repository. 

Once synced up with GitHub, a Webhook will automatically appear in the GitHub project like below:

ReactJS App on Oracle Kubernetes Engine with Travis CI and GitHub - DZone Web Dev

Webhook in response to GitHub sync

Set up OCIR  in your tenancy if you haven’t already done so. Refer to this link for more details: https://www.oracle.com/webfolder/technetwork/tutorials/obe/oci/registry/index.html.

In your project settings (e.g https://travis-ci.org/<user_name>/sample-travis-oke/settings), add OCIR_USER, OCIR_PASSWORD, and COMPARTMENT_ID as secret keys. Your Travis project setting screen should be similar to below:

ReactJS App on Oracle Kubernetes Engine with Travis CI and GitHub - DZone Web Dev

  Project Setting Page  

Every Travis project requires a .travis.yml file in the root of the project. Currently, OKE deployment is not supported out-of-the box from Travis, so we need to write our own deployment steps. Make sure that OCI config and Kube config are part of the image. 

A sample Travis file for building the image and pushing to the OKE is given below:

YAML

 

$ npm install -g serve

2

1

16

 

1

$ npm install -g serve

3

2

$ npm install -g serve

4

3

$ npm install -g serve

5

4

$ npm install -g serve

6

5

$ npm install -g serve

7

6

$ npm install -g serve

8

7

$ npm install -g serve

9

8

# ReactJS Apps can be hosted by Nginx or lightweight "serve" Application. For this tutorial we will be using nginx server but to check the created application you can run "serve" command below to verify the application.

0

9

# ReactJS Apps can be hosted by Nginx or lightweight "serve" Application. For this tutorial we will be using nginx server but to check the created application you can run "serve" command below to verify the application.

1

10

# ReactJS Apps can be hosted by Nginx or lightweight "serve" Application. For this tutorial we will be using nginx server but to check the created application you can run "serve" command below to verify the application.

2

11

# ReactJS Apps can be hosted by Nginx or lightweight "serve" Application. For this tutorial we will be using nginx server but to check the created application you can run "serve" command below to verify the application.

3

12

# ReactJS Apps can be hosted by Nginx or lightweight "serve" Application. For this tutorial we will be using nginx server but to check the created application you can run "serve" command below to verify the application.

4

13

# ReactJS Apps can be hosted by Nginx or lightweight "serve" Application. For this tutorial we will be using nginx server but to check the created application you can run "serve" command below to verify the application.

5

14

# ReactJS Apps can be hosted by Nginx or lightweight "serve" Application. For this tutorial we will be using nginx server but to check the created application you can run "serve" command below to verify the application.

6

15

# ReactJS Apps can be hosted by Nginx or lightweight "serve" Application. For this tutorial we will be using nginx server but to check the created application you can run "serve" command below to verify the application.

7

16

# ReactJS Apps can be hosted by Nginx or lightweight "serve" Application. For this tutorial we will be using nginx server but to check the created application you can run "serve" command below to verify the application.

8

Notice the kubectl commands used under deploy section. This section is different for different cloud providers. OCI config files and Kubernetes config file need to be protected. Travis provides a mechanism to encrypt such files and use it internally in build without making its content public. To do so, you need to install Travis CLI in your development environment and use it to encrypt the config files. Refer to https://docs.travis-ci.com/user/encrypting-files#Encrypting-multiple-files for more details.

Shell

 

# ReactJS Apps can be hosted by Nginx or lightweight "serve" Application. For this tutorial we will be using nginx server but to check the created application you can run "serve" command below to verify the application.

9

1

 

1

$ serve -s build

0

2

$ serve -s build

1

3

$ serve -s build

2

The --add option automatically updates the .travis.yml file. You can verify that keys used for encryption are already part of your project settings in Travis.

ReactJS App on Oracle Kubernetes Engine with Travis CI and GitHub - DZone Web Dev

Checking environment variables

Configure OKE Deployment 

Create pod creation and service creation files for the project for OKE. These are just like any other Kubernetes files, and there is nothing OKE specific here. However, make sure that you have OCI config set up, your private key set up, or authentication token and Kubernetes config set up for OKE. Steps to do that are already given above. Sample Kubernetes files for this project will be like the following:

YAML

 

$ serve -s build

3

1

25

 

1

$ serve -s build

4

2

$ serve -s build

5

3

$ serve -s build

6

4

$ serve -s build

7

5

$ serve -s build

8

6

$ serve -s build

9

7

xxxxxxxxxx

0

8

xxxxxxxxxx

1

9

xxxxxxxxxx

2

10

xxxxxxxxxx

3

11

xxxxxxxxxx

4

12

xxxxxxxxxx

5

13

xxxxxxxxxx

6

14

xxxxxxxxxx

7

15

xxxxxxxxxx

8

16

xxxxxxxxxx

9

17

$ npx create-react-app sample-travis-oke 

00

18

$ npx create-react-app sample-travis-oke 

01

19

$ npx create-react-app sample-travis-oke 

02

20

$ npx create-react-app sample-travis-oke 

03

21

$ npx create-react-app sample-travis-oke 

04

22

$ npx create-react-app sample-travis-oke 

05

23

$ npx create-react-app sample-travis-oke 

06

24

$ npx create-react-app sample-travis-oke 

07

25

$ npx create-react-app sample-travis-oke 

08

Deploy on OKE

As part of the Deploy step of Travis build, the following steps are executed within the container:

Shell

 

$ npx create-react-app sample-travis-oke 

09

1

 

1

$ npx create-react-app sample-travis-oke 

10

2

$ npx create-react-app sample-travis-oke 

11

3

$ npx create-react-app sample-travis-oke 

12

4

$ npx create-react-app sample-travis-oke 

13

Keep on giving the kubectl get services command until the external-IP is exposed:

Plain Text

 

$ npx create-react-app sample-travis-oke 

14

1

 

1

$ npx create-react-app sample-travis-oke 

15

2

$ npx create-react-app sample-travis-oke 

16

Use the external IP to load the application.

ReactJS App on Oracle Kubernetes Engine with Travis CI and GitHub - DZone Web Dev

React project running on OKE

Congrats! Your ReactJS application is now running on OKE deployed via Travis.

Topics:
devops ,ci/cd pipeline ,travis ci ,git and github ,kubernetes ,docker ,ci/cd ,reactjs

Opinions expressed by DZone contributors are their own.

Web Dev Partner Resources

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.linkDescription }}

{{ parent.urlSource.name }}

· {{ parent.articleDate | date:’MMM. dd, yyyy’ }} {{ parent.linkDate | date:’MMM. dd, yyyy’ }}



Notice: Undefined variable: canUpdate in /var/www/html/wordpress/wp-content/plugins/wp-autopost-pro/wp-autopost-function.php on line 51