2020-10-29

google cloud build to serve only build folder from react

I'm new to google cloud and I'm trying my best to implement CI / CD on a simple MERN stack application.

I was able to set up google cloud build and get the deploy with automatic triggers (from github branch) to work. I have only one question: in the cloudbuild.yaml file I have inserted several steps, to do first npm install, then npm build and finally deploy. The process is quite slow and it also copies all the code to the server, not just the build folder.

I would like to understand how to configure the file to be able to use the build folder already present in the github repository and do the deploy directly, without further steps. On the frontend I use react, the only thing I have to do is serve the static index.html file.

Here is my current configuration (only the frontend, to understand)

steps:

# Step 0: FRONTEND npm install
- name: "gcr.io/cloud-builders/npm"
  dir: 'frontend'
  args: ['install']
  timeout: "5m"

# Step 1: FRONTEND optimized build
- name: "gcr.io/cloud-builders/npm"
  dir: 'frontend'
  args: ["run", "build"]
  timeout: "5m"

# Step 2: FRONTEND Deploy cloud app frontend
- name: "gcr.io/cloud-builders/gcloud"
  args: ["app", "deploy", "-v", "0-1-2", "app.yaml"]
  dir: 'frontend'
  timeout: "20m"

timeout: 60m

In my remote repository I have the build folder ready to use, but I can't figure out how to do the job.

I've also tried something similar to this: Upload build folder in Google Cloud Build without success.

One of the problems is that at the end of the process it appears that cloud build is trying to start npm start.

Finally, I am currently using express to simply serve static files. Using google cloud can I avoid using it and simply configure the handlers from the app.yaml file? What web server does it use under the hood to serve files if I don't implement express?



from Recent Questions - Stack Overflow https://ift.tt/2TLUpQp
https://ift.tt/eA8V8J

No comments:

Post a Comment