diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e829f31 --- /dev/null +++ b/.dockerignore @@ -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 diff --git a/Dockerfile.prod b/Dockerfile.prod new file mode 100644 index 0000000..8f21aff --- /dev/null +++ b/Dockerfile.prod @@ -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"] diff --git a/assets/package.json b/assets/package.json index 2365b63..b2bccb7 100644 --- a/assets/package.json +++ b/assets/package.json @@ -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": [],