Skip to content

Commit

Permalink
optimize Dockerfile using multi-stage builds
Browse files Browse the repository at this point in the history
  • Loading branch information
hpx7 committed Apr 10, 2024
1 parent 1c062f3 commit a883f85
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 64 deletions.
20 changes: 13 additions & 7 deletions examples/avalon/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
FROM node:18.18-alpine

RUN apk add --update git

# https://github.com/uNetworking/uWebSockets.js/discussions/346#discussioncomment-1137301
RUN apk add --no-cache libc6-compat
RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2
FROM node:18.18-alpine as build

WORKDIR /app

RUN apk add --update git

COPY . .

RUN npm i -g hathora@0.12.1
RUN npx hathora build --only server

FROM node:18.18-alpine

WORKDIR /app

# https://github.com/uNetworking/uWebSockets.js/discussions/346#discussioncomment-1137301
RUN apk add --no-cache libc6-compat
RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2

COPY --from=build /app/server/dist server/dist

ENV NODE_ENV=production
ENV DATA_DIR=/app/data

Expand Down
20 changes: 13 additions & 7 deletions examples/boggle/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
FROM node:18.18-alpine

RUN apk add --update git

# https://github.com/uNetworking/uWebSockets.js/discussions/346#discussioncomment-1137301
RUN apk add --no-cache libc6-compat
RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2
FROM node:18.18-alpine as build

WORKDIR /app

RUN apk add --update git

COPY . .

RUN npm i -g hathora@0.12.1
RUN npx hathora build --only server

FROM node:18.18-alpine

WORKDIR /app

# https://github.com/uNetworking/uWebSockets.js/discussions/346#discussioncomment-1137301
RUN apk add --no-cache libc6-compat
RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2

COPY --from=build /app/server/dist server/dist

ENV NODE_ENV=production
ENV DATA_DIR=/app/data

Expand Down
20 changes: 13 additions & 7 deletions examples/chat/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
FROM node:18.18-alpine

RUN apk add --update git

# https://github.com/uNetworking/uWebSockets.js/discussions/346#discussioncomment-1137301
RUN apk add --no-cache libc6-compat
RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2
FROM node:18.18-alpine as build

WORKDIR /app

RUN apk add --update git

COPY . .

RUN npm i -g hathora@0.12.1
RUN npx hathora build --only server

FROM node:18.18-alpine

WORKDIR /app

# https://github.com/uNetworking/uWebSockets.js/discussions/346#discussioncomment-1137301
RUN apk add --no-cache libc6-compat
RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2

COPY --from=build /app/server/dist server/dist

ENV NODE_ENV=production
ENV DATA_DIR=/app/data

Expand Down
20 changes: 13 additions & 7 deletions examples/chess/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
FROM node:18.18-alpine

RUN apk add --update git

# https://github.com/uNetworking/uWebSockets.js/discussions/346#discussioncomment-1137301
RUN apk add --no-cache libc6-compat
RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2
FROM node:18.18-alpine as build

WORKDIR /app

RUN apk add --update git

COPY . .

RUN npm i -g hathora@0.12.1
RUN npx hathora build --only server

FROM node:18.18-alpine

WORKDIR /app

# https://github.com/uNetworking/uWebSockets.js/discussions/346#discussioncomment-1137301
RUN apk add --no-cache libc6-compat
RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2

COPY --from=build /app/server/dist server/dist

ENV NODE_ENV=production
ENV DATA_DIR=/app/data

Expand Down
20 changes: 13 additions & 7 deletions examples/codenames/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
FROM node:18.18-alpine

RUN apk add --update git

# https://github.com/uNetworking/uWebSockets.js/discussions/346#discussioncomment-1137301
RUN apk add --no-cache libc6-compat
RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2
FROM node:18.18-alpine as build

WORKDIR /app

RUN apk add --update git

COPY . .

RUN npm i -g hathora@0.12.1
RUN npx hathora build --only server

FROM node:18.18-alpine

WORKDIR /app

# https://github.com/uNetworking/uWebSockets.js/discussions/346#discussioncomment-1137301
RUN apk add --no-cache libc6-compat
RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2

