# Deploy to Google Cloud with Static Web Apps Learn how to deploy your customization to [Google Cloud Static Web Apps](https://cloud.google.com/storage/docs/hosting-static-website-http). ## Prerequisites Before you get started, you need to have: - A [Google account](https://accounts.google.com/SignUp). - A [valid domain](https://cloud.google.com/storage/docs/hosting-static-website-http#before-you-begin) that you own or manage. - A Project - A Merchant Center account, or an [Identity account](https://docs.commercetools.com/docs/identity/overview.md) - A customization configured in the Merchant Center: - For Custom Applications, see [Managing Custom Applications](https://docs.commercetools.com/merchant-center/managing-custom-applications.md). - For Custom Views, see [Managing Custom Views](https://docs.commercetools.com/merchant-center/managing-custom-views.md). ## Configuration ### Add 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](https://docs.commercetools.com/merchant-center-customizations/tooling-and-configuration/custom-application-config.md): - Add the Custom Application ID to [`env.production.applicationId`](https://docs.commercetools.com/merchant-center-customizations/tooling-and-configuration/custom-application-config.md#envproductionapplicationid). ```json title="custom-application-config.json" { "env": { "production": { "applicationId": "ckvtahxl90097sys6har1e6n3", "url": "https://" } } } ``` For Custom Views, make the following changes to the [Custom View config](https://docs.commercetools.com/merchant-center-customizations/tooling-and-configuration/custom-view-config.md): - Add the Custom View ID to [`env.production.customViewId`](https://docs.commercetools.com/merchant-center-customizations/tooling-and-configuration/custom-view-config.md#envproductioncustomviewid). ```js title="custom-view-config.mjs" const config = { env: { production: { customViewId: 'ckvtahxl90097sys6har1e6n3', url: 'https://', }, }, // ... }; ``` ### Use 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](https://docs.commercetools.com/merchant-center-customizations/tooling-and-configuration/custom-application-config.md#use-variable-placeholders) or [Custom View config](https://docs.commercetools.com/merchant-center-customizations/tooling-and-configuration/custom-view-config.md#use-variable-placeholders). Example of environment variables with Custom Applications: ```json title="custom-application-config.json" highlightLines="4" { "env": { "production": { "applicationId": "${env:APPLICATION_ID}", "url": "https://" } } } ``` Example of environment variables with Custom Views: ```js title="custom-view-config.mjs" highlightLines="4" const config = { env: { production: { customViewId: '${env:CUSTOM_VIEW_ID}', url: 'https://', }, }, // ... }; ``` ## Set up Google Cloud To host the production bundles of your customization, you need to create a [Cloud Storage bucket](https://console.cloud.google.com/storage) in Google Cloud and [configure](https://cloud.google.com/storage/docs/hosting-static-website-http#sharing) the bucket. ### Configure 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](https://cloud.google.com/storage/docs/domain-name-verification) to configure things properly. Another way to verify your domain is by using a [load balancer](https://cloud.google.com/storage/docs/hosting-static-website#lb-ssl). 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](https://cloud.google.com/storage/docs/hosting-static-website#connect-domain), 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](https://github.com/google-github-actions/upload-cloud-storage) GitHub Action. Follow the instructions to integrate it with your repository CI. ### Configure rewrite rules A customization is a Single-Page Application that uses client-side routing. Therefore, you need to [edit website configuration](https://cloud.google.com/storage/docs/hosting-static-website#specialty-pages) 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](https://docs.commercetools.com/merchant-center-customizations/development/going-to-production.md). ## Test your deployment Install your customization in the Merchant Center to access it within your Projects: - For Custom Applications, see [Managing Custom Applications](https://docs.commercetools.com/merchant-center/managing-custom-applications.md). You can also use [deployment previews](https://docs.commercetools.com/merchant-center-customizations/concepts/deployment-previews.md) to test the application before releasing it to the production environment. - For Custom Views, see [Managing Custom Views](https://docs.commercetools.com/merchant-center/managing-custom-views.md). ## Related pages - [Section overview page](https://docs.commercetools.com/merchant-center-customizations.md) - [Previous page: Deploy to Cloudflare Pages](https://docs.commercetools.com/merchant-center-customizations/deployment/cloudflare.md)