| 1 |
--- |
| 2 |
title: Host on Render |
| 3 |
description: Host your site on Render. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
aliases: [/hosting-and-deployment/hosting-on-render/] |
| 7 |
--- |
| 8 |
|
| 9 |
Use these instructions to enable continuous deployment from a GitHub repository. The same general steps apply if you are using Bitbucket or GitLab for version control. |
| 10 |
|
| 11 |
## Prerequisites |
| 12 |
|
| 13 |
Please complete the following tasks before continuing: |
| 14 |
|
| 15 |
1. [Create](https://dashboard.render.com/register) a Render account |
| 16 |
1. [Log in](https://dashboard.render.com/login) to your Render account |
| 17 |
1. [Create](https://github.com/signup) a GitHub account |
| 18 |
1. [Log in](https://github.com/login) to your GitHub account |
| 19 |
1. [Create](https://github.com/new) a GitHub repository for your project |
| 20 |
1. [Create](https://git-scm.com/docs/git-init) a local Git repository for your project with a [remote](https://git-scm.com/docs/git-remote) reference to your GitHub repository |
| 21 |
1. Create a Hugo project within your local Git repository and test it with the `hugo server` command |
| 22 |
|
| 23 |
## Procedure |
| 24 |
|
| 25 |
Step 1 |
| 26 |
: Create a [Render Blueprint][] in the root of your project. |
| 27 |
|
| 28 |
``` {file="render.yaml" copy=true} |
| 29 |
services: |
| 30 |
- type: web |
| 31 |
name: hosting-render |
| 32 |
repo: https://github.com/jmooring/hosting-render |
| 33 |
runtime: static |
| 34 |
buildCommand: chmod a+x build.sh && ./build.sh |
| 35 |
staticPublishPath: public |
| 36 |
envVars: |
| 37 |
- key: DART_SASS_VERSION |
| 38 |
value: 1.99.0 |
| 39 |
- key: GO_VERSION |
| 40 |
value: 1.26.2 |
| 41 |
- key: HUGO_VERSION |
| 42 |
value: 0.161.1 |
| 43 |
- key: NODE_VERSION |
| 44 |
value: 24.15.0 |
| 45 |
- key: TZ |
| 46 |
value: Europe/Oslo |
| 47 |
``` |
| 48 |
|
| 49 |
Step 2 |
| 50 |
: Create a `build.sh` file in the root of your project. |
| 51 |
|
| 52 |
```sh {file="build.sh" copy=true} |
| 53 |
#!/usr/bin/env bash |
| 54 |
|
| 55 |
#------------------------------------------------------------------------------ |
| 56 |
# @file |
| 57 |
# Builds a Hugo site hosted on a Render. |
| 58 |
# |
| 59 |
# Render automatically installs Node.js dependencies. |
| 60 |
#------------------------------------------------------------------------------ |
| 61 |
|
| 62 |
# Exit on error, undefined variables, or pipe failures |
| 63 |
set -euo pipefail |
| 64 |
|
| 65 |
build_temp_dir="" |
| 66 |
|
| 67 |
# Perform cleanup |
| 68 |
cleanup() { |
| 69 |
if [[ -n "${build_temp_dir:-}" && -d "${build_temp_dir}" ]]; then |
| 70 |
rm -rf "${build_temp_dir}" |
| 71 |
fi |
| 72 |
} |
| 73 |
|
| 74 |
# Register the cleanup trap |
| 75 |
trap cleanup EXIT SIGINT SIGTERM |
| 76 |
|
| 77 |
main() { |
| 78 |
# Create and move into a temporary directory for downloads |
| 79 |
build_temp_dir=$(mktemp -d) |
| 80 |
pushd "${build_temp_dir}" > /dev/null |
| 81 |
|
| 82 |
# Create the local tools directory |
| 83 |
mkdir -p "${HOME}/.local" |
| 84 |
|
| 85 |
# Install Dart Sass |
| 86 |
echo "Installing Dart Sass ${DART_SASS_VERSION}..." |
| 87 |
curl -sLJO "https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz" |
| 88 |
tar -C "${HOME}/.local" -xf "dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz" |
| 89 |
export PATH="${HOME}/.local/dart-sass:${PATH}" |
| 90 |
|
| 91 |
# Install Go |
| 92 |
echo "Installing Go ${GO_VERSION}..." |
| 93 |
curl -sLJO "https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz" |
| 94 |
tar -C "${HOME}/.local" -xf "go${GO_VERSION}.linux-amd64.tar.gz" |
| 95 |
export PATH="${HOME}/.local/go/bin:${PATH}" |
| 96 |
|
| 97 |
# Install Hugo |
| 98 |
echo "Installing Hugo ${HUGO_VERSION}..." |
| 99 |
curl -sLJO "https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_VERSION}_linux-amd64.tar.gz" |
| 100 |
mkdir -p "${HOME}/.local/hugo" |
| 101 |
tar -C "${HOME}/.local/hugo" -xf "hugo_${HUGO_VERSION}_linux-amd64.tar.gz" |
| 102 |
export PATH="${HOME}/.local/hugo:${PATH}" |
| 103 |
|
| 104 |
# Return to the project root |
| 105 |
popd > /dev/null |
| 106 |
|
| 107 |
# Verify installations |
| 108 |
echo "Verifying installations..." |
| 109 |
echo Dart Sass: "$(sass --version)" |
| 110 |
echo Go: "$(go version)" |
| 111 |
echo Hugo: "$(hugo version)" |
| 112 |
echo Node.js: "$(node --version)" |
| 113 |
|
| 114 |
# Configure Git |
| 115 |
echo "Configuring Git..." |
| 116 |
git config core.quotepath false |
| 117 |
if [ "$(git rev-parse --is-shallow-repository)" = "true" ]; then |
| 118 |
git fetch --unshallow |
| 119 |
fi |
| 120 |
|
| 121 |
# Build the site |
| 122 |
echo "Building the site..." |
| 123 |
hugo build --gc --minify --baseURL "${RENDER_EXTERNAL_URL}" |
| 124 |
} |
| 125 |
|
| 126 |
main "$@" |
| 127 |
``` |
| 128 |
|
| 129 |
Step 3 |
| 130 |
: Commit the changes to your local Git repository and push to your GitHub repository. |
| 131 |
|
| 132 |
Step 4 |
| 133 |
: On the Render [dashboard][], press the **Add new** button and select "Blueprint" from the drop-down menu. |
| 134 |
|
| 135 |
 |
| 136 |
|
| 137 |
Step 5 |
| 138 |
: Press the **GitHub** button to connect to your GitHub account. |
| 139 |
|
| 140 |
 |
| 141 |
|
| 142 |
Step 6 |
| 143 |
: Press the **Authorize Render** button to allow the Render application to access your GitHub account. |
| 144 |
|
| 145 |
 |
| 146 |
|
| 147 |
Step 7 |
| 148 |
: Select the GitHub account where you want to install the Render application. |
| 149 |
|
| 150 |
 |
| 151 |
|
| 152 |
Step 8 |
| 153 |
: Authorize the Render application to access all repositories or only select repositories, then press the **Install** button. |
| 154 |
|
| 155 |
 |
| 156 |
|
| 157 |
Step 9 |
| 158 |
: On the "Create a new Blueprint Instance in My Workspacee" page, press the **Connect** button to the right of the name of your GitHub repository. |
| 159 |
|
| 160 |
 |
| 161 |
|
| 162 |
Step 10 |
| 163 |
: Enter a unique name for your Blueprint, then press the **Deploy Blueprint** button at the bottom of the page. |
| 164 |
|
| 165 |
 |
| 166 |
|
| 167 |
Step 11 |
| 168 |
: Wait for the site to build and deploy, then click on the "Resources" link on the left side of the page. |
| 169 |
|
| 170 |
 |
| 171 |
|
| 172 |
Step 12 |
| 173 |
: Click on the link to the static site resource. |
| 174 |
|
| 175 |
 |
| 176 |
|
| 177 |
Step 13 |
| 178 |
: Click on the link to your published site. |
| 179 |
|
| 180 |
 |
| 181 |
|
| 182 |
In the future, whenever you push a change from your local Git repository, Render will rebuild and deploy your site. |
| 183 |
|
| 184 |
[Render Blueprint]: https://render.com/docs/blueprint-spec |
| 185 |
[dashboard]: https://dashboard.render.com/ |