trying to debug "502 Bad Gateway" error after deploying react app to gcp? - google-cloud-platform

I've deployed a React app via "gcloud app deploy". The "gcloud app browse" command opens a browser which tries to load for a while but then displays a browser title of "502 Bad Gateway." I found the following troubleshooting page:
https://cloud.google.com/endpoints/docs/openapi/troubleshoot-response-errors#gae_errors
The following info on the troubleshoting page appears to be a good match for my scenario:
"An error code 502 with BAD_GATEWAY in the message usually indicates
that App Engine terminated the application because it ran out of
memory. The default App Engine flexible VM only has 1GB of memory,
with only 600MB available for the application container."
But I don't see any "out of memory" error reference in my logs for this. I think I probably need to ensure that I "gcloud app deploy" with a proper app.yaml file. I'm having problems identifying what is a valid minimum yaml file for my React app for which I can be assured that my "gcloud app deploy" will have the expected result. I found the following reference which appears to be a good starting point:
https://cloud.google.com/endpoints/docs/openapi/get-started-app-engine
^^^ This page refers to the following yaml sample code:
https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/endpoints/getting-started/src/main/appengine/app.yaml
But the url refers to "java-docs-sample" so not sure if this is a vaid yaml file for a React app deployment. Can you provide some guidance on this? I'm really just looking for the minimum yaml file that I can use for a successful deployment. This is the structure of the yaml file that I used for my initial "gcloud app deploy", and the deployment process appeared to indicate success, but not sure if there is any type of fatal flaw here or anything else that may be missing:
runtime: nodejs
env: flex
manual_scaling:
instances: 1
resources:
cpu: 1

From what I understand, you just want a minimal good app.yaml for react apps as the out of memory seems to be the issue if everything else is correct.
A sample app.yaml for react is the following:
# [START runtime]
runtime: nodejs
env: flex
# [END runtime]
# [START handlers]
handlers:
- url: /
static_files: index.html
upload: index.html
# [END handlers]
But you need to modify your handlers according to your needs/ configuration.
502 error sometimes indicates that your app has an issue itself. So it's better to test locally first and make sure your app is working.
Then for the memory part, you can try specifying the instance type to be one with a higher memory. If it still throws the same error then most likely the issue is within your app or dependencies.

I think there is something about react-scripts start that google cloud doesn't like; I've had trouble with this (react app + google cloud deployment) twice in completely different environments (one had docker and one did not); but the first time I never posted anything to stack overflow so I had to go through the pain again :p
Try changing the package.json file to not use react-scripts start when you run npm run start.
Note that this will overwrite the npm run start and npm start command, so if you use this, you can also update the package json with another keyword such as local and change your local running process to involve writing npm run local
"scripts": {
"start": "serve -s build",
"local": "react-scripts start",
"build": "react-scripts build",
...
},
A working repo

Related

AWS Elastic Beanstalk ASP.Net app failing because of Procfile error 'failed to generate rsyslog file with error Procfile could not be parsed'

I have a WebApp I am trying to deploy using Elastic Beanstalk. I have set up a code pipeline to my github repo and code build to build it. The build succeeds, but at the last part of the pipeline (the deploy), there is a failure and the logs say the error is
web: dotnet ./DiscoverOnDemand.dll
I have looked at fellow developers procfiles and mine does not seem to be any different, yet I cannot get it working. Does anyone have any ideas?
Procfile
https://github.com/JerryKumarNZ/DiscoverOnDemand/blob/main/Procfile
I have checked the procfile for extra newlines but there were none, and I can't find any online resource that will 'check procfile' for me
Found the reason, in Rider and I couldn't see it, but when I went to edit the file in GitHub I could see a space at the start before web. Removing this fixed the issue, still not sure why it was invisible in Rider

Deploying simple docker app with docker-compose on Elastic Beanstalk

