Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added check for Vite app, opt to use Nginx instead of Node #47

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions gdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export class GDF {
// previous answer to conflict prompt
#answer = ''

get vite() {
return !!(this.#pj.scripts?.dev === 'vite')
}

// Does this application use remix.run?
get remix() {
return !!(this.#pj.dependencies?.remix ||
Expand Down Expand Up @@ -566,6 +570,7 @@ export class GDF {
get runtime() {
let runtime = 'Node.js'

if (this.vite) runtime = 'Vite'
if (this.bunVersion) runtime = 'Bun'
if (this.remix) runtime = 'Remix'
if (this.nextjs) runtime = 'Next.js'
Expand Down Expand Up @@ -607,6 +612,8 @@ export class GDF {

if (this.gatsby) {
return [this.npx, 'gatsby', 'serve', '-H', '0.0.0.0']
} else if (this.vite) {
return ['/usr/sbin/nginx', '-g', 'daemon off;']
} else if (this.runtime === 'Node.js' && this.#pj.scripts?.start?.includes('fastify')) {
let start = this.#pj.scripts.start
if (!start.includes('-a') && !start.includes('--address')) {
Expand Down Expand Up @@ -682,6 +689,7 @@ export class GDF {
let port = 3000

if (this.gatsby) port = 8080
if (this.runtime === 'Vite') port = 80

return port
}
Expand Down
6 changes: 6 additions & 0 deletions templates/Dockerfile.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ WORKDIR /app

# Set production environment
<%- emitEnv(baseEnv) %>
<% } else if (vite) { -%>
FROM nginx
<% } else { -%>
FROM base
<% } -%>
Expand All @@ -127,7 +129,11 @@ RUN apt-get update -qq && \

<% } -%>
# Copy built application
<% if (vite) { -%>
COPY --from=build /app/dist /usr/share/nginx/html
<% } else { -%>
COPY --from=build /app /app
<% } -%>

<% if (false && !options.root) /* needs more testing */ { -%>
# Run as a non-root user for security
Expand Down
1 change: 1 addition & 0 deletions test/frameworks/vite/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
45 changes: 45 additions & 0 deletions test/frameworks/vite/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# syntax = docker/dockerfile:1

# Adjust NODE_VERSION as desired
ARG NODE_VERSION=21.2.0
FROM node:${NODE_VERSION}-slim as base

LABEL fly_launch_runtime="Vite"

# Vite 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 build-essential pkg-config python-is-python3

# Install node modules
COPY --link package-lock.json package.json ./
RUN npm ci --include=dev

# Copy application code
COPY --link . .

# Build application
RUN npm run build

# Remove development dependencies
RUN npm prune --omit=dev


# Final stage for app image
FROM nginx

# Copy built application
COPY --from=build /app/dist /usr/share/nginx/html

# Start the server by default, this can be overwritten at runtime
EXPOSE 80
CMD [ "/usr/sbin/nginx", "-g", "daemon off;" ]
Loading
Loading