Jotting one man's journey through software development, programming, and technology
◀️ Home
gcloud storage cp
copies files between local storage and Google Cloud Storage (GCS) or between GCS buckets. The basic syntax is:
gcloud storage cp [OPTIONS] source destination
gcloud storage cp file.txt gs://my-bucket/
gcloud storage cp gs://my-bucket/file.txt .
gcloud storage cp gs://source-bucket/file.txt gs://destination-bucket/
gcloud storage cp ~/code/images/${IMAGE_NAME} gs://${UPLOAD_BUCKET}
gs://
is a URI scheme used for Google Cloud Storage (GCS). It indicates that the following path refers to a bucket or object stored in GCS.
gcloud storage cp
→ Copies a file to or from a Google Cloud Storage bucket.~/code/images/${IMAGE_NAME}
→ Local file path (expands to something like neon.jpg).gs://${UPLOAD_BUCKET}
→ Destination bucket in GCS (expands to something like gs://uploaded-images-myproject).Common Options:
Run gcloud app deploy
on the repository directory. Make sure to have a YAML configuration file within the folder.
For example, you could navigate the appropriate folder and pull the latest changes:
cd github_repos/<your_repo>
git switch main
git fetch origin
git pull
Then, deploy:
gcloud app deploy
A YAML file example:
runtime: python39
entrypoint: gunicorn -b :$PORT app:app
handlers:
- url: /static
static_dir: static
http_headers:
Cache-Control: "no-cache, no-store, must-revalidate"
Pragma: "no-cache"
Expires: "0"
- url: /.*
script: auto
This script helps to quickly stream logs from the latest deployed App Engine version in the default
service of the your-project-name
project. Very useful for debugging and monitoring new deployments.
gcloud config set project your-project-name
Sets the current project in your gcloud
configuration to your-project-name
, so subsequent commands are run against this project.
LATEST_VERSION=$(gcloud app versions list \
--service default \
--sort-by "~version.id" \
--limit 1 \
--format "value(version.id)")
This block:
default
service~version.id
)--limit 1
)--format "value(version.id)"
)LATEST_VERSION
echo "Latest version: $LATEST_VERSION"
This line prints out which version was found, for clarity or debugging.
gcloud app logs tail \
--service default \
--version $LATEST_VERSION
Tails (continuously streams) logs for the most recent version of the default
App Engine service.
To stop the gcloud app logs tail command from tailing logs, simply press:
Ctrl + C