Search code examples
node.jsvisual-studio-codegoogle-cloud-code

VS Code and Cloud Code file sync for static files


I have a project where we use Node.js and Visual Studio Code with the Google Cloud Code extension. The Node.js runs on Cloud Run and I develop locally with the Cloud Run emulator of Cloud Code. This works fine and even if I change e.g., a .js file, the file gets updated in the container of the emulator.

My launch.json looks something like this:

    {
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Cloud Run: Run/Debug Locally",
            "type": "cloudcode.cloudrun",
            "request": "launch",
            "build": {
                "docker": {
                    "path": "Dockerfile"
                }
            },
            "image": "my_image_name",
            "service": {
                "name": "my_app",
                "containerPort": 8080,
                "env": [
                    {
                        "name": "PROJECT_ID",
                        "value": "some_id"
                    }
                ],
                "resources": {
                    "limits": {
                        "memory": "2028Mi"
                    }
                }
            },
            "target": {
                "minikube": {}
            },
            "watch": true,
            "debug": {
                "sourceFileMap": {
                    "${workspaceFolder}": "/app"
                }
            }
        }
    ]
}

And my Dockerfile something like this:

# Use the official Node.js image as the base image
FROM node:21

# Set the working directory to /app
WORKDIR /app

# Copy the package.json and package-lock.json files to the container
COPY package*.json ./

# Install the dependencies
RUN npm install

# Copy the rest of the application code to the container
COPY . .

# Build the app using Webpack
RUN npm run build

# Set the PORT environment variable
ENV PORT=8080

# Expose the port that the app will listen on
EXPOSE $PORT

# Start the Node.js app
# CMD ["npm", "start"]
CMD ["node", "./node_app.js"]

Unfortunately, I did not manage to configure the file sync described here. At the moment, it's quite annoying to work since I have to restart the emulator each time I change a .HTML file and it would be nice if it would update automatically.

I have no experience with Skaffold and I am a bit lost on what I should do. What do I have to do to set up the file sync for .HTML files?


Solution

  • Unfortunately, Cloud Run Emulator does not support file sync and the section you linked to in the documentation should not be there (This applies to our Kubernetes features but not Cloud Run).

    I've filed a request to remove this from the page.