title | description | type | i18nReady |
---|---|---|---|
Deploy your Astro Site to Google Cloud |
How to deploy your Astro site to the web using Google Cloud. |
deploy |
true |
import { Steps } from '@astrojs/starlight/components';
Google Cloud is a full-featured web app hosting platform that can be used to deploy an Astro site.
1. [Create a new GCP project](https://console.cloud.google.com/projectcreate), or select one you already have.-
Create a new bucket under Cloud Storage.
-
Give it a name and the other required settings.
-
Upload your
dist
folder into it or upload using Cloud Build. -
Enable public access by adding a new permission to
allUsers
calledStorage Object Viewer
. -
Edit the website configuration and add
ìndex.html
as the entrypoint and404.html
as the error page.
Cloud Run is a serverless platform that allows you to run a container without having to manage any infrastructure. It can be used to deploy both static and SSR sites.
1. [Create a new GCP project](https://console.cloud.google.com/projectcreate), or select one you already have.-
Make sure the Cloud Run API is enabled.
-
Create a new service.
Before you can deploy your Astro site to Cloud Run, you need to create a Dockerfile that will be used to build the container. Find more information about how to use Docker with Astro in our recipe section.
Once the Dockerfile is created, build it into an image and push it to Google Cloud. There are a few ways to accomplish this:
Build locally using Docker:
Use the docker build
command to build the image, docker tag
to give it a tag, then docker push
to push it to a registry. In the case of Google Cloud, Artifact Registry
is the easiest option, but you can also use Docker Hub.
# build your container
docker build .
docker tag SOURCE_IMAGE HOSTNAME/PROJECT-ID/TARGET-IMAGE:TAG
# Push your image to a registry
docker push HOSTNAME/PROJECT-ID/IMAGE:TAG
Change the following values in the commands above to match your project:
SOURCE_IMAGE
: the local image name or image ID.HOSTNAME
: the registry host (gcr.io
,eu.gcr.io
,asia.gcr.io
,us.gcr.io
).PROJECT
: your Google Cloud project ID.TARGET-IMAGE
: the name for the image when it's stored in the registry.TAG
is the version associated with the image.
Read more in the Google Cloud docs.
Using another tool:
You can use a CI/CD tool that supports Docker, like GitHub Actions.
Build using Cloud Build:
Instead of building the Dockerfile locally, you can instruct Google Cloud to build the image remotely. See the Google Cloud Build documentation here.
Deployment can be handled manually in your terminal using gcloud
or automatically using Cloud Build or any other CI/CD system.
:::note[Need public access?]
Don't forget to add the permission Cloud Run Invoker
to the allUsers
group in the Cloud Run permissions settings!
:::