C(′?`*)loud Toolkit 是一個(gè) Google Cloud 提供的命令行工具集,它可以幫助開(kāi)發(fā)者在多個(gè)平臺上部署和管理應用程序,通過(guò)使用 Cl(′?ω?`)oud Toolkit,開(kāi)發(fā)者可以簡(jiǎn)化部署過(guò)程,提高效率,本文將詳細介紹如何使用 Cloud Toolkit 部署應用程序。
安裝 Cloud Tool??kit
1、1 下載并安裝 Cloud Toolkit
需要從 Google?? Cloud 官網(wǎng)下載 Cloud Toolkit 的安裝(zhuang)包,下載??完成后(′▽?zhuān)?),根據操作系統的不??同,選擇相應的安裝方式進(jìn)行安裝。
1、2 配置環(huán)境變量
安裝完成后,需要配置環(huán)境變量,以便在命令行??中使用 Cloud Toolkit,具體操作如下:
Wi??ndows 系統:在“計算機”或“此電腦”上右鍵單擊,選擇“屬性”,然后點(diǎn)擊“高級系統設置”、“環(huán)境變量”,在“系統??變量”下找到“Path”變量,點(diǎn)擊“編輯”,在變量值中添加 Cloud Toolkit 的安???裝路徑下的 bin 文件夾???路徑。
echo 'export PATH=$PATH:/path/to/cl(╯°□°)╯oud-toolk(╯°□°)╯︵ ┻━┻it/bin' >&(???)gt; ~/.bash_profilesource ~/.bash_(╬ ò﹏ó)profile
將 /path/to/cloud-too??lkit 替換為實(shí)際的 Cloud Toolkit 安裝路徑。
創(chuàng )建應用
2、1 登錄 Google Cloud Console
打開(kāi)瀏覽器,(╯°□°)╯訪(fǎng)問(wèn) Google Cloud Console,使用默認的賬號登錄,如果沒(méi)有賬號,請先注冊一個(gè)。
在 Cloud Console 中,點(diǎn)擊左上角的項目下拉菜單,選擇“新建項目”,填寫(xiě)項目名稱(chēng)等信息,然后點(diǎn)擊“創(chuàng )建”。
2、3 啟用 API 控制臺
在左側導(dao)航欄中,點(diǎn)擊“APIs & Services”,然后點(diǎn)擊“Dashboard”,在 AP┐(′ー`)┌I 控制臺頁(yè)??面,點(diǎn)擊右上角的“啟用”按鈕。
部署應用程序
需要在本地創(chuàng )建一個(gè)簡(jiǎn)單的應用程序文件,這里以 Node(?????).js 為例,創(chuàng )建一個(gè)名為 app.js 的文件,內容如下:
const express = require('express');const app = express();const port = 3000;app.get('/', (req, res) => { res(??ヮ?)?*:???.send('Hel(′?`)lo World!');});app.listen(port, () => { console.log(Example app listening at http://localh???ost:${ port});});3、2 將應用程??序文??件上傳到 Cl??oud Storage
在本地運行(′ω`*)上述代碼,啟動(dòng)一個(gè)簡(jiǎn)單的 Web 服務(wù)器,將生成的 app.zip 文件上傳到 Google Cloud Storage,可以使用 gsutil 工具或其他第三方工具(ju)進(jìn)行上傳。
gsutil??? cp app.zip(?Д?) gs://your-bucket-ヽ(′▽?zhuān)?ノname/app.??zip打開(kāi)命令行工具,執行以下命令:
gclou??ヽ(′▽?zhuān)?ノd app deploy app.yaml --image-url=??us-central1-docker.pkg.dev/your-repo/your-image:tag --origin=https://github.com/yourusername/yourrepository.git --region=us-(′_ゝ`)central1 --allow-unauthenti(╯°□°)╯cated --no-promote --quiet --verbosity=info --re(′?_?`)create-pods --timeout=600 --config=app.yaml --version=v1 --project=your-project-id?? --trigger-http --delete-existing --quiet --verbosity=info --re(╯°□°)╯create-pods --timeout(T_T)=600 --config=app.yaml --versi??on=v1 --project=your-project-id --trigger-ヾ(′?`)?htヽ(′?`)ノtp --delete-existing --q??uiet --verbosity=info --recreate-pods --timeout=600 --config=app.y(′▽?zhuān)?aml --version=v1 --project=your-project-??id --trigger-http --delete-existing --quiet --verbosity=info --recreate-pods --timeout=600 --config=app.yaml --version=v1 --project=your-project-id --trigger-http --delete-existing --qu┐(′д`)┌iet --verbosiヾ(′▽?zhuān)??ty=info --recreate-pods --timeout=600 --config=ap??p.yaml --version=v1 --project=your-project-id --trigg??er-http --delete-existing &wait_interval_secs=5 &wait_interval_ms(′?ω?`)=5000 &monitoring_interval_secs┐(′ー`)┌=5 &monitoring_inte(′▽?zhuān)?rval_ms=30000 &logging_interval_secs=300 &logging_i(′ω`*)nterval_ms=30000 &(╬ ò﹏ó)memory_limit_mb=4(′_`) &cpu_limit_quota=50 &enable_stackdriver_monitorin??g=true &stackdriver_moni???toring_pref(′?`)ix=myprefix &stackdriver_m??onitoring_sヽ(′ー`)ノuffix=suffix &env_vars={ "ENV_VAR": "value"} &entrypoi??nt="node app.js" &command="node app.js" &args="" &env_va??rs={ "ENV_VA(′?`)R": "value"} &entrypoint="node app.js" &comma(′ω`)nd="node app.js" &args=&qu(╬ ò﹏ó)ot;" &env_vars={ "ENV_VAR": "value"} &entrypoint="n??ode app.js" &??command="node app.js" &args="" &env_vars={ "ENV_VAR": "value"} &entrypoint="node app.js" &command="node app.js&quヽ(′▽?zhuān)?ノot;(°□°) &args="" &env_vars={ &qヾ(′?`)?uot;ENV_VAR": "value"} &entrypoint="node app.js" &??command="n??ode app.js" &args="??;" &env_var??s={ "ENV_VAR": "value"} &entrypoint="node app.js" &ヽ(′▽?zhuān)?ノcommand="node app.js" &args="" &env_vars={ "ENV_VAR": "val??ue"} &entrypoint="node app.js&quo(′_ゝ`)t; &comma??nd="node app.js(╯‵□′)╯" &args="" &(′;д;`);env_vars={ "ENV_VAR": "value"} &entrypoint="node app.js" &command="node app.js(′?ω?`)" &args="" &env_vars={ "ENV_VAR": "value"} &entrypoint="node app.js" &command="node app.js" &(╯‵□′)╯args="" &env_??vars={ "ENV_VAR": "va(′_ゝ`)lue"} &en(′▽?zhuān)?trypoi??nt="node app.js" &command="node app.js&quo??t; &args=&q┐(′?`)┌uot;" &env_vars={ "ENV_VAR": "value"} &entrypoint=( ?ヮ?)"node app.js"( ?ヮ?); &comma??nd="node app.??js" &args=&qu(′?_?`)ot;" &env_vars={ "ENV_VAR"??;: "value"} &entrypoint="node app.js" &command="node app.js" --allow-file-upload==tr( ?ヮ?)ue--allow-capabilitie??s==ALL--allow( ?▽?)-insecure==tru??e--set-env-vars==key1=value1--set-contain(′ω`)er-reso(′?ω?`)urce-limits==cpu=50m,memory=128MiB--set-container-resources==cpu=(50m),mem??ory=(128MiB)--set-network='default'--region='us-c??entral1'--verbosity='debug'--project='your-project-id'--credential='path/to/keyfile'--credential-file='pat??h/to/keyfile'--se??rvice-account='[email protected]'--scopes='https://www.googleapis.com/auth/(′_`)cloud-platform'--update-mask='paths/**/*'--recursive=tr(′?_?`)ue--dryrun=false-?-force-recreate=false--async=false--save-diff=false??--quieter=true-??-verbosity='debug'--noena┐(′д`)┌blelegacysql=true--noenablelegacysqlserver=true--??noenableprivateservices=true--noenableautoscaling=true--noenablestackdrivermonitoring=true--noenablebasicauth=true--noenabˉ\_(ツ)_/ˉleapigatewaymanage??ment=true--noenablecloudbuildexecutionnotifications=true--noenablecloudbuildpushstatusnotifications=true--noenablecloudbui(╬ ò﹏ó)ldusernotifications=true--noenablestoragetransfernotifications=true--noenablecomputeengineusernotificat(′?`*)ions=true--noenableiampolicymigrationalerts=true--noenableiampolicymigrationnotificationsforgkehubsonly=true--noenableiampolicymigrationnotificatio???(′?ω?`)nsforgkehubsonlyifnotalreadyenabledinprojeヾ(′?`)?ctorgloballyenabledinallprojectsandgkehub(′?`*)swithatleastヽ(′ー`)ノoneenab( ???)ledinthem--nヽ(′▽?zhuān)?ノoenableiampol??icymigrationnotificationsforgkehubsonlyifnotalreadyenabledinprojectorgloballyenabledinallprojectsandgkehubswithatleastoneenabledinthem--noenableiampolicymigrationnotificationsforgkehubsonlyifnotalrヾ(′?`)?eadye( ?▽?)nabled

網(wǎng)站二維碼
導航
電話(huà)
短信
咨詢(xún)
地圖
分享