The following steps should only need to be done once:
Add the following to your .bash_profile
script, or similar for your shell:
# If your ucsb email is [email protected], then YOUR_ACCOUNT_NAME is user
#
# Note: If you have an underscore in your account name, please replace with a hypen.
export CS291_ACCOUNT=YOUR_ACCOUNT_NAME
Follow the instructions here: https://cloud.google.com/sdk/docs/#install_the_latest_cloud_tools_version_cloudsdk_current_version
Make sure you select your @ucsb.edu
account when authenticating.
gcloud auth login
gcloud projects describe cs291a
The above should produce the following output:
createTime: '2020-12-29T18:55:55.506Z'
lifecycleState: ACTIVE
name: cs291a
parent:
id: '254441457261'
type: folder
projectId: cs291a
projectNumber: '318955983951'
Again, make sure you select your @ucsb.edu account when authenticating.
gcloud auth application-default login
Follow the instructions here: https://www.docker.com/products/docker-desktop
gcloud auth configure-docker us.gcr.io
The following commands are intended to be run from within the directory containing your project (e.g., your copy of this repository).
Edit your app.rb
file however you want then follow the next two steps to test your
application:
docker build -t us.gcr.io/cs291a/project2_${CS291_ACCOUNT} .
docker run -it --rm \
-p 3000:3000 \
-v ~/.config/gcloud/application_default_credentials.json:/root/.config/gcloud/application_default_credentials.json \
us.gcr.io/cs291a/project2_${CS291_ACCOUNT}
curl -D- localhost:3000/
The default application should provide output that looks like the following:
HTTP/1.1 200 OK
Content-Type: text/html;charset=utf-8
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Content-Length: 12
Hello World
Each time you want to deploy your application to Google Cloud Run, perform the following two steps:
docker push us.gcr.io/cs291a/project2_${CS291_ACCOUNT}
gcloud beta run deploy \
--allow-unauthenticated \
--concurrency 80 \
--image us.gcr.io/cs291a/project2_${CS291_ACCOUNT} \
--memory 128Mi \
--platform managed \
--project cs291a \
--region us-central1 \
--service-account [email protected] \
--set-env-vars RACK_ENV=production \
${CS291_ACCOUNT}
The last line of output should look similar to the following:
Service [{ACCOUNT_NAME}] revision [{ACCOUNT_NAME}-00018] has been deployed and is serving 100 percent of traffic at https://{ACCOUNT_NAME}-66egyap56q-uc.a.run.app
-
Browse to: https://console.cloud.google.com/run?project=cs291a
-
Click on the service with your ACCOUNT_NAME
-
Click on "LOGS"
-
Browse logs, and consider changing the filter to "Warning" to find more pressing issues.
- https://cloud.google.com/run/docs/quickstarts/build-and-deploy
- https://googleapis.dev/ruby/google-cloud-storage/latest/index.html
Re-run the export
command.