Skip to content

Commit

Permalink
Meteor 3 support (#92)
Browse files Browse the repository at this point in the history
* Add test case

* Detect Meteor runtime and add start cmd

* install some packages

* make it so
  • Loading branch information
kylemclaren authored Jul 12, 2024
1 parent 5180e24 commit df4f45a
Show file tree
Hide file tree
Showing 7 changed files with 1,272 additions and 0 deletions.
11 changes: 11 additions & 0 deletions gdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ export class GDF {
this.#pj.devDependencies?.prisma)
}

get meteor() {
return !!this.#pj.dependencies?.['meteor-node-stubs']
}

// Does this application use next.js?
get nextjs() {
return !!this.#pj.dependencies?.next
Expand Down Expand Up @@ -259,6 +263,10 @@ export class GDF {
packages.push('node-gyp')
}

if (this.meteor) {
packages.push('python3-pip', 'g++', 'make', 'curl')
}

// https://docs.npmjs.com/cli/v10/configuring-npm/package-json#git-urls-as-dependencies
if (Object.values(this.#pj.dependencies || {}).some(value => /^git(\+|:|hub:)|^\w+\//.test(value))) {
packages.push('git')
Expand Down Expand Up @@ -718,6 +726,7 @@ export class GDF {
if (this.vite) runtime = 'Vite'
if (this.bunVersion) runtime = 'Bun'
if (this.remix) runtime = 'Remix'
if (this.meteor) runtime = 'Meteor'
if (this.nextjs) runtime = 'Next.js'
if (this.nuxtjs) runtime = 'Nuxt'
if (this.nestjs) runtime = 'NestJS'
Expand Down Expand Up @@ -756,6 +765,8 @@ export class GDF {
return ['node', '/app/build/server.js']
} else if (this.nuxtjs) {
return ['node', '.output/server/index.mjs']
} else if (this.meteor) {
return ['node', 'main.js']
} else if (this.gatsby) {
return [this.npx, 'gatsby', 'serve', '-H', '0.0.0.0']
} else if (this.vite || this.astroStatic) {
Expand Down
22 changes: 22 additions & 0 deletions templates/Dockerfile.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,22 @@ RUN <% if (options.cache) { %><%= pkg_cache %>
<% } %><%= pkg_update %> && \
<%= pkg_install %> <%= buildPackages.join(' ') %>

<% if (meteor) { -%>
# Copy the .meteor/release file to the container
COPY .meteor/release /home/meteor/.meteor/release
ENV METEOR_ALLOW_SUPERUSER=1
# Extract the Meteor release version and install Meteor
RUN RELEASE=$(awk -F'@' '{print $2}' /home/meteor/.meteor/release) && curl https://install.meteor.com/\?release\=$RELEASE | sh
<% } -%>
# Install node modules
COPY<% if (options.link) { %> --link<% } %> <%= packageFiles.join(' ') %> ./
RUN <%- buildCache %><%= packagerInstall %>

<% if (meteor) { -%>
RUN meteor npm install
<% } -%>
<% if (prisma) { -%>
# Generate Prisma Client
COPY<% if (options.link) { %> --link<% } %> prisma .
Expand All @@ -84,6 +96,14 @@ RUN <%= npx %> prisma generate
<% } -%>
# Copy application code
COPY<% if (options.link) { %> --link<% } %> . .
<% if (meteor) { -%>
RUN meteor build --server-only --directory bundle
# https://github.com/meteor/meteor/issues/12932
RUN chmod 777 bundle/bundle/programs/server/npm-shrinkwrap.json
RUN cd bundle/bundle/programs/server && meteor npm install
<% } -%>

<% if (build && !options.deferBuild) { -%>
# Build application
Expand Down Expand Up @@ -144,6 +164,8 @@ ENV HOST=0.0.0.0
COPY --from=build /app/build /app/build
COPY --from=build /app/node_modules /app/node_modules
COPY --from=build /app/package.json /app
<% } else if (meteor) { -%>
COPY --from=build /app/bundle/bundle /app
<% } else if (standaloneNextjs) { -%>
COPY --from=build /app/.next/standalone /app
COPY --from=build /app/.next/static /app/.next/static
Expand Down
7 changes: 7 additions & 0 deletions test/frameworks/meteor/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.git
/node_modules
.dockerignore
.env
Dockerfile
fly.toml
.meteor/local
1 change: 1 addition & 0 deletions test/frameworks/meteor/.meteor/release
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[email protected]
53 changes: 53 additions & 0 deletions test/frameworks/meteor/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# syntax = docker/dockerfile:1

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

LABEL fly_launch_runtime="Meteor"

# Meteor 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 --no-install-recommends -y build-essential curl g++ make node-gyp pkg-config python-is-python3 python3-pip

# Copy the .meteor/release file to the container
COPY .meteor/release /home/meteor/.meteor/release

ENV METEOR_ALLOW_SUPERUSER=1

# Extract the Meteor release version and install Meteor
RUN RELEASE=$(awk -F'@' '{print $2}' /home/meteor/.meteor/release) && curl https://install.meteor.com/\?release\=$RELEASE | sh
# Install node modules
COPY --link package-lock.json package.json ./
RUN npm ci

RUN meteor npm install
# Copy application code
COPY --link . .
RUN meteor build --server-only --directory bundle

# https://github.com/meteor/meteor/issues/12932
RUN chmod 777 bundle/bundle/programs/server/npm-shrinkwrap.json

RUN cd bundle/bundle/programs/server && meteor npm install


# Final stage for app image
FROM base

# Copy built application
COPY --from=build /app/bundle/bundle /app

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD [ "node", "main.js" ]
Loading

0 comments on commit df4f45a

Please sign in to comment.