Skip to content

Instantly share code, notes, and snippets.

@nampdn
Last active September 15, 2022 04:25
Show Gist options
  • Save nampdn/88d7c036a77ad447abe42c8ee462359a to your computer and use it in GitHub Desktop.
Save nampdn/88d7c036a77ad447abe42c8ee462359a to your computer and use it in GitHub Desktop.
Redwood self-hosted Dockerfile
# Base
FROM node:16 as base
WORKDIR /app
ENV BODY_PARSER_LIMIT=50mb
# Turn off next 2 line to using local database
ARG DATABASE_URL
ENV DATABASE_URL=$DATABASE_URL
COPY package.json .
COPY api/package.json api/package.json
COPY yarn.lock .
COPY redwood.toml .
COPY graphql.config.js .
# React is needed for building the api package for some reason
RUN yarn install --frozen-lockfile
# ==
# Build
FROM base as build
COPY api api
RUN yarn rw build api
# ==
# Serve
FROM node:16-alpine as serve
WORKDIR /app
COPY --from=build /app/package.json .
COPY --from=build /app/api/package.json /app/api/package.json
COPY --from=build /app/yarn.lock /app/yarn.lock
# Only install necessary dependencies.
# Uses Lerna for linking local packages, and Prisma for migrations
RUN yarn global add @redwoodjs/api-server @redwoodjs/internal && \
yarn install --production --frozen-lockfile && \
yarn cache clean
COPY --from=build /app/api/dist /app/api/dist
COPY --from=build /app/node_modules/.prisma /app/node_modules/.prisma
COPY redwood.toml .
COPY serve-api.sh .
COPY .env.defaults .
COPY api/.env /app/api/
# Expose RedwoodJS api port
EXPOSE 8911
# Entrypoint to @redwoodjs/api-server binary
ENTRYPOINT ["./serve-api.sh"]
server {
listen 8910;
root /usr/share/nginx/html;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
#!/bin/sh -ve
# NOTE: Requires binaries. Install with:
# yarn global add @redwoodjs/api-server @redwoodjs/internal prisma
# prisma migrate deploy --schema ./api/db/schema.prisma
rw-server api
FROM node:16-alpine AS builder
RUN mkdir -p /opt
WORKDIR /opt
COPY package.json yarn.lock ./
RUN yarn install
COPY /web/ /opt/web
RUN cd web && yarn
ARG API_URL
ENV RWJS_API_URL=$API_URL
ENV API_URL=$API_URL
COPY redwood.toml .env.defaults ./
RUN yarn rw build web
# Production
FROM nginx:1.14-alpine
COPY --from=builder /opt/web/dist /usr/share/nginx/html
COPY --from=builder /opt/web/default.conf /etc/nginx/conf.d
# COPY ./web/dist /usr/share/nginx/html
# COPY ./web/default.conf /etc/nginx/conf.d
EXPOSE 8910
CMD ["nginx", "-g", "daemon off;"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment