I want to run a sails.js application on Google Kubernetes Engine. Running the application docker container locally works perfectly. The deployment to GKE is done via gitlab Auto-Devops pipelines. Deploying the application to GKE is working so far and I can access pages of the sails.js application using the generated domain by gitlab-CI - e.g. xyz-review-autodevops-123.my.host.com
But when accessing pages, only the requested page can be loaded - every asset like images, javascript and css files are not loaded but return a 404.
When looking at the nginx-ingress-controller logs in GKE, I see that these url's are requested but result in a 404:
[05/Aug/2018:12:27:25 +0000] "GET /js/cloud.setup.js HTTP/1.1" 404 9 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36" 573 0.004 [my-app-review-autodevops-1232u0-my-app-443] xx.xx.xx.xx:80 9 0.004 404
There are also regularly errors logged as the following. I am not sure if this is related to this issue but still want to mention it in case it is:
error obtaining PEM from secret my-app-1239989/review-autodevops-1232u0-my-app-tls: error retrieving secret my-app-1239989/review-autodevops-1232u0-my-app-tls: secret my-app-1239989/review-autodevops-1232u0-my-app-tls was not found"
My guess is that ingress does not know the requested host for the assets because they are requested as absolute paths (/js/cloud.setup.js
) instead of relative paths (js/cloud.setup.js
) and therefore does not know where to route this request to because the domain information is lost in the request.
But I do now kow how I fix this 404 issue. Would changing all paths to relative paths in sails.js fix it? I even don't know if this can easily be done since quite some are generated by grunt tasks in sails.js and are generated in the absolute form.
Ok, found the error by myself. This was a silly mistake because sails was somehow configured to include grunt
and sails-hook-grunt
only as devdependencies in package.json
.
Since on the production container, NODE_ENV
is set as environment variable, npm install
only installs the production dependencies.
And since grunt is used for manipulating and providing the assets in sails.js, those have just not been generated.
The solution was to move grunt
and sails-hook-grunt
to the dependencies
in package.json
.