Dockerfile.
Before continuing, make sure you have:
- A Bun application ready for deployment
- A Google Cloud account with billing enabled
- Google Cloud CLI installed and configured
1
Initialize gcloud by select/creating a project
Make sure that you’ve initialized the Google Cloud CLI. This command logs you in, and prompts you to either select an existing project or create a new one.For more help with the Google Cloud CLI, see the official documentation.
terminal
2
(Optional) Store your project info in environment variables
Set variables for your project ID and number so they’re easier to reuse in the following steps.
terminal
3
Link a billing account
List your available billing accounts and link one to your project:Link your billing account to your project. Replace
terminal
[BILLING_ACCOUNT_ID] with the ID of your billing account.terminal
4
Enable APIs and configure IAM roles
Activate the necessary services and grant Cloud Build permissions:
terminal
These commands enable Cloud Run (
run.googleapis.com) and Cloud Build (cloudbuild.googleapis.com), which are required for deploying from source. Cloud Run runs your containerized app, while Cloud Build handles building and packaging it.The IAM binding grants the Compute Engine service account ($PROJECT_NUMBER-compute@developer.gserviceaccount.com) permission to build and deploy images on your behalf.5
Add a Dockerfile
Create a new Create a new
Dockerfile in the root of your project. This file contains the instructions to initialize the container, copy your local project files into it, install dependencies, and start the application.Dockerfile
Make sure that the start command corresponds to your application’s entry point. This can also be
CMD ["bun", "run", "start"] if you have a start script in your package.json.This image installs dependencies and runs your app with Bun inside a container. If your app doesn’t have dependencies, you can omit the RUN bun install --production --frozen-lockfile line.This image installs dependencies and runs your app with Bun inside a container. If your app doesn’t have dependencies, you can omit the RUN bun install --production --frozen-lockfile line..dockerignore file in the root of your project. This file contains the files and directories that should be excluded from the container image, such as node_modules. This makes your builds faster and smaller:.dockerignore
6
Deploy your service
Make sure you’re in the directory containing your
Dockerfile, then deploy directly from your local source:Update the
--region flag to your preferred region. You can also omit this flag to get an interactive prompt to
select a region. Update the --region flag to your preferred region. You can also omit this flag to get an
interactive prompt to select a region.terminal
7
Visit your live application
🎉 Your Bun application is now live!Visit the Service URL (
https://my-bun-app-....us-west1.run.app) to confirm everything works as expected.