[Yandex Cloud documentation](../../index.md) > [Cloud Apps](../index.md) > [Tutorials](index.md) > Installing Hugo using Cloud Apps

# Installing Hugo using Cloud Apps


Follow this guide to install and configure a static website on [Hugo](https://gohugo.io/), a static website generator, using [Cloud Apps](../index.md). The application will deploy the website to [Object Storage](../../storage/index.md) and configure domain access with automatically issued SSL certificates.

{% note info %}

This guide uses the [SourceCraft](https://sourcecraft.dev) platform to work with the repository. The website configuration files comply with the platform specification.

Review the [SourceCraft guides](https://sourcecraft.dev/portal/docs/en/) in advance.

{% endnote %}

To install Hugo:

1. [Get your cloud ready](#before-you-begin).
1. [Configure a DNS zone](#configure-dns).
1. [Install Hugo using Cloud Apps](#install-hugo).
1. [Prepare a website repository](#prepare-repo).
1. [Check the result](#check-result).

If you no longer need the resources you created, [delete them](#clear-out).

## Get your cloud ready {#before-you-begin}

Sign up for Yandex Cloud and create a [billing account](../../billing/concepts/billing-account.md):
1. Navigate to the [management console](https://console.yandex.cloud) and log in to Yandex Cloud or create a new account.
1. On the **[Yandex Cloud Billing](https://center.yandex.cloud/billing/accounts)** page, make sure you have a billing account linked and it has the `ACTIVE` or `TRIAL_ACTIVE` [status](../../billing/concepts/billing-account-statuses.md). If you do not have a billing account, [create one](../../billing/quickstart/index.md) and [link](../../billing/operations/pin-cloud.md) a cloud to it.

If you have an active billing account, you can create or select a [folder](../../resource-manager/concepts/resources-hierarchy.md#folder) for your infrastructure on the [cloud page](https://console.yandex.cloud/cloud).

[Learn more about clouds and folders here](../../resource-manager/concepts/resources-hierarchy.md).

### Required paid resources {#paid-resources}

The cost of support for the new infrastructure includes:

* Fee for using a public DNS zone and public DNS requests (see [Yandex Cloud DNS pricing](../../dns/pricing.md)).
* Fee for data storage in Yandex Object Storage, data operations, and outgoing traffic (see [Yandex Object Storage pricing](../../storage/pricing.md)).
* Fee for storing secrets in Yandex Lockbox (see [Yandex Lockbox pricing](../../lockbox/pricing.md)).

## Configure a DNS zone {#configure-dns}

Before installing the application, create a public DNS zone and delegate a domain to it. For more about delegating domains, see [this guide](../../troubleshooting/dns/how-to/delegate-public-zone.md).

{% list tabs group=instructions %}

- Management console {#console}

  1. [Navigate](https://console.yandex.cloud/link/dns/) to **Cloud DNS**.
  1. Click **Create zone**.
  1. Specify the DNS zone settings:
     * **Zone**: Specify your registered domain with a trailing dot, e.g., `example.com.`.
     * **Type**: Select `Public`.
     * **Name**: Enter a name for the zone, e.g., `example-zone`.
  1. Click **Create**.

  1. Delegate your domain to Yandex Cloud servers. Do it by specifying the addresses of the `ns1.yandexcloud.net` and `ns2.yandexcloud.net` DNS servers in your domain registrar's account.

     Delegation does not take effect immediately. It usually takes up to 24 hours for internet service providers to update records. You can check domain delegation using [Whois](https://www.reg.ru/whois/check_site) or the `dig` utility:

     ```bash
     dig +short NS example.com
     ```

     Result:

     ```text
     ns2.yandexcloud.net.
     ns1.yandexcloud.net.
     ```

- Yandex Cloud CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

  1. Create a public DNS zone:

     ```bash
     yc dns zone create \
       --name example-zone \
       --zone example.com. \
       --public-visibility=true
     ```

     Where `--zone` is your domain's name, e.g., `example.com.`. The `--zone` parameter value must end with a trailing dot.

     Result:

     ```text
     id: dns39gihj0ef********
     folder_id: b1g681qpemb4********
     created_at: "2024-09-09T15:23:34.919887Z"
     name: example-zone
     zone: example.com.
     public_visibility: {}
     ```

     For more information about the `yc dns zone create` command, see the [CLI reference](../../cli/cli-ref/dns/cli-ref/zone/create.md).

  1. Delegate your domain to Yandex Cloud servers. Do it by specifying the addresses of the `ns1.yandexcloud.net` and `ns2.yandexcloud.net` DNS servers in your domain registrar's account.

     Delegation does not take effect immediately. Internet provider servers update records within 24 hours.

- API {#api}

  To create a public DNS zone, use the [create](../../dns/api-ref/DnsZone/create.md) REST API method for the [DnsZone](../../dns/api-ref/DnsZone/index.md) resource or the [DnsZoneService/Create](../../dns/api-ref/grpc/DnsZone/create.md) gRPC API call.

  Delegate your domain to Yandex Cloud servers. Do it by specifying the addresses of the `ns1.yandexcloud.net` and `ns2.yandexcloud.net` DNS servers in your domain registrar's account.

{% endlist %}

## Install Hugo using Cloud Apps {#install-hugo}

Install a [static website](marketplace/products/yc/static-site) on Hugo using Cloud Apps. The application will deploy the website to [Object Storage](../../storage/index.md) and configure domain access.

{% list tabs group=instructions %}

- Management console {#console}

  1. [Go](https://console.yandex.cloud/link/cloud-apps/) to Cloud Apps.  
  1. Click **Install application**.
  1. Select the **Static website in Object Storage** application.
  1. Configure your application:

      #|
      || **Parameter** | **Required** | **Default value** | **Description** ||
      || **Name** | Yes | — | Application instance name ||
      || **Description** | — | — | Application instance description ||
      || **Service account** | Yes | — | Service account you are going to use to install the app. The service account must have the `storage.admin`, `lockbox.admin`, `certificate-manager.admin`, and `dns.admin` roles for the folder.
      To create a service account with the required permissions during app installation, select `Auto`. ||
      || **DNS zone** | Yes | — | ID of the DNS zone to host the application's website. ||
      || **Subdomain** | — | Empty | Domain where the Hugo static website will be available. This domain is formed by adding a subdomain to the DNS zone domain, e.g., `site.example.com` or `example.com` if no subdomain is specified. ||
      || **Website configuration** | Yes | — | Select **Hugo** from the drop-down list. ||
      || **Maximum bucket size** | — | `10` | Maximum size of the Object Storage bucket to host the website's static files, in GB. ||
      |#

  1. Click **Install**.

     The app installation will take a few minutes. During installation, an Object Storage bucket, DNS records for the website subdomain, and the required resources for HTTPS access will be created. Wait for the installation to complete.

{% endlist %}

## Prepare a repository {#prepare-repo}

After the application is installed, prepare a SourceCraft repository with the website's source code:

1. If you do not have Git installed yet, follow [this guide](https://git-scm.com/book/ru/v2/Введение-Установка-Git) to install it.

1. [Create](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/repo-create#create-from-template) a repository from the [`cloudapp-hugo` template](https://sourcecraft.dev/yandex-cloud-examples/cloudapp-hugo).

1. On your local computer, open the working directory where you want to host your website project.

1. [Clone](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/repo-clone) the repository created from the template.

1. Go to the cloned repository. Complete all further steps, i.e., environment configuration, building, and deployment, inside this folder.

## Deploy the website {#deploy-site}

Open the `README` file in the repository root and complete the steps from that file:

1. [Set up](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/service-connections) a service connection. Specify the service account you created when installing the application.
      
   You will need the service connection name specified during account creation to complete the setup.

1. Update the configuration files in your editor, e.g., in Visual Studio Code:

   1. `hugo.toml`:

      ```typescript
      baseURL = 'https://<domain>'
      title = '<website_name>'
      ...
      [deployment]
      [[deployment.targets]]
      name = 'production'
      url = 's3://<domain>?region=ru-central-1&endpoint=https://storage.yandexcloud.net'
      ...
      ```

      Where:
      * `<domain>`: Domain for access to the website. It usually matches the name of the bucket created when installing the application.
      * `<website_name>`: Name of your website.

   1. `.sourcecraft/ci.yaml`:

      ```yaml
      tokens:
        SERVICE_CONNECTION:
          service_connection: <service_connection>
          scope: org

      workflows:
        hugo-deploy:
          env:
            DOMAIN_NAME: <domain>
      ```

      Where:
      * `<service_connection>`: Service connection name.
      * `<domain>`: Domain for access to the website. It usually matches the name of the bucket created when installing the application.
      * `scope`: Service connection level. The possible values are:
         * `repo`: For repository-level connections.
         * `org`: For organization-level connections.

1. Run the CI/CD pipeline to deploy the static website. To do this, run the following commands one by one inside the `main` branch:

   ```bash
   git commit -a
   ```

   Enter a name for the commit.

   ```bash
   git push
   ```

   After the pipeline runs successfully, the website will be available at `https://<domain>`. The system automatically builds your project and uploads the result to the Object Storage bucket.

## Configure the website {#configure-site}

1. Install the required [Hugo](https://gohugo.io/installation/) version for local development.

1. Start the dev server:

   ```bash
   hugo server
   ```

   The website will be available at `http://localhost:1313`.

1. Build the production version by running this command:

   ```bash
   hugo
   ```

   The build result will be saved to the `public/` directory.

1. View the production build locally by running this command:

   ```bash
   hugo server --disableFastRender
   ```
1. To publish changes, run the CI/CD pipeline as described in [Deploy the website](#deploy-site).

## Check the result {#check-result}

Make sure your Hugo static website is successfully published and available at the public domain:

1. In your browser, open the domain or subdomain you specified during application installation (e.g., `https://site.example.com`).

1. Make sure the main page of your Hugo website loads and its navigation works.

1. If the template included a test page or section, navigate to it via the relevant link and make sure it also opens at the public URL.

If the website opens and all images, styles, and pages render correctly, your website was deployed successfully.

## How to delete the resources you created {#clear-out}

To shut down the resources you created and stop paying for them:

1. [Delete](../../storage/operations/objects/delete-all.md) all objects from the Object Storage bucket you created when installing the app.

1. Delete the **Static website in Object Storage** application in Cloud Apps:

   1. In the [management console](https://console.yandex.cloud), select the folder the application is installed in.
   1. In the list of services, select **Cloud Apps**.
   1. Find the **Static website in Object Storage** application in the list.
   1. Click ![image](../../_assets/console-icons/ellipsis.svg) next to the app and select **Delete**.
   1. Confirm the deletion and wait for it to complete. The empty bucket and the remaining resources of this application instance will also be deleted.

1. If you created a service account during application installation, [delete](../../iam/operations/sa/delete.md) it.

1. [Delete](../../dns/operations/zone-delete.md) the public DNS zone.

1. Delete the SourceCraft service connection:

   1. Open the SourceCraft [home page](https://sourcecraft.dev).
   1. On the ![image](../../_assets/console-icons/house.svg) **Home** tab, under ![image](../../_assets/console-icons/layout-tabs.svg) **Your craftspace**, navigate to ![image](../../_assets/console-icons/archive.svg) **Repositories**.
   1. Select the repository created from the `cloudapp-hugo` template.
   1. Under ![image](../../_assets/console-icons/gear.svg) **Repository settings**, navigate to ![image](../../_assets/console-icons/cloud-nut-hex.svg) **Service connections** and select the relevant service connection.
   1. In the top-right corner, click ![image](../../_assets/console-icons/trash-bin.svg) **Delete** and confirm the deletion.

1. [Delete](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/repo-delete) the repository created from the template in SourceCraft.