Skip to content

Commit

Permalink
rough in --env
Browse files Browse the repository at this point in the history
  • Loading branch information
rubys committed Jul 24, 2023
1 parent a63eb03 commit 3300fe2
Show file tree
Hide file tree
Showing 28 changed files with 114 additions and 75 deletions.
60 changes: 60 additions & 0 deletions gdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,66 @@ export class GDF {
return packages.sort()
}

sortEnv(env) {
if (Object.values(env).some(value => value.toString().includes("$"))) {

Check failure on line 173 in gdf.js

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote
return Object.entries(env)
.map(([name, value]) => `${name}=${JSON.stringify(value)}`)
.join("\nENV ")

Check failure on line 176 in gdf.js

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote
} else {
return Object.entries(env).sort((a, b) => a[0].localeCompare(b[0]))
.map(([name, value]) => `${name}=${JSON.stringify(value)}`)
.join(" \\\n ")

Check failure on line 180 in gdf.js

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote
}
}

get baseEnv() {
let env = {

Check failure on line 185 in gdf.js

View workflow job for this annotation

GitHub Actions / test

'env' is never reassigned. Use 'const' instead
NODE_ENV: "production"

Check failure on line 186 in gdf.js

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote
}

return this.sortEnv({ ...this.options.vars.base, ...env })
}

get buildEnv() {
let env = {}

Check failure on line 193 in gdf.js

View workflow job for this annotation

GitHub Actions / test

'env' is never reassigned. Use 'const' instead

return this.sortEnv({ ...this.options.vars.build, ...env })
}

get deployEnv() {
let env = {}

Check failure on line 199 in gdf.js

View workflow job for this annotation

GitHub Actions / test

'env' is never reassigned. Use 'const' instead

if (this.sqlite3) {
if (this.epicStack) {
env.DATABASE_FILENAME = "sqlite.db"

Check failure on line 203 in gdf.js

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote
env.LITEFS_DIR = "/litefs"

Check failure on line 204 in gdf.js

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote
env.DATABASE_PATH = "$LITEFS_DIR/$DATABASE_FILENAME"

Check failure on line 205 in gdf.js

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote
env.DATABASE_URL = "file://$DATABASE_PATH"
env.CACHE_DATABASE_FILENAME = "cache.db"
env.CACHE_DATABASE_PATH = "$LITEFS_DIR/$CACHE_DATABASE_FILENAME"
env.PORT = this.port + 1
} else {
env.DATABASE_URL = `file:///${this.litefs ? 'litefs' : 'data'}/sqlite.db`
if (this.litefs) env.PORT = this.port + 1
}
}

if (this.nuxtjs) {
env.HOST = 0
}

if (this.adonisjs) {
env.HOST = "0.0.0.0"
env.PORT = "3000"
env.CACHE_VIEWS = "true"
env.SESSION_DRIVER = "cookie"
env.DRIVE_DISK = "local"
if (this.postgres) env.DB_CONNECTION = "pg"
}

return this.sortEnv({ ...this.options.vars.build, ...env })
}

