温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/docs/guides/deployment/google-cloud-run
点击访问原文链接

Deploy a Bun application on Google Cloud Run - Bun

Deploy a Bun application on Google Cloud Run - BunSkip to main contentBun home pageSearch...⌘KInstall BunSearch...NavigationDeploymentDeploy a Bun application on Google Cloud RunRuntimePackage ManagerBundlerTest RunnerGuidesReferenceBlogFeedbackdiv:first-child]:!hidden peer-[.is-custom]:[&>div:first-child]:sm:!hidden peer-[.is-custom]:[&>div:first-child]:md:!hidden peer-[.is-custom]:[&>div:first-child]:lg:!hidden peer-[.is-custom]:[&>div:first-child]:xl:!hidden">OverviewGuidesDeploymentDeploy on VercelDeploy on RailwayDeploy on RenderDeploy on AWS LambdaDeploy on DigitalOceanDeploy on Google Cloud RunRuntime & DebuggingTypeScript typesRe-map import pathsVS Code debuggerWeb debuggerHeap snapshotsBuild-time constantsDefine constantsGitHub ActionsCodesign on macOSUtilitiesUpgrade BunDetect BunGet Bun versionHash passwordGenerate UUIDBase64 encodingGzip compressionDEFLATE compressionEscape HTMLDeep equalitySleepFile URL to pathPath to file URLFind executable pathimport.meta.dirimport.meta.fileimport.meta.pathCheck entrypointGet entrypoint pathEcosystem & FrameworksAstro with BunDiscord.js with BunDocker with BunDrizzle with BunGel with BunElysia with BunExpress with BunHono with BunMongoose with BunNeon Drizzle with BunNeon Serverless Postgres with BunNext.js with BunNuxt with BunPM2 with BunPrisma ORM with BunPrisma Postgres with BunQwik with BunReact with BunRemix with BunTanStack Start with BunSentry with BunSolidStart with BunSSR React with BunStricJS with BunSvelteKit with Bunsystemd with BunVite with BunUpstash with BunHTTP & NetworkingHTTP Server with BunSimple HTTP Server with BunFetch with BunHot reload an HTTP serverStart a cluster of HTTP serversConfigure TLSProxy HTTP requests using fetch()Stream file responseUpload files via HTTP using FormDataFetch with unix domain socketsStream with iteratorsStream with Node.jsWebSocketSimple serverPub-sub serverContextual dataEnable compressionProcesses & SystemSpawn child processRead stdoutRead stderrParse command-line argumentsRead from stdinSpawn a child process and communicate using IPCListen for CTRL+COS signalsProcess uptimeRun shell commandSet time zoneSet env variablesRead env variablesPackage ManagerAdd a dependencyAdd a dev dependencyAdd an optional dependencyAdd a peer dependencyAdd a Git dependencyAdd a tarball dependencyInstall with aliasWorkspaces with BunOverride the default npm registryConfigure a scoped registryAzure Artifacts with BunJFrog Artifactory with BunAdd a trusted dependencyGenerate a yarn-compatible lockfileMigrate from npm to bunConfigure git to diff Bun's lockfileInstall Bun in GitHub ActionsTest RunnerRun testsWatch modeMigrate from JestMock functionsSpy on methodsMock system timeSnapshot testingUpdate snapshotsCoverage reportsCoverage thresholdConcurrent test globSkip testsTodo testsTest timeoutBail earlyRe-run testsTesting LibraryDOM testsTest SvelteRuntime & DebuggingVS Code debuggerWeb debuggerHeap snapshotsBuild-time constantsDefine constantsGitHub ActionsCodesign on macOSModule SystemImport JSONImport TOMLImport YAMLImport JSON5Import HTMLimport.meta.dirimport.meta.fileimport.meta.pathCheck entrypointGet entrypoint pathFile SystemRead as stringRead to BufferRead to Uint8ArrayRead to ArrayBufferRead JSON fileGet MIME typeCheck file existsWatch directoryRead as streamWrite string to fileWrite BlobWrite ResponseAppend to fileIncremental writeWrite streamWrite to stdoutWrite file to stdoutCopy fileDelete fileDelete filesDelete directoriesUtilitiesHash passwordGenerate UUIDBase64 encodingGzip compressionDEFLATE compressionEscape HTMLDeep equalitySleepFile URL to pathPath to file URLFind executable pathHTML ProcessingExtract links using HTMLRewriterOpenGraph tagsBinary DataArrayBuffer to stringArrayBuffer to BufferArrayBuffer to BlobArrayBuffer to ArrayArrayBuffer to Uint8ArrayBuffer to stringBuffer to ArrayBufferBuffer to BlobBuffer to Uint8ArrayBuffer to ReadableStreamBlob to stringBlob to ArrayBufferBlob to Uint8ArrayBlob to DataViewBlob to ReadableStreamUint8Array to stringUint8Array to ArrayBufferUint8Array to BufferUint8Array to BlobUint8Array to DataViewUint8Array to ReadableStreamDataView to stringStreamsStream to stringStream to JSONStream to BlobStream to BufferStream to ArrayBufferStream to Uint8ArrayStream to arrayReadable to stringReadable to JSONReadable to BlobReadable to Uint8ArrayReadable to ArrayBufferDeploymentDeploy a Bun application on Google Cloud RunCopy pagespan]:line-clamp-1 overflow-hidden group flex items-center py-0.5 gap-1 text-sm text-gray-950/50 dark:text-white/50 group-hover:text-gray-950/70 dark:group-hover:text-white/70 rounded-none rounded-r-xl border px-3 border-gray-200 aspect-square dark:border-white/[0.07] bg-background-light dark:bg-background-dark hover:bg-gray-600/5 dark:hover:bg-gray-200/5" aria-label="More actions" type="button" id="radix-_R_2shjinpfd9rqaabsnpfdb_" aria-haspopup="menu" aria-expanded="false" data-state="closed">Copy pagespan]:line-clamp-1 overflow-hidden group flex items-center py-0.5 gap-1 text-sm text-gray-950/50 dark:text-white/50 group-hover:text-gray-950/70 dark:group-hover:text-white/70 rounded-none rounded-r-xl border px-3 border-gray-200 aspect-square dark:border-white/[0.07] bg-background-light dark:bg-background-dark hover:bg-gray-600/5 dark:hover:bg-gray-200/5" aria-label="More actions" type="button" id="radix-_R_5hjinpfd9rqaabsnpfdb_" aria-haspopup="menu" aria-expanded="false" data-state="closed">Google Cloud Run is a managed platform for deploying and scaling serverless applications. Google handles the infrastructure for you. In this guide, we will deploy a Bun HTTP server to Google Cloud Run using a 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.terminalCopygcloud init CopyWelcome! This command will take you through the configuration of gcloud. You must sign in to continue. Would you like to sign in (Y/n)? Y You are signed in as [email@example.com]. Pick cloud project to use: [1] existing-bun-app-1234 [2] Enter a project ID [3] Create a new project Please enter numeric choice or text value (must exactly match list item): 3 Enter a Project ID. my-bun-app Your current project has been set to: [my-bun-app] The Google Cloud CLI is configured and ready to use! 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.terminalCopyPROJECT_ID=$(gcloud projects list --format='value(projectId)' --filter='name="my bun app"') PROJECT_NUMBER=$(gcloud projects list --format='value(projectNumber)' --filter='name="my bun app"') echo $PROJECT_ID $PROJECT_NUMBER Copymy-bun-app-... [PROJECT_NUMBER] 3

