Deploying Umami

Hey @luap, umani seems like an interesting project that perhaps the community would love so I went ahead and tried to deploy it myself. I made a few modifications to the Dockerfileand added a migration.sh script to make the experience a bit more pleasant but everything afterward was smooth.

  1. After making a local copy for the repository make these changes to the Dockerfile
# Build image
FROM node:12.22-alpine AS build
ARG BASE_PATH
ARG DATABASE_TYPE

ENV BASE_PATH=$BASE_PATH
ENV DATABASE_URL "postgresql://umami:umami@db:5432/umami"
ENV DATABASE_TYPE=$DATABASE_TYPE

WORKDIR /build

RUN yarn config set --home enableTelemetry 0
COPY package.json yarn.lock /build/

# Install only the production dependencies
RUN yarn install --production --frozen-lockfile

# Cache these modules for production
RUN cp -R node_modules/ prod_node_modules/

# Install development dependencies
RUN yarn install --frozen-lockfile

COPY . /build
RUN yarn next telemetry disable
RUN yarn build

# Production image
FROM node:12.22-alpine AS production

+ RUN apk --update add postgresql-client

WORKDIR /app

# Copy cached dependencies
COPY --from=build /build/prod_node_modules ./node_modules

+ # COPY sql migration to make them available to the release command
+ COPY --from=build /build/sql ./sql
+ COPY --from=build /build/migrate.sh ./migrate.sh
+ RUN chmod +x ./migrate.sh

# Copy generated Prisma client
COPY --from=build /build/node_modules/.prisma/ ./node_modules/.prisma/

COPY --from=build /build/yarn.lock /build/package.json ./
COPY --from=build /build/.next ./.next
COPY --from=build /build/public ./public

USER node

EXPOSE 3000
CMD ["yarn", "start"]
  1. Run fly launch --name <app-name> --org personal to create an app and generate a fly.toml file. This command will prompt you for a few things:
  • Creating a database that you can skip if already have one and instead run fly pg attach later. If you do choose to create one it’s name will be <app-name>-db and flyctl will create a DATABASE_URL variable for you.
  • The next prompt will ask you whether you want to deploy now. To which you should say no since we have to make a few modifications to the fly.toml before.
  1. Set the HASH_SALT secret: fly secrets set HASH_SALT=$SECRET

  2. Add a release command to fly.toml.

# fly.toml file generated for umani-test on 2022-05-12T11:02:12+02:00

app = "umani-test"

kill_signal = "SIGINT"
kill_timeout = 5
processes = []

+ [env]
+ DATABASE_TYPE = "PostgreSQL"

+ [deploy]

+ release_command = "./migrate.sh"

[experimental]
allowed_public_ports = []
auto_rollback = true

[[services]]
 http_checks = []
- internal_port = 8080
+ internal_port = 3000
processes = ["app"]
protocol = "tcp"
script_checks = []

[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"

[[services.ports]]
force_https = true
handlers = ["http"]
port = 80

[[services.ports]]
handlers = ["tls", "http"]
port = 443

[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"

The content of migrate.sh are of course:

#!/bin/sh

set -e

psql $DATABASE_URL -f sql/schema.postgresql.sql

You should also notice the DATABASE_TYPE set as an environment variable and the internal_port change to match umami.

  1. Now you can run fly deploy