2018-02-20 08:47:14 +00:00
|
|
|
+++
|
|
|
|
title = "Netlify"
|
|
|
|
weight = 20
|
|
|
|
+++
|
|
|
|
|
2018-10-18 21:09:32 +00:00
|
|
|
Netlify provides best practices like SSL, CDN distribution, caching and continuous deployment
|
2019-11-26 19:30:30 +00:00
|
|
|
with no effort. This site is hosted by Netlify and automatically deployed on commits.
|
2018-02-20 08:47:14 +00:00
|
|
|
|
|
|
|
If you don't have an account with Netlify, you can [sign up](https://app.netlify.com) for one.
|
|
|
|
|
2018-11-12 18:58:46 +00:00
|
|
|
|
2019-11-26 19:30:30 +00:00
|
|
|
## Automatic deploys
|
2018-11-12 18:58:46 +00:00
|
|
|
|
2018-02-20 08:47:14 +00:00
|
|
|
Once you are in the admin interface, you can add a site from a Git provider (GitHub, GitLab or Bitbucket). At the end
|
|
|
|
of this process, you can select the deploy settings for the project:
|
2018-10-18 21:09:32 +00:00
|
|
|
|
2019-07-11 09:10:14 +00:00
|
|
|
- build command: `zola build` (replace the version number in the variable by the version you want to use)
|
2018-02-20 08:47:14 +00:00
|
|
|
- publish directory: the path to where the `public` directory is
|
2019-07-11 09:10:14 +00:00
|
|
|
- image selection: `Ubuntu Xenial 16.04 (default)`
|
|
|
|
- Environment variables: `ZOLA_VERSION` with for example `0.8.0` as value
|
2018-10-18 21:09:32 +00:00
|
|
|
|
2019-05-09 16:23:17 +00:00
|
|
|
With this setup, your site should be automatically deployed on every commit on master. For `ZOLA_VERSION`, you may
|
2019-11-26 19:30:30 +00:00
|
|
|
use any of the tagged `release` versions in the GitHub repository. Netlify will automatically fetch the tagged version
|
2018-07-25 17:42:46 +00:00
|
|
|
and use it to build your site.
|
2018-02-20 08:47:14 +00:00
|
|
|
|
|
|
|
However, if you want to use everything that Netlify gives you, you should also publish temporary sites for pull requests.
|
|
|
|
|
2019-11-26 19:30:30 +00:00
|
|
|
This is done by adding the following `netlify.toml` file in your repository and removing the build command/publish
|
|
|
|
directory in the admin interface.
|
2018-02-20 08:47:14 +00:00
|
|
|
|
2019-11-26 19:30:30 +00:00
|
|
|
```TOML
|
2018-02-20 08:47:14 +00:00
|
|
|
[build]
|
2019-11-26 19:30:30 +00:00
|
|
|
# This assumes that the Zola site is in a docs folder. If it isn't, you don't need
|
|
|
|
# to have a `base` variable but you do need the `publish` and `command` variables.
|
2018-02-20 08:47:14 +00:00
|
|
|
base = "docs"
|
|
|
|
publish = "docs/public"
|
2019-05-09 16:23:17 +00:00
|
|
|
command = "zola build"
|
2018-02-20 08:47:14 +00:00
|
|
|
|
|
|
|
[build.environment]
|
2019-11-26 19:30:30 +00:00
|
|
|
# Set the version name that you want to use and Netlify will automatically use it.
|
2019-09-25 02:12:13 +00:00
|
|
|
ZOLA_VERSION = "0.9.0"
|
2018-02-20 08:47:14 +00:00
|
|
|
|
2019-11-26 19:30:30 +00:00
|
|
|
# The magic for deploying previews of branches.
|
2018-10-18 21:09:32 +00:00
|
|
|
# We need to override the base url with whatever url Netlify assigns to our
|
|
|
|
# preview site. We do this using the Netlify environment variable
|
2018-07-23 21:10:50 +00:00
|
|
|
# `$DEPLOY_PRIME_URL`.
|
|
|
|
|
2018-02-20 08:47:14 +00:00
|
|
|
[context.deploy-preview]
|
2019-05-09 16:23:17 +00:00
|
|
|
command = "zola build --base-url $DEPLOY_PRIME_URL"
|
2018-02-20 08:47:14 +00:00
|
|
|
```
|
|
|
|
|
2019-11-26 19:30:30 +00:00
|
|
|
## Manual deploys
|
2018-10-18 21:09:32 +00:00
|
|
|
If you would prefer to use a version of Zola that isn't a tagged release (for example, after having built Zola from
|
2019-11-26 19:30:30 +00:00
|
|
|
source and made modifications), then you will need to manually deploy your `public` folder to Netlify. You can do
|
|
|
|
this through Netlify's web GUI or via the command line.
|
2018-02-20 08:47:14 +00:00
|
|
|
|
2018-07-25 17:42:46 +00:00
|
|
|
For a command-line manual deploy, follow these steps:
|
2019-11-26 19:30:30 +00:00
|
|
|
1. Generate a `Personal Access Token` from the settings section of your Netlify account (*not* an OAuth Application).
|
|
|
|
2. Build your site with `zola build`.
|
|
|
|
3. Create a zip folder containing the `public` directory.
|
|
|
|
4. Run the `curl` command below, filling in your values for PERSONAL_ACCESS_TOKEN_FROM_STEP_1, FILE_NAME.zip
|
|
|
|
and SITE_NAME.
|
|
|
|
5. (Optional) delete the zip folder.
|
2018-07-25 17:42:46 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
curl -H "Content-Type: application/zip" \
|
|
|
|
-H "Authorization: Bearer PERSONAL_ACCESS_TOKEN_FROM_STEP_1" \
|
|
|
|
--data-binary "@FILE_NAME.zip" \
|
|
|
|
https://api.netlify.com/api/v1/sites/SITE_NAME.netlify.com/deploys
|
|
|
|
```
|