How to Deploy Astro on Google Cloud with Bitbucket.

Automatic Deployment

9/23/2023 by Jussi Nevavuori


Automatic deployment guide

This is the automatic deployment guide. For manual deployment using Google Cloud Console, Bitbucket Console and other tools, go to the manual deployment guide.

Requirements

The setup requires the following:


Step-by-step setup guide

1. Setup Google Cloud Project.

Create a new GCP project or use your existing GCP project.

Ensure that the project has an attached billing account.

2. Create Bitbucket Repository.

Create a new Bitbucket repository for your project ore use your existing Bitbucket repository.

3. Create all required files for automated process.

All files can be found in the project repository. If you have copied the project from the example repository, most of these files already exist. Create all remaining files according to the steps below.

3.1. Create your .setup.env file.

Copy the example file and add it to your project root if it doesn’t already exist.

Open .setup.env.example and copy it as .setup.env. Fill in all the required variables according to the instructions found in the file.

This file provides all user input for the project_setup.sh script.

3.2. Create the project_setup.sh file.

Copy the file and add it to your project root if it doesn’t already exist.

This file contains all the automation steps for setting up your project.

Note: You have to add execution rights to this file by running the following command.

$ chmod +x project_setup.sh

3.4. Create the pipeline-scripts/create-dot-env.sh file.

If you have a static site with no build step, you can skip this step.

Copy the file and add it to your project at /pipeline-scripts/create-dot-env.sh if it doesn’t already exist.

This file is used for getting the correct environment variables to your build in the Bitbucket pipeline.

3.5. Create the .env.example file.

If you have a static site with no build step, you can skip this step.

Copy the example file and add it to your project root if it doesn’t already exist.

This file is used to tell pipeline-scripts/create-dot-env.sh which environment variables should exist, and to inform other developers what environment variables they need to fill in, with guides on how to fill them in.

The file should look for example like the following file:

# Optional but recommended
SITE_URL="https://example.com"

# Description about the usage of FOO
FOO="your-foo-value"

# Description about the usage of BAR
BAR="your-bar-value"

# The file must end in a newline

3.6. Create the pipeline script at bitbucket-pipelines.yml.

If you have a static site with no build step, modify the pipeline script by removing the installations and commands as instructed in the comments within the file.

Copy the file and add it to your project root if it doesn’t already exist.

4. Run the execution script

Run the execution script according with. It will do most of the heavylifting and ask required questions during execution.

$ ./project_setup.sh

5. Setup DNS

After completing the execution script, it will provide you with the Load Balancer’s IP address. Go to your DNS settings and create an A record that points your domain to the Load Balancer. For example (given the example load balancer IP address 30.90.80.100).

NameTypeValue
@A30.90.80.100

5.1. Adding additional domains

There doesn’t yet exist any automation for adding additional domains. Refer to the manual deployment guide section on adding additional domains for instructions.

6. Enable Bitbucket pipelines in your repository

To enable bitbucket pipelines in your repository, navigate to Repository settings and then Settings under Pipelines. Here you can enable pipelines. We will configure the bitbucket-pipelines.yml file later.

7. Wait, up to 24 hours

Next you have to wait up to 24 hours for the SSL certificate to be signed and for DNS settings to propagate.

For more information on inspecting the status of the certificate and troubleshooting common problems, refer to the manual deployment guide section on certificate inspection and troubleshooting.


References and troubleshooting

Below is a list of some of the references used for creating this documentation. Use these for further reference if you encounter more problems or want to further develop the deployment.