I have a simple docker app that is able to run for me locally via docker-compose up, and when I send the .yml file to my friend, they are also able to get it up and running on their local machine. However, when I try to deploy it on Elastic Beanstalk, I get errors (specifically, something related to error:open /var/pids/eb-docker-compose-log.pid: no such file or directory, as I'll show below). I've tried to upload multiple times to Elastic Beanstalk, with the same errors. This is a custom app, but they are the same errors I got when I was trying to follow the instructions on https://docker-curriculum.com/#docker-on-aws. Here is the docker-compose.yml for my current app:
version: "3"
services:
server:
image: mfatigati/shop-server
container_name: shop-server
ports:
- "4000:4000"
client:
image: mfatigati/shop-client
depends_on:
- server
ports:
- "3000:3000"
mfatigati/shop-server and mfatigati/shop-client are both Node.JS apps, i.e., FROM node:16 in their Dockerfile.
To deploy this on AWS, I go to my EB console, and then:
Click "Create Application" to take me to the create app screen
Choose "Docker" as the platform
Choose "Upload local code", and upload the above-mentioned .yml file.
Click "Create Application"
Based on the notes here, I think this should be all I need to do (maybe I'm wrong about that?), but I get errors every time that point me to the eb.engine.log file. I've pasted what seems to be the relevant section below, as it is the only section that mentions errors, and it also reflects what appears in the AWS GUI console. The main problem seems reflected by the bit about error:open /var/pids/eb-docker-compose-log.pid: no such file or directory:
2022/02/14 14:17:23.619888 [ERROR] update processes [cfn-hup eb-docker-events healthd eb-docker-compose-events eb-docker-compose-log docker] pid symlinks failed with error Read pid source file /var/pids/eb-docker-compose-log.pid failed with error:open /var/pids/eb-docker-compose-log.pid: no such file or directory
2022/02/14 14:17:23.619901 [ERROR] An error occurred during execution of command [app-deploy] - [Track pids in healthd]. Stop running the command. Error: update processes [cfn-hup eb-docker-events healthd eb-docker-compose-events eb-docker-compose-log docker] pid symlinks failed with error Read pid source file /var/pids/eb-docker-compose-log.pid failed with error:open /var/pids/eb-docker-compose-log.pid: no such file or directory
2022/02/14 14:17:23.619905 [INFO] Executing cleanup logic
2022/02/14 14:17:23.620005 [INFO] CommandService Response: {"status":"FAILURE","api_version":"1.0","results":[{"status":"FAILURE","msg":"Engine execution has encountered an error.","returncode":1,"events":[{"msg":"Instance deployment failed. For details, see 'eb-engine.log'.","timestamp":1644848243,"severity":"ERROR"}]}]}
Any insight would be greatly appreciated! I'm pasting some screenshots below, in case that helps.
GUI corresponding to step 2; GUI corresponding to step 3; GUI errors
I had the same error:open /var/pids/eb-docker-compose-log.pid: no such file or directory error happening for my Docker Compose app when trying to deploy it to my Elastic Beanstalk environment; I'm not sure if my solution will be the same solution you need, but I hope it points you in the right direction (and helps future devs facing a similar problem).
What caused the error for me:
This ...eb-docker-compose-log.pid: no such file... error was a false error that was triggered by a separate issue; my separate error was actually a problem with my application code not finding the environment variables set in my Elastic Beanstalk environment. See below for how I found the problem, and what I did to fix it.
How I found my real problem:
I downloaded the Full Logs:
go to your EB environment
click Logs on the left nav
click the Request Logs dropdown button (at the top right)
click Full Logs
click the Download link once the full logs are ready
Inside of the logs, I found the real problem in the eb-docker/containers/eb-current-app/eb-stdouterr.log file, the issue being that my application code wasn't able to find the environment variables that were setup in my Elastic Beanstalk Software configuration.
In case you're curious what my error said:
panic: required key ONE_OF_MY_ENV_KEYS missing value
(I also had a couple other errors in this log that I fixed, but fixing the error shown above is what ended up solving the ...eb-docker-compose-log.pid: no such file... error).
How I fixed this error:
I turns out that if you use docker-compose.yml, while setting up your environment variables in your Elastic Beanstalk Software configuration, you have to make sure you use the .env file that Elastic Beanstalk creates for you; otherwise (from my own testing), EB only see's/uses the environment variable keys/values you specify in your own .env file or environment: list you can specify in docker-compose.yml.
NOTE: see the Elastic Beanstalk "Environment properties and Environment Variables" and "Referencing environment variables in containers" sections in the docs here, in particular this bit:
"Elastic Beanstalk generates a Docker Compose environment file called .env in the root directory of your application project. This file stores the environment variables you configured for Elastic Beanstalk.
Note
If you include a .env file in your application bundle, Elastic Beanstalk will not generate an .env file."
I solved my problem by updating my docker-compose.yml file to point to the supposed .env file that EB would create for me (by adding env_file: .env to my services that needed it), i.e.:
version: "3"
services:
my_service1:
# ...
env_file: .env
my_service2:
# ...
env_file: .env

Unknown or duplicate parameter: NodeCommand

I'm trying to deploy a Node.js API with Elastic beanstalk.
I want to set the node command to start the app.
This is my nodecommand.config:
option_settings:
aws:elasticbeanstalk:container:nodejs:
NodeCommand: "npm start"
This is my file structure:
Whenever I try to run eb deploy, I get this error:
2020-05-13 19:03:44 INFO Environment update is starting.
2020-05-13 19:03:48 ERROR "option_settings" in one of the configuration files failed validation. More details to follow.
2020-05-13 19:03:48 ERROR Unknown or duplicate parameter: NodeCommand
2020-05-13 19:03:48 ERROR Failed to deploy application.
ERROR: ServiceError - Failed to deploy application.
I just encountered this very same issue. Upon investigation I found that "NodeCommand" is the legacy way to run your application with custom commands.
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.container.html
I removed the ".ebextensions" directory and added a file called "Procfile" to my source directory.
Inside Procfile, try putting the following:
web: npm start
Make sure you update your repository with these changes if necessary before trying to deploy.
Hope this helps!
I used Procfile to deploy app
in Procfile
web: npm run deploy
In package.json, added new command deploy
"scripts": {
"deploy": "npm run build && npm run start"
},
For those who came here through Google, I had a similar problem and was getting this response:
ERROR: ServiceError - Configuration validation exception: Unknown or duplicate parameter: NodeVersion
After trying a lot of things I learned this is now legacy. I deleted that file and added a ProcFile at the root of my application (file name is case sensitive, there doesn't seem to be a required extension), with this line:
web: npm start
That error disappeared (to be replaced by a different one about role permissions, but any progress is good progress, right?).

How do I upload a webpage to Bluemix using the cf CLI?

I'm trying to upload an index.html page to Bluemix using the cf CLI. I'm not sure if I'm approaching this with the right mentality. I'm thinking of uploading this HTML file as we usually do with normal hosting services, through FTP. With Bluemix I assume I should be using the push command in cf and treat this index.html as an app. Is this right?
If this is right, I'm not getting how to use this command. Can you give me an example of full command to push/upload this page?
The cf push command would be the one to use to 'upload' your application to the Bluemix server. However, it does more than just upload. In Bluemix there is a concept of a runtime or buildpack, the idea being this will be the runtime to run your application. So if you uploaded a Java application you would pair it with the Java Liberty Buildpack/runtime. If you uploaded a PHP application then you would pair it with the PHP buildpack.
If you pushed just a HTML file with no buildpack then you would likely get an error indicating the buildpack could not be determined. Bluemix tries to guess the type of buildpack you want based on the type of files uploaded, and then pull the buildpack from an internal cache. The cf push command allows you to explicitly state the buildpack to use -b so there is no guess work and no need to rely on only the buildpack that Bluemix currently knows about.
In your case, for a static HTML file you would need some type of http server like nginx as the 'runtime'. Notice that Bluemix currently does not have a built-in buildpack for this, so you'd have to get it from somewhere else. There are a few buildpacks available already, but the best one to use would be this one: https://github.com/cloudfoundry-community/staticfile-buildpack . To use it simply supply that url with the -b option on the cf push command from the root directory of your application i.e.
cf push yourappname -b https://github.com/cloudfoundry-community/staticfile-buildpack
Be sure you are issuing this command from your app directory.
The yourappname will be part of the URL for your website/app
For an actual example, we will upload your index.html which exist in folder C:\Users\XYZ\Documents\projects\ProjectHelloWorld and we will call this app HelloWorld. Here is what we would do:
C:\> cd C:\Users\XYZ\Documents\projects\ProjectHelloWorld
C:\Users\XYZ\Documents\projects\ProjectHelloWorld> cf push HelloWorld -b https://git
hub.com/cloudfoundry-community/staticfile-buildpack
Bluemix will then upload everything in that local directory to the server and also grab the buildpack from the URL location and stage your application code with the buildpack, Bluemix will then attempt to start the application. This is an example Bluemix output when the push command succeed:
Creating app HelloWorld in org xyz#gmail.com / space test as xyz#gmail.com...
OK
Creating route HelloWorld.mybluemix.net...
OK
Binding HelloWorld.mybluemix.net to HelloWorld...
OK
Uploading HelloWorld...
Uploading app files from: C:\Users\XYZ\Documents\projects\ProjectHelloWorld
Uploading 1M, 21 files
Done uploading
OK
Starting app HelloWorld in org xyz#gmail.com / space test as xyz#gmail.com...
-----> Downloaded app package (960K)
Cloning into '/tmp/buildpacks/staticfile-buildpack'...
grep: Staticfile: No such file or directory
-----> Using root folder
-----> Copying project files into public/
-----> Setting up nginx
grep: Staticfile: No such file or directory
-----> Uploading droplet (3.4M)
1 of 1 instances running
App started
OK
Showing health and status for app HelloWorld in org xyz#gmail.com / space
test as xyz#gmail.com...
OK
requested state: started
instances: 1/1
usage: 1G x 1 instances
urls: HelloWorld.mybluemix.net
last uploaded: Tue Nov 25 14:50:44 +0000 2014
For more details:
See the github page for the buildpack on how to structure your application (public folder etc)
See Bluemix Docs website. It has a lot of demos and examples.
See Takehiko Amano's Bluemix demo. Is a good and easy to understand demo.
you can either deploy your app directly using "cf push ..." or via creating a manifest.yml file.if you create manifest.yml file inside you app code path,only cf push is sufficient.
below is the reference link for this:
http://clouds-with-carl.blogspot.in/2014/02/deploy-minimal-nodejs-application-to.html
Hope it clears your doubt!!
Yeah as whitfiea mentioned its pretty simple. You need to use the cf push command. For example if you had a static website with an index.html file.
For example the following.
[02:30 PM] jsloyer#jeffs-mbp [friendme]>ls
index.html
To push that app to Bluemix run the following.
cf push yourappname -b https://github.com/cloudfoundry-community/staticfile-buildpack.git
https://www.ng.bluemix.net/docs/#starters/index.html
In this browse Creating Web Apps->Building a web app-> Uploading an app
It says;-
You can use a sample Java™ web application to get started. This sample application displays the list of environment variables that are available. You can download the sample Java web application from the community sample site. The sample application contains a single JSP and the WEB-INF/web.xml file.
Extract the downloaded file, and a new directory that contains the application is created. From the newly created application directory, issue the cf push command. In the following example, you can use a unique name testEnv for the application and 512M for memory allocation. The name must be unique in the whole Bluemix environment.
$ cf push testEnv -m 512m
->So as per your requirement, you can add your html file along with the JSP file before uploading the application.
Hopefully this help...

how to read vmc push log

when i use vmc push project to micro cloudfoundry,start application error,
smart tips is below. but i can't find log is my project path.
Uploading Application:
Checking for available resources: OK
Processing resources: OK
Packing application: OK
Uploading (206K): OK
Push Status: OK
Stopping Application: OK
Staging Application: OK
Starting Application: ..........................Error 306: Error retrieving file 'logs/startup.log'
where can found the log?
You can also manually look at files (such as logs) by using vmc files <myapp> path/to/file. For example:
vmc files myapp logs/stderr.log
You ran vmc push to deploy the app. You should be able to run vmc logs myapp to see the logs.
But I have never seen a 306 error like that. I fear that vmc logs myapp might fail for the same underlying reason you got during push.
You should be able to ssh to the Micro Cloud Foundry instance and then track down the logs. They'll be here:
/var/vcap/data/dea/apps/myapp-a-bunch-of-other-letters-and-digits/tomcat