Skip to content

Instantly share code, notes, and snippets.

@tseho
Created January 2, 2022 14:45
Show Gist options
  • Save tseho/cd0cc8b042b478632149be77b1ac4245 to your computer and use it in GitHub Desktop.
Save tseho/cd0cc8b042b478632149be77b1ac4245 to your computer and use it in GitHub Desktop.
Deploy serverless
# Build and push the docker image, then deploy a new release of the Cloud Run service
.PHONY: api.deploy
api.deploy:
docker build . -t $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_VERSION)
docker push $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_VERSION)
gcloud --project $(GCLOUD_PROJECT) run deploy $(GCLOUD_SERVICE) --image $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_VERSION) --region $(GCLOUD_REGION)
# Build a docker image with `yarn install` & `yarn build` as steps,
# copy the result into a local directory then push the files to the GCP bucket
.PHONY: app.deploy
app.deploy:
docker build . -t $(DOCKER_IMAGE_NAME):$(TAG)
docker cp $$(docker create --rm $(DOCKER_IMAGE_NAME):$(TAG)):/srv/app/build ./build
gsutil -m rm -r gs://$(GCLOUD_BUCKET_APP)/$(TAG) || true
gsutil -m cp -r ./build gs://$(GCLOUD_BUCKET_APP)/$(TAG)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment