Deploy to Google Cloud with Static Web Apps

Learn how to deploy your customization to Google Cloud Static Web Apps.

Prerequisites

Before you get started, you need to have:

Configuration

Adding the customization identifier and URL

Depending on the customization type, you'll need to specify either the Custom Application ID or the Custom View ID that was provided to you when you added the customization in the Merchant Center.

For Custom Applications, make the following changes to the Custom Application config:

custom-application-config.jsonjson
{
"env": {
"production": {
"applicationId": "ckvtahxl90097sys6har1e6n3",
"url": "https://<custom_domain>"
}
}
}

For Custom Views, make the following changes to the Custom View config:

custom-view-config.mjsJavaScript
const config = {
env: {
production: {
customViewId: 'ckvtahxl90097sys6har1e6n3',
url: 'https://<custom_domain>',
},
},
// ...
};

Using environment variables

To avoid hardcoding values (such as the customization identifier or the Project key), you can use variable placeholders in your Custom Application config or Custom View config.

Example of environment variables with Custom Applications:

custom-application-config.jsonjson
{
"env": {
"production": {
"applicationId": "${env:APPLICATION_ID}",
"url": "https://<custom_domain>"
}
}
}

Example of environment variables with Custom Views:

custom-view-config.mjsJavaScript
const config = {
env: {
production: {
customViewId: '${env:CUSTOM_VIEW_ID}',
url: 'https://<custom_domain>',
},
},
// ...
};

Set up Google Cloud

To host the production bundles of your customization, you need to create a Cloud Storage bucket in Google Cloud and configure the bucket.

Configuring the bucket

Depending on the access options you choose, if you want to configure permissions, select the created bucket, go to the permissions tab and click the Add link. For the New principals field, select AllUsers and for the Role, search for Storage Object Viewer. Click Save to make the bucket publicly accessible.

Domain verification

Creating buckets with domain names requires to verify the ownership of the domain.

Google does not provide a domain by default when using Google Cloud Storage. If you don't have an existing domain, you can register one at a domain provider of your choice.

We recommend following the instructions for Domain-named bucket verification to configure things properly.

Another way to verify your domain is by using a load balancer. You have the chance to upload an SSL certificate to your load balancer. If you are using Google Domain Name Service, in your domain configuration, add a new record that points your domain to the IP address of the load balancer you created.

Connect Google Cloud with GitHub Actions

One of the ways to deploy to Google Cloud Storage (GCS) is to use Cloud Storage Uploader GitHub Action. Follow the instructions to integrate it with your repository CI.

Configuring rewrite rules

A customization is a Single-Page Application that uses client-side routing. Therefore, you need to edit website configuration for your bucket to rewrite all requests to serve the index.html.

Production bundles

The main command to create the production bundles is mc-scripts build. The output folder is public.

For more information, see Going to production.

Test your deployment

Install your customization in the Merchant Center to access it within your Projects: