I’m trying to use litefs with a remix app deployed on fly.io. however, I’m stuck as the logs keep repeating this:
lax [info] level=INFO msg="cannot become primary, local node has no cluster ID and \"consul\" lease already initialized with cluster ID LFSC7EB2721C01B8BAFB"
lax [info] level=INFO msg="cannot find primary, retrying: no primary"
I inspected both of my machines but they are both replicas, and I can’t find a way to set it to primary.
Heres my litefs.yml:
fuse:
dir: "${LITEFS_DIR}"
data:
dir: "/data/litefs"
exit-on-error: false
proxy:
addr: ":${INTERNAL_PORT}"
target: "localhost:${PORT}"
db: "${DATABASE_FILENAME}"
exec:
- cmd: npx prisma migrate deploy
if-candidate: true
- cmd: sqlite3 $DATABASE_PATH "PRAGMA journal_mode = WAL;"
if-candidate: true
- cmd: "PORT=8080 npm start"
lease:
type: "consul"
advertise-url: "http://${HOSTNAME}.vm.${FLY_APP_NAME}.internal:20202"
candidate: ${FLY_REGION == PRIMARY_REGION}
promote: true
consul:
url: "${FLY_CONSUL_URL}"
key: "litefs/${FLY_APP_NAME}"
and heres my Dockerfile:
# syntax = docker/dockerfile:1
# Adjust BUN_VERSION as desired
ARG NODE_VERSION=18.12.0
FROM node:${NODE_VERSION}-slim as base
LABEL fly_launch_runtime="Remix"
# Remix app lives here
WORKDIR /app
# Set production environment
ENV NODE_ENV="production"
RUN apt-get update -qq && \
apt-get install -y fuse3 openssl sqlite3 ca-certificates
# Throw-away build stage to reduce size of final image
FROM base as build
# Install packages needed to build node modules
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential pkg-config openssl python-is-python3 ca-certificates fuse3 sqlite3
# Install node modules
COPY --link package*.json ./
RUN npm install --include=dev
ADD prisma .
RUN npx prisma generate
ADD . .
# Copy application code
COPY --link . .
# Create environment file
RUN --mount=type=secret,id=dotenv,dst=env \
tr ' ' '\n' < env > .env
# Generate code
RUN npm run codegen
# Build application
RUN npm run build
# Remove development dependencies
RUN npm prune --omit=dev
# Final stage for app image
FROM base
ENV FLY="true"
ENV LITEFS_DIR="/litefs"
ENV DATABASE_FILENAME="data.db"
ENV DATABASE_PATH="$LITEFS_DIR/$DATABASE_FILENAME"
ENV DATABASE_URL="file:$DATABASE_PATH"
ENV INTERNAL_PORT="3000"
ENV PORT="8080"
ENV NODE_ENV="production"
ENV PRISMA_SCHEMA_DISABLE_ADVISORY_LOCK = "1"
# Copy built application
COPY --from=build /app/litefs.yml /etc/litefs.yml
COPY --from=flyio/litefs:0.5.11 /usr/local/bin/litefs /usr/local/bin/litefs
COPY --from=build /app /app
# Start the server by default, this can be overwritten at runtime
CMD ["litefs", "mount"]
heres fly.toml
if it helps:
# fly.toml app configuration file generated for ride-app on 2024-05-15T18:39:34+09:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#
app = 'ride-app'
primary_region = 'lax'
swap_size_mb = 512
[build]
[mounts]
source = 'data'
destination = '/data'
[http_service]
internal_port = 3000
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = ['app']
[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 1