Ruby로 작성된 Cloud Run Functions는 번들러를 사용하여 종속 항목에 액세스합니다. 종속 항목은 함수 배포 시 또는 함수와 함께 로컬로 패키징될 수 있습니다.
각 함수는 함수에 필요한 추가 gem과 함께 functions_framework gem을 지정하는 Gemfile을 제공해야 합니다. Gemfile은 함수 코드가 포함된 app.rb 파일과 동일한 디렉터리에 있어야 합니다. 또한 함수는 모든 임시 종속 항목과 정확한 버전을 지정하는 lockfile을 제공해야 합니다. 이 Gemfile.lock 파일도 Gemfile과 함께 동일한 디렉터리에 있습니다.
함수를 배포하면 Cloud Run Functions가 bundler를 사용하여 Gemfile 및 Gemfile.lock에 선언된 종속 항목을 다운로드하고 설치합니다.
Gemfile은 선택적 버전 제약조건과 함께 함수에 필요한 패키지를 나열합니다. 자세한 내용은 Gemfile 참조를 확인하세요.
다음 명령어를 실행하여 functions_framework gem 및 기타 종속 항목을 설치합니다.
bundleinstall
Gemfile.lock은 종속 항목을 분석할 때 Bundler에 의해 생성되고 설치할 각 gem의 정확한 버전을 고정합니다. 예를 들어 이렇게 하면 로컬 테스트에 사용된 버전과 동일한 종속 항목 버전으로 함수가 배포됩니다. Gemfile.lock의 정확한 형식은 Bundler에게만 공개되며 직접 수정할 수 없습니다.
이미 Bundler를 사용하여 종속 항목을 설치하고 테스트를 로컬에서 실행하고 있다면 이미 Gemfile.lock 파일이 있을 수 있습니다. 그렇지 않은 경우 다음을 실행하여 생성할 수 있습니다.
bundlelock
함수 프레임워크는 모든 함수에 필요한 종속 항목입니다. Cloud Run Functions는 함수 생성 시 이를 자동으로 설치하지만 명확히 하자면 명시적 종속 항목으로 포함하는 것이 좋습니다.
함수에서 비공개 종속 항목을 사용하는 경우 functions-framework를 비공개 레지스트리에 미러링하는 것이 좋습니다. 공개 인터넷에서 패키지를 설치하지 않으려면 미러링된 functions-framework를 함수에 대한 종속 항목으로 포함합니다.
로컬 종속 항목 패키징
함수와 함께 종속 항목을 패키징하고 배포할 수도 있습니다.
이 방법은 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-05(UTC)"],[[["\u003cp\u003eRuby functions in Cloud Run utilize Bundler to manage dependencies, which can be downloaded during deployment or packaged locally with the function.\u003c/p\u003e\n"],["\u003cp\u003eEach function requires both a \u003ccode\u003eGemfile\u003c/code\u003e listing dependencies, including the \u003ccode\u003efunctions_framework\u003c/code\u003e gem, and a \u003ccode\u003eGemfile.lock\u003c/code\u003e file specifying the exact versions of all transitive dependencies, located in the same directory as the function code.\u003c/p\u003e\n"],["\u003cp\u003eTo install dependencies locally, the \u003ccode\u003ebundle install\u003c/code\u003e command is used, generating a \u003ccode\u003eGemfile.lock\u003c/code\u003e if one does not exist, or the \u003ccode\u003ebundle lock\u003c/code\u003e command to generate one if it does not exist.\u003c/p\u003e\n"],["\u003cp\u003eLocal gems can be packaged by including them in a subdirectory within the function's directory structure, specifying their path in the \u003ccode\u003eGemfile\u003c/code\u003e, useful for private or unavailable dependencies through the public rubygems package manager.\u003c/p\u003e\n"],["\u003cp\u003eWhile Cloud Run installs the \u003ccode\u003efunctions_framework\u003c/code\u003e, it's recommended to include it as an explicit dependency in the \u003ccode\u003eGemfile\u003c/code\u003e for clarity, especially when mirroring \u003ccode\u003efunctions-framework\u003c/code\u003e to a private registry for private dependencies.\u003c/p\u003e\n"]]],[],null,["# Specify dependencies in Ruby\n============================\n\nCloud Run functions written in Ruby use\n[bundler](https://bundler.io) to access\ndependencies. Dependencies can be downloaded when your function is deployed, or\npackaged locally alongside your function.\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 functions 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\nYou run the following command to install the `functions_framework` gem and other\ndependencies: \n\n bundle install\n\nThe `Gemfile.lock` is generated by bundler when it analyzes your dependencies,\nand freezes the exact versions of each gem to be installed. This ensures, for\nexample, that your function is deployed with the same dependency versions as\nthose used in your local tests. The exact format of the `Gemfile.lock` is\nprivate to bundler and is not meant to be edited by hand.\n\nIf you have already used bundler to install your dependencies and run tests\nlocally, you probably already have a `Gemfile.lock` file present. If not, you\ncan generate one by running: \n\n bundle lock\n\nThe [Functions Framework](/functions/docs/functions-framework) is a\nrequired dependency for all functions. Although Cloud Run functions\ninstalls it on your behalf when the function is created, we recommend\nthat you include it as an explicit dependency for clarity.\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\nPackaging local dependencies\n----------------------------\n\nYou can also package and deploy dependencies alongside alongside your function.\nThis approach is useful if your dependency is not available via 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\n[Gemfile reference](https://bundler.io/gemfile.html)\nfor more discussion about referencing local gem paths."]]