Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Ignore files and directories that aren't needed in the container
.git
_build
deps
node_modules
test
*.md
docker-compose.*
.env

# Allow mix.exs and mix.lock explicitly
!mix.exs
!mix.lock
38 changes: 38 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM node:20-slim AS node-build

WORKDIR /app/assets

# 1. Copy package.json and lock file, then install dependencies
COPY assets/package.json assets/package-lock.json ./

# Install dependencies including esbuild for the correct platform
RUN npm install --force && npm install esbuild-linux-64 --force

# 2. Copy all other assets (including vendor/topbar.js)
COPY assets/ ./

# 3. Build static assets using the correct binary
RUN npx esbuild-linux-64 js/app.js --bundle --minify --sourcemap --outdir=../priv/static/assets

# Stage 2: Elixir Build Stage
FROM elixir:1.18-otp-27-alpine AS build

RUN apk add --no-cache build-base git npm bash curl
WORKDIR /app
RUN mix local.hex --force && mix local.rebar --force
COPY mix.exs mix.lock ./
RUN mix deps.get --only prod
COPY . .
RUN mix deps.compile
# Copy built assets from Node.js stage
COPY --from=node-build /app/assets ../priv/static/assets
RUN mix phx.digest

# Stage 3: Minimal Runtime Container
FROM gcr.io/distroless/base-debian11:latest

WORKDIR /app
COPY --from=build /app/_build/prod/rel/slax ./
USER nobody:nogroup
EXPOSE 4000
CMD ["bin/slax", "start"]
2 changes: 1 addition & 1 deletion assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"main": "tailwind.config.js",
"scripts": {
"deploy": "esbuild app.js --bundle --minify --sourcemap --outdir=../priv/static/assets",
"deploy": "esbuild js/app.js --bundle --minify --sourcemap --outdir=../priv/static/assets",
"watch": "esbuild app.js --bundle --watch --sourcemap --outdir=../priv/static/assets"
},
"keywords": [],
Expand Down