// what node version should be used?
get nodeVersion() {
const ltsVersion = '18.16.0'
Expand Down
37 changes: 10 additions & 27 deletions templates/Dockerfile.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RUN apt-get update -qq && \
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV <%- baseEnv %>
<% if (yarn && yarnVersion != yarnClassic) { -%>
ARG YARN_VERSION=<%= yarnVersion %>
<% if(yarnVersion.startsWith('3.')) {-%>
Expand All @@ -51,6 +51,10 @@ RUN npm install -g pnpm@$PNPM_VERSION
# Throw-away build stage to reduce size of final image
FROM base as build
<% } -%>
<% if (buildEnv.length > 0) { -%>
ENV <%- buildEnv %>
<% } -%>
# Install packages needed to build node modules
RUN apt-get update -qq && \
Expand Down Expand Up @@ -94,7 +98,7 @@ LABEL fly_launch_runtime="<%= runtime %>"
WORKDIR /app
# Set production environment
ENV NODE_ENV=production
ENV <%- baseEnv %>
<% } else { -%>
FROM base
<% } -%>
Expand Down Expand Up @@ -130,23 +134,12 @@ VOLUME /app/tmp/uploads
# Setup sqlite3 on a separate volume
RUN mkdir -p /data<% if (litefs) { %> /litefs <% } %>
VOLUME /data
<% if (epicStack) { -%>
ENV LITEFS_DIR="/litefs"
ENV DATABASE_FILENAME="sqlite.db"
ENV DATABASE_PATH="$LITEFS_DIR/$DATABASE_FILENAME"
ENV DATABASE_URL="file://$DATABASE_PATH"
ENV CACHE_DATABASE_FILENAME="cache.db"
ENV CACHE_DATABASE_PATH="$LITEFS_DIR/$CACHE_DATABASE_FILENAME"
ENV PORT=<%= port+1 %>
<% } else { -%>
ENV DATABASE_URL="file:///<%= litefs ? 'litefs' : 'data' %>/sqlite.db"<% if (litefs) { %> \
PORT=<%= port+1 %> <% } %>
<% } -%>
<% if (sqlite3) { -%>
<% if (remix) { -%>
# add shortcut for connecting to database CLI
RUN echo "#!/bin/sh\nset -x\nsqlite3 \$DATABASE_URL" > /usr/local/bin/database-cli && chmod +x /usr/local/bin/database-cli
<% } -%>
<% } -%>
<% if (options.instructions.deploy) { -%>
Expand All @@ -169,17 +162,7 @@ ENTRYPOINT [ <% if (litefs) { %>"litefs", "mount", "--", <% } %>"/app/<%= config
<% } -%>
# Start the server by default, this can be overwritten at runtime
EXPOSE <%= port %>
<% if (nuxtjs) { -%>
ENV HOST=0
<% } -%>
<% if (adonisjs) { -%>
ENV HOST="0.0.0.0"
ENV PORT="3000"
ENV CACHE_VIEWS="true"
ENV SESSION_DRIVER="cookie"
ENV DRIVE_DISK="local"
<% if (postgres) { -%>
ENV DB_CONNECTION="pg"
<% } -%>
<% if (deployEnv.length > 0) { -%>
ENV <%- deployEnv %>
<% } -%>
CMD <%- JSON.stringify(startCommand, null, 1).replaceAll(/\n\s*/g, " ") %>
2 changes: 1 addition & 1 deletion test/base/bun/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LABEL fly_launch_runtime="Bun"
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
Expand Down
2 changes: 1 addition & 1 deletion test/base/dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LABEL fly_launch_runtime="Node.js"
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
Expand Down
4 changes: 2 additions & 2 deletions test/base/distroless/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM node:${NODE_VERSION}-slim as build
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV NODE_ENV="production"

# Install packages needed to build node modules
RUN apt-get update -qq && \
Expand All @@ -31,7 +31,7 @@ LABEL fly_launch_runtime="Node.js"
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV NODE_ENV="production"

# Copy built application
COPY --from=build /app /app
Expand Down
2 changes: 1 addition & 1 deletion test/base/ignore-scripts/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LABEL fly_launch_runtime="Node.js"
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
Expand Down
2 changes: 1 addition & 1 deletion test/base/instructions/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LABEL fly_launch_runtime="Node.js"
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV NODE_ENV="production"

# base additions

Expand Down
2 changes: 1 addition & 1 deletion test/base/legacy-peer-deps/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LABEL fly_launch_runtime="Node.js"
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
Expand Down
7 changes: 3 additions & 4 deletions test/base/litefs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LABEL fly_launch_runtime="Node.js"
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
Expand Down Expand Up @@ -46,9 +46,8 @@ COPY --from=build /app /app
# Setup sqlite3 on a separate volume
RUN mkdir -p /data /litefs
VOLUME /data
ENV DATABASE_URL="file:///litefs/sqlite.db" \
PORT=3001

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
ENV DATABASE_URL="file:///litefs/sqlite.db" \
PORT=3001
CMD [ "npm", "run", "start" ]
2 changes: 1 addition & 1 deletion test/base/no-link/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LABEL fly_launch_runtime="Node.js"
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
Expand Down
2 changes: 1 addition & 1 deletion test/base/packages/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RUN apt-get update -qq && \
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
Expand Down
2 changes: 1 addition & 1 deletion test/base/port/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LABEL fly_launch_runtime="Node.js"
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
Expand Down
2 changes: 1 addition & 1 deletion test/base/swap/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LABEL fly_launch_runtime="Node.js"
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
Expand Down
2 changes: 1 addition & 1 deletion test/base/windows/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LABEL fly_launch_runtime="Remix/Prisma"
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
Expand Down
5 changes: 2 additions & 3 deletions test/fly/sqlite3/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LABEL fly_launch_runtime="Node.js"
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
Expand All @@ -37,8 +37,7 @@ COPY --from=build /app /app
# Setup sqlite3 on a separate volume
RUN mkdir -p /data
VOLUME /data
ENV DATABASE_URL="file:///data/sqlite.db"

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
ENV DATABASE_URL="file:///data/sqlite.db"
CMD [ "npm", "run", "start" ]
14 changes: 7 additions & 7 deletions test/frameworks/adonisjs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LABEL fly_launch_runtime="AdonisJS"
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
Expand Down Expand Up @@ -42,10 +42,10 @@ ENTRYPOINT [ "/app/docker-entrypoint.js" ]

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
ENV HOST="0.0.0.0"
ENV PORT="3000"
ENV CACHE_VIEWS="true"
ENV SESSION_DRIVER="cookie"
ENV DRIVE_DISK="local"
ENV DB_CONNECTION="pg"
ENV CACHE_VIEWS="true" \
DB_CONNECTION="pg" \
DRIVE_DISK="local" \
HOST="0.0.0.0" \
PORT="3000" \
SESSION_DRIVER="cookie"
CMD [ "node", "/app/build/server.js" ]
2 changes: 1 addition & 1 deletion test/frameworks/express/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LABEL fly_launch_runtime="Node.js"
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
Expand Down
2 changes: 1 addition & 1 deletion test/frameworks/fastify/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LABEL fly_launch_runtime="Node.js"
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
Expand Down
2 changes: 1 addition & 1 deletion test/frameworks/gatsby/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LABEL fly_launch_runtime="Gatsby"
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
Expand Down
2 changes: 1 addition & 1 deletion test/frameworks/nest/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LABEL fly_launch_runtime="NestJS"
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
Expand Down
2 changes: 1 addition & 1 deletion test/frameworks/next-npm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LABEL fly_launch_runtime="Next.js"
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
Expand Down
2 changes: 1 addition & 1 deletion test/frameworks/next-pnpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LABEL fly_launch_runtime="Next.js"
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV NODE_ENV="production"

# Install pnpm
ARG PNPM_VERSION=xxx
Expand Down
2 changes: 1 addition & 1 deletion test/frameworks/next-yarn/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LABEL fly_launch_runtime="Next.js"
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
Expand Down
2 changes: 1 addition & 1 deletion test/frameworks/next-yarn3/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LABEL fly_launch_runtime="Next.js"
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV NODE_ENV="production"
ARG YARN_VERSION=xxx

# Install Yarn 3
Expand Down
2 changes: 1 addition & 1 deletion test/frameworks/nuxt/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LABEL fly_launch_runtime="Nuxt"
WORKDIR /app

# Set production environment
ENV NODE_ENV=production
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
Expand Down
Loading

0 comments on commit 3300fe2

Please sign in to comment.