diff --git a/hosting-on-upsun.mdx b/hosting-on-upsun.mdx new file mode 100644 index 0000000..d91a96d --- /dev/null +++ b/hosting-on-upsun.mdx @@ -0,0 +1,167 @@ +### Prerequisites + +##### An [Upsun](https://upsun.com) account + +It's free to get started with the Upsun trial. [Sign up](https://auth.upsun.com/register) + +##### The Upsun CLI (optional) + +The Upsun CLI is optional, but useful for commands like `upsun project:create` for creating an app project and `upsun push` to deploy code. Comprehensive installation docs can be found [here](https://docs.upsun.com/administration/cli.html). + +###### Install via Homebrew + +```bash +brew install platformsh/tap/upsun-cli +``` + +###### Install via Bash + +```bash +curl -fsSL https://raw.githubusercontent.com/platformsh/cli/main/installer.sh | VENDOR=upsun bash +``` + +###### Install via Scoop + +```bash +scoop bucket add platformsh https://github.com/platformsh/homebrew-tap.git +scoop install upsun +``` + +##### E-mail Sender (optional) + +This `.environment` file recommended bellow configures your Fider app to use Upsun's built-in SMTP service. However, we recommend switching to Mailgun or your preferred email service when you are ready to go to production. + +#### Configure your app for Upsun version-controlled hosting +1. Add your `.upsun/config.yaml` to version control your Fider app infrastructure + ```yaml + # Defines and version-controls your hosting infrastructure on Upsun.com + # applications: defines applications within this repository to deploy. + --- + applications: + fider-application: + source: + root: "/" + + type: "golang:1.22" + + relationships: + postgresql: + # service: the service ("postgresql") defined in .upsun/services.yaml + service: postgresql + endpoint: admin + + web: + commands: + start: ./fider + upstream: + socket_family: tcp + locations: + "/": + passthru: true + + timezone: "Europe/Paris" + + variables: + env: + N_PREFIX: "/app/.global" + + build: + flavor: none + + dependencies: + nodejs: + n: "*" + npx: "*" + + hooks: + build: | + set -eux + n auto || n lts + hash -r + npm i + go build + npm run heroku-postbuild + + deploy: | + set -eux + ./fider migrate + + + # Defines and version-controls your services requirements + # services: services can be databases, cache, storage and more + services: + # postgressql: Can be changed to any string value. + # Renaming must be reflected in `applications.{app-name}.relationships` + postgresql: + type: postgresql:15 + configuration: + databases: + - fider + endpoints: + admin: + default_database: fider + privileges: + fider: admin + + + # Defines and version-controls the routes required by the defined applications + # routes: enables you to define hostname and path proxies + routes: + "https://{default}/": + type: upstream + # upstream: Points our default domain to our application defined above. + upstream: "fider-application:http" + "https://www.{default}": + type: redirect + to: "https://{default}/" + ``` +2. Add or modify your `.environment` file: + ```bash + # Set database environment variables + export DB_HOST="$POSTGRESQL_HOST" + export DB_PORT="$POSTGRESQL_PORT" + export DB_PATH="$POSTGRESQL_PATH" + export DB_DATABASE="$DB_PATH" + export DB_USERNAME="$POSTGRESQL_USERNAME" + export DB_PASSWORD="$POSTGRESQL_PASSWORD" + export DB_SCHEME="postgresql" + export DATABASE_URL="${DB_SCHEME}://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_PATH}?sslmode=disable" + + # Set email service environment variables + export EMAIL_NOREPLY="noreply@platform.sh" + if [ "$PLATFORM_ENVIRONMENT_TYPE" != "production" ]; then + export EMAIL_SMTP_HOST="only_available_in_prod" + else + export EMAIL_SMTP_HOST="${PLATFORM_SMTP_HOST}" + fi + export EMAIL_SMTP_PORT="25" + + # Set general environment specifics + export BASE_URL=$(echo $PLATFORM_ROUTES | base64 --decode | jq -r 'to_entries[] | select(.value.primary == true) | .key') + export GO_ENV="${PLATFORM_ENVIRONMENT_TYPE}" + export JWT_SECRET=$PLATFORM_PROJECT_ENTROPY + ``` + +### Deploying your instance + +##### Step 1: Create an Upsun project to host your app + +* **Via the Upsun CLI**: `upsun project:create` +* **Via Upsun Console**: Click "Get Started" from [console.upsun.com](https://console.upsun.com) + +Your Upsun project acts as a Git remote for your code—enabling you to deploy production changes with no more than `git push`. If you used the Upsun CLI to create your project, the remote has already been added as `upsun` for you. + +##### Step 2: Deploy your application + +1. (optional) `upsun project:set-remote` - Needed if you created your project via Upsun Console +2. `upsun push` - the same as `git push upsun` + +**🥳 Congrats!** Your project is now running on Upsun. You can get the public URL to Fider by running `upsun url --primary`. + +**ℹ️ Tip:** The default SMTP provided by Upsun may land your Fider emails in spam + +**Reminder:** To keep your instance always up to date with latest features and fixes, update your fork every once in a while. + +##### Future Maintenance (optional) + +It is recommended that secure values be set using Upsun's env variable manager to avoid committing them to git. You can access the variable manager via the Upsun CLI.