Link a billing account

List your available billing accounts and link one to your project:terminalCopygcloud billing accounts list CopyACCOUNT_ID NAME OPEN MASTER_ACCOUNT_ID [BILLING_ACCOUNT_ID] My Billing Account True Link your billing account to your project. Replace [BILLING_ACCOUNT_ID] with the ID of your billing account.terminalCopygcloud billing projects link $PROJECT_ID --billing-account=[BILLING_ACCOUNT_ID] CopybillingAccountName: billingAccounts/[BILLING_ACCOUNT_ID] billingEnabled: true name: projects/my-bun-app-.../billingInfo projectId: my-bun-app-... 4

Enable APIs and configure IAM roles

Activate the necessary services and grant Cloud Build permissions:terminalCopygcloud services enable run.googleapis.com cloudbuild.googleapis.com gcloud projects add-iam-policy-binding $PROJECT_ID \ --member=serviceAccount:$PROJECT_NUMBER-compute@developer.gserviceaccount.com \ --role=roles/run.builder 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 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.DockerfileCopy# Use the official Bun image to run the application FROM oven/bun:latest # Copy the package.json and bun.lock into the container COPY package.json bun.lock ./ # Install the dependencies # Install the dependencies RUN bun install --production --frozen-lockfile # Copy the rest of the application into the container COPY . . # Run the application CMD ["bun", "index.ts"] 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.Create a new .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:.dockerignoreCopynode_modules Dockerfile* .dockerignore .git .gitignore README.md LICENSE .vscode .env # Any other files or directories you want to exclude 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.terminalCopygcloud run deploy my-bun-app --source . --region=us-west1 --allow-unauthenticated CopyDeploying from source requires an Artifact Registry Docker repository to store built containers. A repository named [cloud-run-source-deploy] in region [us-west1] will be created. Do you want to continue (Y/n)? Y Building using Dockerfile and deploying container to Cloud Run service [my-bun-app] in project [my-bun-app-...] region [us-west1] ✓ Building and deploying... Done. ✓ Validating Service... ✓ Uploading sources... ✓ Building Container... Logs are available at [https://console.cloud.google.com/cloud-build/builds...]. ✓ Creating Revision... ✓ Routing traffic... ✓ Setting IAM Policy... Done. Service [my-bun-app] revision [my-bun-app-...] has been deployed and is serving 100 percent of traffic. Service URL: https://my-bun-app-....us-west1.run.app 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.

Was this page helpful?

YesNoSuggest editsRaise issueDeploy a Bun application on DigitalOceanPreviousInstall TypeScript declarations for BunNext⌘IxgithubdiscordyoutubePowered by

智能索引记录