Install required package to the system.
$ apt-get update
$ apt-get install curl
$ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash –
$ apt-get install -y nodejs
$ apt-get install -y build-essential
To check npm and Node version :
$ node -v
$ npm -v
Now we will clone the simple react code from github and build it.
$ git clone https://github.com/imvishalvyas/simple-react-app.git
Go to the directory and install npm in to that and create build.
$ cd simple-react-app
$ npm install
$ npm run build # it will create build folder from code.
Now we will deploy that build to the kubernetes deployments. for that we will have require docker for build that code and upload it to docker container, So now we will create one Dockerfile for build.
Build the docker file. It will copy build directory in to docker image container.
$ vim Dockerfile
COPY ./build /var/www
COPY nginx.conf /etc/nginx/nginx.conf
ENTRYPOINT [“nginx”,”-g”,”daemon off;”]
— it will copy your build folder to container.also copy nginx file to the container and expose it to port 80.
Build the images and push to Google container engine. here i am using google container registery for the store docker image which i have build. you can also use docker hub.
To build Docker image :
$ docker build -t us.gcr.io/gcp-project-name/mysite:v1 .
Push Docker image to GCR. this command will push the docker image to google container registery.
$ docker push us.gcr.io/gcp-project-name/mysite:v1