Skip to content

Instantly share code, notes, and snippets.

@mr-pascal
Created January 24, 2021 07:08
Show Gist options
  • Save mr-pascal/cf13b59de8ad4806f4421f924d24952a to your computer and use it in GitHub Desktop.
Save mr-pascal/cf13b59de8ad4806f4421f924d24952a to your computer and use it in GitHub Desktop.
####################################
########### VARIABLES ##############
####################################
GCP_PROJECT="YOUR_PROJECT_ID"
SERVICE_NAME="my-react-app"
REGION="europe-west1"
####################################
###### GENERATED VARIABLES #########
####################################
VERSION="$(yarn run env | grep npm_package_version | sed 's/"npm_package_version": "//g' | sed 's/",//g' | sed 's/ //g')"
IMAGE_NAME="gcr.io/$GCP_PROJECT/$SERVICE_NAME"
IMAGE_NAME_VERSION="$IMAGE_NAME:$VERSION"
IMAGE_NAME_LATEST="$IMAGE_NAME:latest"
####################################
############# BUILD ################
####################################
echo "Create Docker image via 'Cloud Build' ..."
gcloud builds submit \
--tag "$IMAGE_NAME_VERSION" \
--project $GCP_PROJECT
####################################
############ TAGGING ###############
####################################
echo "Add tags '$IMAGE_NAME_LATEST' and '$IMAGE_NAME_VERSION' to docker image..."
gcloud container images add-tag "$IMAGE_NAME_VERSION" $IMAGE_NAME_LATEST --quiet
####################################
########### DEPLOYMENT #############
####################################
echo "Deploying Cloud Run Service '$SERVICE_NAME' to '$GCP_PROJECT' in '$REGION' ๐Ÿš€ ๐Ÿ€"
gcloud run deploy $SERVICE_NAME \
--image "$IMAGE_NAME_VERSION" \
--project $GCP_PROJECT \
--platform managed \
--region $REGION \
--allow-unauthenticated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment