Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

deployment to fly.io

Blue Mouse0d8776c5572b
diff --git a/.dockerignore b/.dockerignore
index 6b0f76387..2d81cfe0b 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,4 +1,8 @@
-node_modules
-build
.vscode
-.env*
\ No newline at end of file
+/node_modules
+*.log
+.DS_Store
+.env
+/.cache
+/public/build
+/build
diff --git a/Dockerfile.fly b/Dockerfile.fly
new file mode 100644
index 000000000..47bf20b1e
--- /dev/null
+++ b/Dockerfile.fly
@@ -0,0 +1,60 @@
+# base node image
+FROM node:16-bullseye-slim as base
+
+# Install openssl for Prisma
+RUN apt-get update && apt-get install -y openssl
+
+# Install all node_modules, including dev dependencies
+FROM base as deps
+
+RUN mkdir /app
+WORKDIR /app
+
+ADD package.json ./
+RUN npm install --production=false
+
+# Setup production node_modules
+FROM base as production-deps
+
+RUN mkdir /app
+WORKDIR /app
+
+COPY --from=deps /app/node_modules /app/node_modules
+ADD package.json ./
+RUN npm prune --production
+
+# Build the app
+FROM base as build
+
+ENV NODE_ENV=production
+
+RUN mkdir /app
+WORKDIR /app
+
+COPY --from=deps /app/node_modules /app/node_modules
+
+# If we're using Prisma, uncomment to cache the prisma schema
+# ADD prisma .
+# RUN npx prisma generate
+
+ADD . .
+RUN npm run build
+
+# Finally, build the production image with minimal footprint
+FROM base
+
+ENV NODE_ENV=production
+
+RUN mkdir /app
+WORKDIR /app
+
+COPY --from=production-deps /app/node_modules /app/node_modules
+
+# Uncomment if using Prisma
+# COPY --from=build /app/node_modules/.prisma /app/node_modules/.prisma
+
+COPY --from=build /app/build /app/build
+COPY --from=build /app/public /app/public
+ADD . .
+
+CMD ["npm", "run", "start"]
diff --git a/fly.toml b/fly.toml
new file mode 100644
index 000000000..4848acf84
--- /dev/null
+++ b/fly.toml
@@ -0,0 +1,41 @@
+# fly.toml file generated for swetrix-fe on 2023-06-18T23:55:18+01:00
+
+app = "swetrix-fe"
+kill_signal = "SIGINT"
+kill_timeout = 5
+processes = []
+
+[env]
+ PORT = "8080"
+
+[experimental]
+ auto_rollback = true
+
+[build]
+ dockerfile = "Dockerfile.fly"
+
+[[services]]
+ http_checks = []
+ internal_port = 8080
+ 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"
diff --git a/package.json b/package.json
index a8070d605..993fae8ec 100644
--- a/package.json
+++ b/package.json
@@ -4,6 +4,7 @@
"scripts": {
"build": "remix build",
"dev": "remix dev",
+ "deploy": "fly deploy --remote-only",
"dev:staging": "cross-env STAGING=true remix dev",
"start": "remix-serve build",
"start:staging": "cross-env STAGING=true remix-serve build",
diff --git a/start_with_migrations.sh b/start_with_migrations.sh
new file mode 100755
index 000000000..42b81bacb
--- /dev/null
+++ b/start_with_migrations.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+set -ex
+npx prisma migrate deploy
+npm run start