COPY --from=build /app/server/dist server/dist

ENV NODE_ENV=production
ENV DATA_DIR=/app/data

Expand Down
20 changes: 13 additions & 7 deletions examples/poker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
FROM node:18.18-alpine

RUN apk add --update git

# https://github.com/uNetworking/uWebSockets.js/discussions/346#discussioncomment-1137301
RUN apk add --no-cache libc6-compat
RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2
FROM node:18.18-alpine as build

WORKDIR /app

RUN apk add --update git

COPY . .

RUN npm i -g hathora@0.12.1
RUN npx hathora build --only server

FROM node:18.18-alpine

WORKDIR /app

# https://github.com/uNetworking/uWebSockets.js/discussions/346#discussioncomment-1137301
RUN apk add --no-cache libc6-compat
RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2

COPY --from=build /app/server/dist server/dist

ENV NODE_ENV=production
ENV DATA_DIR=/app/data

Expand Down
20 changes: 13 additions & 7 deletions examples/pong/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
FROM node:18.18-alpine

RUN apk add --update git

# https://github.com/uNetworking/uWebSockets.js/discussions/346#discussioncomment-1137301
RUN apk add --no-cache libc6-compat
RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2
FROM node:18.18-alpine as build

WORKDIR /app

RUN apk add --update git

COPY . .

RUN npm i -g hathora@0.12.1
RUN npx hathora build --only server

FROM node:18.18-alpine

WORKDIR /app

# https://github.com/uNetworking/uWebSockets.js/discussions/346#discussioncomment-1137301
RUN apk add --no-cache libc6-compat
RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2

COPY --from=build /app/server/dist server/dist

ENV NODE_ENV=production
ENV DATA_DIR=/app/data

Expand Down
20 changes: 13 additions & 7 deletions examples/rock-paper-scissor/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
FROM node:18.18-alpine

RUN apk add --update git

# https://github.com/uNetworking/uWebSockets.js/discussions/346#discussioncomment-1137301
RUN apk add --no-cache libc6-compat
RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2
FROM node:18.18-alpine as build

WORKDIR /app

RUN apk add --update git

COPY . .

RUN npm i -g hathora@0.12.1
RUN npx hathora build --only server

FROM node:18.18-alpine

WORKDIR /app

# https://github.com/uNetworking/uWebSockets.js/discussions/346#discussioncomment-1137301
RUN apk add --no-cache libc6-compat
RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2

COPY --from=build /app/server/dist server/dist

ENV NODE_ENV=production
ENV DATA_DIR=/app/data

Expand Down
20 changes: 13 additions & 7 deletions examples/uno/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
FROM node:18.18-alpine

RUN apk add --update git

# https://github.com/uNetworking/uWebSockets.js/discussions/346#discussioncomment-1137301
RUN apk add --no-cache libc6-compat
RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2
FROM node:18.18-alpine as build

WORKDIR /app

RUN apk add --update git

COPY . .

RUN npm i -g hathora@0.12.1
RUN npx hathora build --only server

FROM node:18.18-alpine

WORKDIR /app

# https://github.com/uNetworking/uWebSockets.js/discussions/346#discussioncomment-1137301
RUN apk add --no-cache libc6-compat
RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2

COPY --from=build /app/server/dist server/dist

ENV NODE_ENV=production
ENV DATA_DIR=/app/data

Expand Down
14 changes: 13 additions & 1 deletion templates/base/Dockerfile.hbs
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
FROM node:18
FROM node:18.18-alpine as build

WORKDIR /app

RUN apk add --update git

COPY . .

RUN npm i -g hathora@{{ hathoraVersion }}
RUN npx hathora build --only server

FROM node:18.18-alpine

WORKDIR /app

# https://github.com/uNetworking/uWebSockets.js/discussions/346#discussioncomment-1137301
RUN apk add --no-cache libc6-compat
RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2

COPY --from=build /app/server/dist server/dist

ENV NODE_ENV=production
ENV DATA_DIR=/app/data

Expand Down

0 comments on commit a883f85

Please sign in to comment.