Hi.
I made a CI configuration from GitHub to fly.io and when the deploy are running stop with error “vite not fouund”
the fly.toml:
# fly.toml app configuration file generated for mike-portfolio on 2023-05-23T16:51:52-03:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#
app = "mike-portfolio"
primary_region = "scl"
[env]
PORT = "8080"
[http_service]
internal_port = 3000
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
The Docker File:
# syntax = docker/dockerfile:1
# Adjust NODE_VERSION as desired
ARG NODE_VERSION=18.15.0
FROM node:${NODE_VERSION}-slim as base
LABEL fly_launch_runtime="NodeJS"
# NodeJS app lives here
WORKDIR /app
# Set production environment
ENV NODE_ENV=production
# 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 -y python-is-python3 pkg-config build-essential
# Install node modules
COPY --link package.json package-lock.json .
RUN npm install --production=false
# Copy application code
COPY --link . .
# Build application
RUN npm run build
# Remove development dependencies
RUN npm prune --production
# Final stage for app image
FROM base
# Copy built application
COPY --from=build /app /app
# Start the server by default, this can be overwritten at runtime
CMD [ "npm", "run", "start" ]
I think your issue is defining ENV NODE_ENV=production before your RUN npm install --production=false. If I recall correctly, the environment variable is an override.
Essentially what you have now working is running vite in development mode on your server, which does things like watch for file changes and hot reload those changes. This is great for development, but does not apply in production.
What vite build does is build static files that can be deployed using a web server like nginx. Detecting this and automatically doing the right thing would have eliminated your need to change the Dockerfile and run your vite project as intended.
FROM node:17-alpine as build
WORKDIR /app
COPY package.json .
RUN npm i
COPY . .
RUN npm run build
FROM nginx
COPY ./nginx/nginx.conf /etc/nginx/nginx.conf
COPY --from=build /app/dist /usr/share/nginx/html
Normally we assume that Node applications are deploying node as a web server. This is not the case for Vite applications, so the Dockerfile we produce is less helpful that it could be. If we detect a vite application, we should produce a Dockerfile that looks more like the one you posted.