The docker container works just fine when tested locally, upon deployment on cloud run I get 502 bad gateway
. It takes approximately 50 - 60 min then for no reason starts working....causing a site down time. Have been onto this for approximately a week now no success on figuring out why this is happenning.
History:
I was deploying a Vuejs static build before, with the same backend, everything was working fine... i recently re-wrote my front end to Nuxtjs that's when the deployment problems started.
How am testing dockerfile
build:
As recommended by google am using : PORT=8080 && docker run -p 9090:${PORT} -e PORT=${PORT} myImage:latest
check here
Dockfile:
# Alpine Deployment Server
FROM nginx:stable-alpine as alpine-server
# install necessary packages
....
# Start server
CMD pm2 start > pm2.log && \
gunicorn -b 0.0.0.0:5000 --workers 1 --threads 8 --timeout 0 api:app --daemon && \
gunicorn -b 0.0.0.0:5001 --workers 1 --threads 1 --timeout 0 extras:app --daemon && \
nohup sh -c "scrapyrt -p 7000 -i 0.0.0.0" > /dev/null 2>&1 & \
nginx -g 'daemon off;'
NB: Nuxt is also configured to start at 0.0.0.0:3000
am using pm2
to start Nuxt
NGINX CONFIG
server {
listen 8080;
server_name _;
charset utf-8;
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
....
}
location ~^/api/v1/(.+)/search/(.+)$ {
set $allowspace2 $2;
proxy_pass http://127.0.0.1:5000/api/v1/$1/search/$allowspace2;
proxy_http_version 1.1;
proxy_redirect ~^/api/v1/(.+)/search/(.+)$ http://127.0.0.1:5000/api/v1/$1/search/$allowspace2;
....
}
location ~^/api/v1/(.+)/view/(.+)$ {
set $allowspace2 $2;
proxy_pass http://127.0.0.1:5000/api/v1/$1/view/$allowspace2;
proxy_http_version 1.1;
proxy_redirect ~^/api/v1/(.+)/view/(.+)$ http://127.0.0.1:5000/api/v1/$1/view/$allowspace2;
...
}
location ~^/extras/v1/(.+)/(.+)$ {
set $allowspace2 $2;
proxy_pass http://127.0.0.1:5001/extras/v1/$1/$allowspace2;
proxy_http_version 1.1;
proxy_redirect ~^/extras/v1/(.+)/(.+)$ http://127.0.0.1:5001/extras/v1/$1/$allowspace2;
....
}
....
gzip on;
gzip_types text/plain application/xml text/css application/javascript;
gzip_comp_level 6;
gzip_min_length 1000;
gzip_proxied any;
gzip_vary on;
}
What ERROR is logged cloud run when trying to navigate to url during 502 bad Gateway
?
*13 connect() failed (111: Connection refused) while connecting to upstream,....
What bums me out is why ??
Why the upstream are offline, all services are started first then NGINX is started.
Why does it take long and eventually start.
Why it works just locally on deployment to cloud run its just hocus-pocus.
How do I resolve this ??