함수 프레임워크는 모든 함수에 필요한 종속 항목입니다. Cloud Run Functions는 함수 생성 시 이를 자동으로 설치하지만 명확히 하자면 명시적 종속 항목으로 포함하는 것이 좋습니다.
함수에서 비공개 종속 항목을 사용하는 경우 functions-framework를 비공개 레지스트리에 미러링하는 것이 좋습니다. 공개 인터넷에서 패키지를 설치하지 않으려면 미러링된 functions-framework를 함수에 대한 종속 항목으로 포함합니다.
각 함수는 함수에 필요한 추가 gem과 함께 functions_framework gem을 지정하는 Gemfile을 제공해야 합니다. Gemfile은 함수 코드가 포함된 app.rb 파일과 동일한 디렉터리에 있어야 합니다. 또한 함수는 모든 임시 종속 항목과 정확한 버전을 지정하는 lockfile을 제공해야 합니다. 이 Gemfile.lock 파일도 Gemfile과 함께 동일한 디렉터리에 있습니다.
함수를 배포하면 Cloud Run이 bundler를 사용하여 Gemfile 및 Gemfile.lock에 선언된 종속 항목을 다운로드하고 설치합니다.
Gemfile은 선택적 버전 제약조건과 함께 함수에 필요한 패키지를 나열합니다. 자세한 내용은 Gemfile 참조를 확인하세요.
함수와 함께 종속 항목을 패키징하고 배포할 수도 있습니다.
이 방법은 rubygems 패키지 관리자를 통해 종속 항목을 사용할 수 없는 경우에 유용합니다.
gem을 로컬로 패키징하려면 함수의 디렉터리 구조에 있는 디렉터리에 이를 포함하고 종속 항목의 Gemfile 항목에 경로를 제공합니다. gem 디렉터리는 유효한 gemspec 파일을 포함해야 하며 해당 코드가 함수와 함께 배포되도록 함수의 디렉터리 계층 구조 내에 있어야 합니다. 예를 들어 다음과 같은 디렉터리 구조를 사용할 수 있습니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[],[],null,["# The Ruby runtime\n\nYour Cloud Run function runs in an environment consisting of an\noperating system version with add-on packages, language support, and\nthe [Ruby Functions Framework](https://github.com/GoogleCloudPlatform/functions-framework-ruby)\nlibrary that supports and invokes your function. This\nenvironment is identified by the language version, and is known as the\nruntime ID.\n\nFunction preparation\n--------------------\n\nYou can prepare a function directly from the Google Cloud console or write it on\nyour local machine and upload it. To prepare your local machine for Ruby\ndevelopment, see [Set up a Ruby development environment](/ruby/docs/setup).\n\nSupported Ruby runtimes and base images\n---------------------------------------\n\nSelect your runtime\n-------------------\n\nYou can select one of the supported Ruby runtimes for your function during\ndeployment.\n\n\nYou can select a runtime version using the Google Cloud console, or the\ngcloud CLI. Click the tab for instructions on using the tool of\nyour choice: \n\n### gcloud\n\nSpecify the [Ruby base image](/run/docs/configuring/services/runtime-base-images#how_to_obtain_base_images) for your function using the `--base-image` flag,\nwhile deploying your function. For example: \n\n gcloud run deploy \u003cvar translate=\"no\"\u003eFUNCTION\u003c/var\u003e \\\n --source . \\\n --function \u003cvar translate=\"no\"\u003eFUNCTION_ENTRYPOINT\u003c/var\u003e \\\n --base-image ruby34\n\nReplace:\n\n- \u003cvar translate=\"no\"\u003eFUNCTION\u003c/var\u003e with the name of the function you are\n deploying. You can omit this parameter entirely,\n but you will be prompted for the name if you omit it.\n\n- \u003cvar translate=\"no\"\u003eFUNCTION_ENTRYPOINT\u003c/var\u003e with the entry point to your function in\n your source code. This is the code Cloud Run executes when your\n function runs. The value of this flag must be a function name or\n fully-qualified class name that exists in your source code.\n\nFor detailed instructions on deploying a function using the gcloud CLI, see [Deploy functions in Cloud Run](/run/docs/deploy-functions#gcloud).\n\n### Console\n\nYou can select a runtime version when you create or update a Cloud Run function in the Google Cloud console. For detailed\ninstructions on deploying a function, see [Deploy functions in Cloud Run](/run/docs/deploy-functions#deploy-functions).\n\nTo select a runtime in the Google Cloud console when you create a function, follow these steps:\n\n1. In the Google Cloud console, go to the Cloud Run page:\n\n [Go to Cloud Run](https://console.cloud.google.com/run)\n2. Click **Write a function**.\n\n3. In the **Runtime** list, select a Ruby runtime version.\n\n4. Click **Create**, and wait for Cloud Run to create the service\n using a placeholder revision.\n\n5. The console will redirect you to the **Source**\n tab where you can see the source code of your function. Click **Save and redeploy**.\n\nFor detailed instructions on updating the runtime version after your function is\ndeployed, see\n[Re-deploy new source code](/run/docs/deploy-functions#update-code-functions).\n\nSource code structure\n---------------------\n\nFor Cloud Run functions to find your function's definition, your\nsource code must follow a specific structure. See\n[Write Cloud Run functions](/run/docs/write-functions#ruby) for\nmore information.\n\nSpecify dependencies\n--------------------\n\nCloud Run functions written in Ruby use\n[bundler](https://bundler.io) to access dependencies.\n\nThe [Functions Framework](https://github.com/GoogleCloudPlatform/functions-framework-ruby)\nis a required dependency for all functions. Although\nCloud Run functions installs it on your behalf when the function\nis created, we recommend that you include it as an explicit dependency for\nclarity.\n\nIf your\nfunction relies on private dependencies, we recommend that you\nmirror `functions-framework` to your private registry. Include the mirrored\n`functions-framework` as a dependency to your function to avoid installing the\npackage from the public internet.\n\nEach function must provide a `Gemfile` that specifies the `functions_framework`\ngem, along with any additional gems needed by the function. `Gemfile` must be in\nthe same directory as the `app.rb` file that contains your function code. In\naddition, your function must provide a lockfile that specifies all the\ntransitive dependencies and their exact versions. This file, `Gemfile.lock`, is\nalso located in the same directory alongside the `Gemfile`.\n\nWhen you deploy your function, Cloud Run downloads and installs\nthe dependencies declared in the `Gemfile` and `Gemfile.lock` using `bundler`.\n\nThe `Gemfile` lists the packages required by your function, along with any\noptional version constraints. For more details, see the\n[Gemfile reference](https://bundler.io/gemfile.html).\n\nThe following is an example `Gemfile`: \n\n```\nsource \"https://rubygems.org\"\n\ngem \"functions_framework\", \"~\u003e 0.7\"\ngem \"google-cloud-storage\", \"~\u003e 1.29\"\n```\n\n### Packaging local dependencies\n\nYou can also package and deploy dependencies alongside alongside your function.\nThis approach is useful if your dependency is not available using the\n[rubygems package manager](https://rubygems.org/pages/download).\n\nTo package a gem locally, include it in a directory in your function's directory\nstructure, and provide the path in the dependency's `Gemfile` entry. The gem\ndirectory must include a valid `gemspec` file, and it must be located within the\nfunction's directory hierarchy so that its code is deployed along with your\nfunction. For example, you might use a directory structure such as the\nfollowing: \n\n```\nmyfunction/\n├── Gemfile\n├── Gemfile.lock\n├── app.rb\n└── my_private_gem/\n ├── lib/\n | └── my_private_gem.rb\n └── my_private_gem.gemspec\n```\n\nThe `Gemfile` entry might look like this: \n\n```\nsource \"https://rubygems.org\"\n\ngem \"functions_framework\", \"~\u003e 0.7\"\ngem \"my_private_gem\", path: \"./my_private_gem\"\n```\n\nSee the [Gemfile reference](https://bundler.io/gemfile.html) for more discussion\nabout referencing local gem paths."]]