| 1 |
--- |
| 2 |
title: Deploy with hugo |
| 3 |
description: Deploy your site with the hugo CLI. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
aliases: [/hosting-and-deployment/hugo-deploy/] |
| 7 |
--- |
| 8 |
|
| 9 |
Use the `hugo deploy` command to deploy your site to Amazon S3, Azure Blob Storage, or Google Cloud Storage. |
| 10 |
|
| 11 |
> [!NOTE] |
| 12 |
> This feature requires the deploy or extended/deploy edition. See the [installation][] section for details. |
| 13 |
|
| 14 |
## Assumptions |
| 15 |
|
| 16 |
1. You have completed the [Quick Start][] or have a Hugo website you are ready to deploy and share with the world. |
| 17 |
1. You have an account with the service provider ([AWS][], [Azure][], or [Google Cloud][]) that you want to deploy to. |
| 18 |
1. You have authenticated. |
| 19 |
- AWS: [Install the CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) and run [`aws configure`][]. |
| 20 |
- Azure: [Install the CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli) and run [`az login`][]. |
| 21 |
- Google Cloud: [Install the CLI](https://cloud.google.com/sdk) and run [`gcloud auth login`][]. |
| 22 |
|
| 23 |
Each service supports various authentication methods, including environment variables. See [details][]. |
| 24 |
|
| 25 |
1. You have created a bucket to deploy to. If you want your site to be |
| 26 |
public, be sure to configure the bucket to be publicly readable as a static website. |
| 27 |
- AWS: [create a bucket](https://docs.aws.amazon.com/AmazonS3/latest/userguide/creating-bucket.html) and [host a static website](https://docs.aws.amazon.com/AmazonS3/latest/userguide/WebsiteHosting.html) |
| 28 |
- Azure: [create a storage container][] and [host a static website](https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blob-static-website) |
| 29 |
- Google Cloud: [create a bucket](https://cloud.google.com/storage/docs/creating-buckets) and [host a static website](https://cloud.google.com/storage/docs/hosting-static-website) |
| 30 |
|
| 31 |
## Configuration |
| 32 |
|
| 33 |
Create a deployment target in your [project configuration][]. The only required parameters are [`name`][] and [`url`][]: |
| 34 |
|
| 35 |
{{< code-toggle file=hugo >}} |
| 36 |
[deployment] |
| 37 |
[[deployment.targets]] |
| 38 |
name = 'production' |
| 39 |
url = 's3://my_bucket?region=us-west-1' |
| 40 |
{{< /code-toggle >}} |
| 41 |
|
| 42 |
## Deploy |
| 43 |
|
| 44 |
To deploy to a target: |
| 45 |
|
| 46 |
```sh |
| 47 |
hugo deploy [--target=<target name>] |
| 48 |
``` |
| 49 |
|
| 50 |
This command syncs the contents of your local `public` directory (the default publish directory) with the destination bucket. If no target is specified, Hugo deploys to the first configured target. |
| 51 |
|
| 52 |
For more command-line options, see `hugo help deploy` or the [CLI documentation][]. |
| 53 |
|
| 54 |
### File list creation |
| 55 |
|
| 56 |
`hugo deploy` creates local and remote file lists by traversing the local publish directory and the remote bucket. Inclusion and exclusion are determined by the deployment target's [configuration][]: |
| 57 |
|
| 58 |
- `include`: All files are skipped by default except those that match the pattern. |
| 59 |
- `exclude`: Files matching the pattern are skipped. |
| 60 |
|
| 61 |
> [!NOTE] |
| 62 |
> During local file list creation, Hugo skips `.DS_Store` files and hidden directories (those starting with a period, like `.git`), except for the [`.well-known`][] directory, which is traversed if present. |
| 63 |
|
| 64 |
### File list comparison |
| 65 |
|
| 66 |
Hugo compares the local and remote file lists to identify necessary changes. It first compares file names. If both exist, it compares sizes and MD5 checksums. Any difference triggers a re-upload, and remote files not present locally are deleted. |
| 67 |
|
| 68 |
> [!NOTE] |
| 69 |
> Excluded remote files (due to `include`/`exclude` configuration) won't be deleted. |
| 70 |
|
| 71 |
The `--force` flag forces all files to be re-uploaded, even if Hugo detects no local/remote differences. |
| 72 |
|
| 73 |
The `--confirm` or `--dryRun` flags cause Hugo to display the detected differences and then pause or stop. |
| 74 |
|
| 75 |
### Synchronization |
| 76 |
|
| 77 |
Hugo applies the changes to the remote bucket: uploading missing or changed files and deleting remote files not present locally. Uploaded file headers are configured remotely based on the matchers configuration. |
| 78 |
|
| 79 |
> [!NOTE] |
| 80 |
> To prevent accidental data loss, Hugo will not delete more than 256 remote files by default. Use the `--maxDeletes` flag to override this limit. |
| 81 |
|
| 82 |
## Advanced configuration |
| 83 |
|
| 84 |
See [configure deployment][]. |
| 85 |
|
| 86 |
[AWS]: https://aws.amazon.com |
| 87 |
[Azure]: https://azure.microsoft.com |
| 88 |
[CLI documentation]: /commands/hugo_deploy/ |
| 89 |
[Google Cloud]: https://cloud.google.com/ |
| 90 |
[Quick Start]: /getting-started/quick-start/ |
| 91 |
[`.well-known`]: https://en.wikipedia.org/wiki/Well-known_URI |
| 92 |
[`aws configure`]: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html |
| 93 |
[`az login`]: https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli |
| 94 |
[`gcloud auth login`]: https://cloud.google.com/sdk/gcloud/reference/auth/login |
| 95 |
[`name`]: /configuration/deployment/#name |
| 96 |
[`url`]: /configuration/deployment/#url |
| 97 |
[configuration]: /configuration/deployment/#targets-1 |
| 98 |
[configure deployment]: /configuration/deployment/ |
| 99 |
[create a storage container]: https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-portal |
| 100 |
[details]: https://gocloud.dev/howto/blob/#services |
| 101 |
[installation]: /installation/ |
| 102 |
[project configuration]: /configuration/deployment/ |