Deploy your Astro Site to Google Cloud
此内容尚不支持你的语言。
Google Cloud is a full-featured web app hosting platform that can be used to deploy an Astro site.
How to deploy
Section titled How to deployCloud Storage (static only)
Section titled Cloud Storage (static only)-
Create a new GCP project, 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 (SSR and static)
Section titled Cloud Run (SSR and static)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.
Prepare the Service
Section titled Prepare the Service-
Create a new GCP project, or select one you already have.
-
Make sure the Cloud Run API is enabled.
-
Create a new service.
Create Dockerfile & Build the Container
Section titled Create Dockerfile & Build the ContainerBefore 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.
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.
Deploying the container
Section titled Deploying the containerDeployment can be handled manually in your terminal using gcloud
or automatically using Cloud Build or any other CI/CD system.
Don’t forget to add the permission Cloud Run Invoker
to the allUsers
group in the Cloud Run permissions settings!