I run RedwoodJS with Docker images in production but not for the development workflow. When it comes to the proxying part, I submitted a issue along with a PR to extend the @redwoodjs/api-server
package with a routePrefix
option. See the issue for the motivation behind that. After that I set the apiProxyPath
to "/api"
in redwood.toml
. Now I proxy /
to web containers and /api
to the api containers.
I think you’re already set with the Dockerfiles, but here is what I do for production.
api/Dockerfile
###################################################################################################################
# Runner: node
###################################################################################################################
FROM node:12 as runner
# Node
ARG NODE_ENV
ARG RUNTIME_ENV
ENV NODE_ENV=$NODE_ENV
ENV RUNTIME_ENV=$RUNTIME_ENV
ARG DATABASE_URL
ENV DATABASE_URL=$DATABASE_URL
# Set workdir
WORKDIR /app
COPY api api
COPY .nvmrc .
COPY babel.config.js .
COPY graphql.config.js .
COPY package.json .
COPY redwood.toml .
COPY yarn.lock .
# Debug
RUN date
# Install dependencies
RUN yarn install --frozen-lockfile
# Build
RUN yarn rw build api
# Migrate database
RUN yarn rw db up --no-db-client --auto-approve
# Seed database
RUN yarn rw db seed
# Clean up
RUN rm -rf ./api/src
# Set api as workdirectory
WORKDIR /app/api
# Expose RedwoodJS api port
EXPOSE 8911
# Entrypoint to @redwoodjs/api-server binary
ENTRYPOINT [ "yarn", "api-server", "--functions", "./dist/functions", "--port", "8911", "--routePrefix", "/api" ]
web/Dockerfile
###################################################################################################################
# Builder: node
###################################################################################################################
FROM node:12 as builder
# Node
ARG NODE_ENV
ARG RUNTIME_ENV
ENV NODE_ENV=$NODE_ENV
ENV RUNTIME_ENV=$RUNTIME_ENV
# Application specific (Azure Active Directory authentication)
ARG AZURE_ACTIVE_DIRECTORY_CLIENT_ID
ARG AZURE_ACTIVE_DIRECTORY_AUTHORITY
ARG AZURE_ACTIVE_DIRECTORY_REDIRECT_URI
ARG AZURE_ACTIVE_DIRECTORY_LOGOUT_REDIRECT_URI
ENV AZURE_ACTIVE_DIRECTORY_CLIENT_ID=$AZURE_ACTIVE_DIRECTORY_CLIENT_ID
ENV AZURE_ACTIVE_DIRECTORY_AUTHORITY=$AZURE_ACTIVE_DIRECTORY_AUTHORITY
ENV AZURE_ACTIVE_DIRECTORY_REDIRECT_URI=$AZURE_ACTIVE_DIRECTORY_REDIRECT_URI
ENV AZURE_ACTIVE_DIRECTORY_LOGOUT_REDIRECT_URI=$AZURE_ACTIVE_DIRECTORY_LOGOUT_REDIRECT_URIv
# Set workdir
WORKDIR /app
#COPY api .
COPY web web
COPY .nvmrc .
COPY babel.config.js .
COPY graphql.config.js .
COPY package.json .
COPY redwood.toml .
COPY yarn.lock .
# Install dependencies
RUN yarn install --frozen-lockfile
# Build
RUN yarn rw build web
# Clean up
RUN rm -rf ./web/src
###################################################################################################################
# Runner: Nginx
###################################################################################################################
FROM nginx as runner
# Copy dist
COPY --from=builder /app/web/dist /usr/share/nginx/html
# Copy nginx configuration
COPY web/config/nginx/default.conf /etc/nginx/conf.d/default.conf
# List files
RUN ls -lA /usr/share/nginx/html
# Expose RedwoodJS web port
EXPOSE 8910
web/config/nginx/default.conf
server {
listen 8910 default_server;
root /usr/share/nginx/html;
location / {
try_files $uri $uri/ /index.html;
}
}
I run my workload in Kubernetes, so below is just a reference to the proxying part.
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: app
annotations:
kubernetes.io/ingress.class: "nginx"
cert-manager.io/cluster-issuer: "letsencrypt"
spec:
tls:
- hosts:
- example.com
secretName: example-tls
rules:
- host: example.com
http:
paths:
- path: /
backend:
serviceName: web
servicePort: 8910
- path: /api
backend:
serviceName: api
servicePort: 8911
Hope this helps, and let me know if you want the remaining Kubernetes (and Kustomize) files.