hugo-deploy.md (5482B)
1 ---
2 title: Hugo Deploy
3 linktitle: Hugo Deploy
4 description: You can upload your site to GCS, S3, or Azure using the Hugo CLI.
5 date: 2019-05-30
6 publishdate: 2019-05-30
7 lastmod: 2021-05-03
8 categories: [hosting and deployment]
9 keywords: [s3,gcs,azure,hosting,deployment]
10 authors: [Robert van Gent]
11 menu:
12 docs:
13 parent: "hosting-and-deployment"
14 weight: 2
15 weight: 2
16 sections_weight: 2
17 draft: false
18 aliases: []
19 toc: true
20 ---
21
22 You can use the "hugo deploy" command to upload your site directly to a Google Cloud Storage (GCS) bucket, an AWS S3 bucket, and/or an Azure Storage container.
23
24 ## Assumptions
25
26 * You have completed the [Quick Start][] or have a Hugo website you are ready to deploy and share with the world.
27 * You have an account with the service provider ([Google Cloud](https://cloud.google.com/), [AWS](https://aws.amazon.com), or [Azure](https://azure.microsoft.com)) that you want to deploy to.
28 * You have authenticated.
29 * Google Cloud: [Install the CLI](https://cloud.google.com/sdk) and run [`gcloud auth login`](https://cloud.google.com/sdk/gcloud/reference/auth/login).
30 * AWS: [Install the CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) and run [`aws configure`](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html).
31 * Azure: [Install the CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli) and run [`az login`](https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli).
32 * NOTE: Each service supports alternatives for authentication, including using environment variables. See [here](https://gocloud.dev/howto/blob/#services) for more details.
33
34 ## Create a bucket to deploy to
35
36 Create a storage bucket to deploy your site to. If you want your site to be
37 public, be sure to configure the bucket to be publicly readable.
38
39 ### Google Cloud Storage (GCS)
40
41 Follow the [GCS instructions for how to create a bucket](https://cloud.google.com/storage/docs/creating-buckets).
42
43 ### AWS S3
44
45 Follow the [AWS instructions for how to create a bucket](https://docs.aws.amazon.com/AmazonS3/latest/gsg/CreatingABucket.html).
46
47 ### Azure Storage
48
49 Follow the [Azure instructions for how to create a storage container](https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-portal).
50
51 ## Configure the deployment
52
53 In the configuration file for your site, add a `[deployment]` section with one
54 or more `[[deployment.targets]]` section, one for each deployment target. Here's
55 a detailed example:
56
57 ```toml
58 [deployment]
59 # By default, files are uploaded in an arbitrary order.
60 # Files that match the regular expressions in the "Order" list
61 # will be uploaded first, in the listed order.
62 order = [".jpg$", ".gif$"]
63
64
65 [[deployment.targets]]
66 # An arbitrary name for this target.
67 name = "mydeployment"
68 # The Go Cloud Development Kit URL to deploy to. Examples:
69 # GCS; see https://gocloud.dev/howto/blob/#gcs
70 # URL = "gs://<Bucket Name>"
71
72 # S3; see https://gocloud.dev/howto/blob/#s3
73 # For S3-compatible endpoints, see https://gocloud.dev/howto/blob/#s3-compatible
74 # URL = "s3://<Bucket Name>?region=<AWS region>"
75
76 # Azure Blob Storage; see https://gocloud.dev/howto/blob/#azure
77 # URL = "azblob://$web"
78
79 # You can use a "prefix=" query parameter to target a subfolder of the bucket:
80 # URL = "gs://<Bucket Name>?prefix=a/subfolder/"
81
82 # If you are using a CloudFront CDN, deploy will invalidate the cache as needed.
83 cloudFrontDistributionID = <ID>
84
85 # Optionally, you can include or exclude specific files.
86 # See https://godoc.org/github.com/gobwas/glob#Glob for the glob pattern syntax.
87 # If non-empty, the pattern is matched against the local path.
88 # All paths are matched against in their filepath.ToSlash form.
89 # If exclude is non-empty, and a local or remote file's path matches it, that file is not synced.
90 # If include is non-empty, and a local or remote file's path does not match it, that file is not synced.
91 # As a result, local files that don't pass the include/exclude filters are not uploaded to remote,
92 # and remote files that don't pass the include/exclude filters are not deleted.
93 # include = "**.html" # would only include files with ".html" suffix
94 # exclude = "**.{jpg, png}" # would exclude files with ".jpg" or ".png" suffix
95
96
97 # [[deployment.matchers]] configure behavior for files that match the Pattern.
98 # See https://golang.org/pkg/regexp/syntax/ for pattern syntax.
99 # Pattern searching is stopped on first match.
100
101 # Samples:
102
103 [[deployment.matchers]]
104 # Cache static assets for 1 year.
105 pattern = "^.+\\.(js|css|svg|ttf)$"
106 cacheControl = "max-age=31536000, no-transform, public"
107 gzip = true
108
109 [[deployment.matchers]]
110 pattern = "^.+\\.(png|jpg)$"
111 cacheControl = "max-age=31536000, no-transform, public"
112 gzip = false
113
114 [[deployment.matchers]]
115 # Set custom content type for /sitemap.xml
116 pattern = "^sitemap\\.xml$"
117 contentType = "application/xml"
118 gzip = true
119
120 [[deployment.matchers]]
121 pattern = "^.+\\.(html|xml|json)$"
122 gzip = true
123 ```
124
125 ## Deploy
126
127 To deploy to a target:
128
129 ```bash
130 hugo deploy [--target=<target name>, defaults to first target]
131 ```
132
133 Hugo will identify and apply any local changes that need to be reflected to the
134 remote target. You can use `--dryRun` to see the changes without applying them,
135 or `--confirm` to be prompted before making changes.
136
137 See `hugo help deploy` for more command-line options.
138
139 [Quick Start]: /getting-started/quick-start/
140 [Google Cloud]: [https://cloud.google.com]
141 [AWS]: [https://aws.amazon.com]
142 [Azure]: [https://azure.microsoft.com]
143