I'm trying to setup a basic nodeJS app on cloud run, built with typescript
On checking the cloud logs I see a warning Container called exit(1).
Hitting the URL of the project just shows Cannot GET /
- Added binding to check that 0.0.0.0 as well as localhost will work
- I've tried using cloud-build to avoid the problems with building arm on M1 mac
- I also tried building with Docker where my Dockerfile looks like this
#!/bin/sh
# image with bin/sh but not bin/bash
FROM node:16-alpine
# needed for node-gyp
RUN apk --no-cache add --virtual .builds-deps build-base python3
# curl
RUN apk add --update curl
# Create and change to the app directory.
WORKDIR /usr/src/app
# Copy local code to the container image.
COPY . ./
# Copy application dependency manifests to the container image.
# A wildcard is used to ensure copying both package.json AND package-lock.json (when available).
# Copying this first prevents re-running npm install on every code change.
COPY package*.json ./
# Install production dependencies.
RUN npm install --omit=dev
ENV PORT 8080
ENV HOST 0.0.0.0
# for testing local run, not needed on GCP?
EXPOSE 8080
# Run the web service on container startup.
# CMD [ "node", "dist/index.js" ]
# CMD [ "npm", "start" ]
CMD npm run start --bind 0.0.0.0:$PORT
I've tried various ways to start the service. I have a justfile with these commands:
# building with a build pack, not docker image
build-pack: build-source
@echo "making build for ${DOCKER_TAG}"
gcloud builds submit --pack image=${DOCKER_TAG}
gcp-submit:
@echo "submitting image: ${DOCKER_TAG}"
gcloud builds submit --tag=${DOCKER_TAG}
# build on an M1 mac for linux/amd64
build-amd: build-source
docker buildx build --platform linux/amd64 -t ${DOCKER_TAG} .
# deploy from existing docker image
deploy-image:
@echo "deploy DOCKER_TAG=${DOCKER_TAG} on PORT=${PORT}"
gcloud run deploy ${GCP_SERVICE_NAME} \
--image ${DOCKER_IMAGE} \
--port=${PORT} \
--allow-unauthenticated \
--platform managed
The image runs fine locally eg:
docker run -p 8080:8080 ${DOCKER_IMAGE}
when deploying I don't get any errors
just deploy-image
deploy DOCKER_TAG=XXXXX:latest on PORT=8080
gcloud run deploy ${GCP_SERVICE_NAME} --image ${DOCKER_IMAGE} --port=${PORT} --allow-unauthenticated --platform managed
Deploying container to Cloud Run service [XXXX] in project [XXX] region [us-west4]
✓ Deploying... Done.
✓ Creating Revision...
✓ Routing traffic...
✓ Setting IAM Policy...
Done.
Service [XXXX] revision [XXXXX-00004-huc] has been deployed and is serving 100 percent of traffic.
Service URL: https://XXXX.a.run.app
(I've XXX'd out the actual URLs)
But then I just get Cannot GET /
on accessing.
So if this was my own infra maybe the app is running but the PORT mapping is broken? Or the proxy doesn't know how to find the backend server?
Not really sure where else to look on GCP. =Pulls Hair=
actual GCP error:
{
"textPayload": "Container called exit(1).",
"insertId": "633625d6000da4e8178f8c46",
"resource": {
"type": "cloud_run_revision",
"labels": {
"project_id": "xxxx",
"location": "us-west4",
"configuration_name": "xxx-app",
"service_name": "xxx-app",
"revision_name": "xxx-app-00003-nef"
}
},
"timestamp": "2022-09-29T23:10:14.894111786Z",
"severity": "WARNING",
"labels": {
"instanceId": "xxx9da465dbd803c39781062c2e1f392e54b524a563aaafa01e7bdb0b769fd62c94898738c506e09f79b1b6"
},
"logName": "projects/xxx/logs/run.googleapis.com%2Fvarlog%2Fsystem",
"receiveTimestamp": "2022-09-29T23:10:14.897307028Z"
}