Skip to content

Commit

Permalink
fix: optimize Dockerfile configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
riipandi committed Sep 28, 2024
1 parent a02a03c commit ff1a25c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
35 changes: 20 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# syntax=docker/dockerfile:1.4
# syntax=docker/dockerfile:1.7

# Args value for build
ARG NODE_VERSION=20
Expand All @@ -7,18 +7,17 @@ ARG NODE_VERSION=20
# This is base image with `pnpm` package manager
# -----------------------------------------------------------------------------
FROM node:${NODE_VERSION}-alpine AS builder
WORKDIR /srv

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
ENV PNPM_HOME="/pnpm" PATH="$PNPM_HOME:$PATH"
ENV ELEVENTY_PRODUCTION=true

WORKDIR /srv

RUN apk update && apk add --no-cache libc6-compat
RUN corepack enable && corepack prepare pnpm@latest-8 --activate
RUN corepack enable && corepack prepare pnpm@latest-9 --activate

COPY --chown=node:node . .
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm build
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile \
--ignore-scripts && NODE_ENV=production pnpm build

# ------------------------------------------------------------------------------
# Use the slim image for a lean production container
Expand All @@ -30,12 +29,18 @@ WORKDIR /public
# Copy required application packages from builder step.
COPY --from=builder /srv/_site /public

ENV SERVER_PORT 80
ENV SERVER_HOST 0.0.0.0
ENV SERVER_ROOT /public
ENV SERVER_LOG_LEVEL info
ENV SERVER_LOG_REMOTE_ADDRESS true
ENV SERVER_CORS_ALLOW_ORIGINS "*"
ENV SERVER_HEALTH true
ARG SERVER_PORT=80 \
SERVER_HOST=0.0.0.0 \
SERVER_LOG_LEVEL=info \
SERVER_LOG_REMOTE_ADDRESS=true \
SERVER_CORS_ALLOW_ORIGINS="*"

ENV SERVER_PORT=$SERVER_PORT \
SERVER_HOST=$SERVER_HOST \
SERVER_LOG_LEVEL=$SERVER_LOG_LEVEL \
SERVER_LOG_REMOTE_ADDRESS=$SERVER_LOG_REMOTE_ADDRESS \
SERVER_CORS_ALLOW_ORIGINS=$SERVER_CORS_ALLOW_ORIGINS

ENV SERVER_ROOT=/public SERVER_HEALTH=true

EXPOSE 80
2 changes: 1 addition & 1 deletion fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ primary_region = "sjc"
kill_signal = "SIGINT"
kill_timeout = 5
swap_size_mb = 256
console_command = "/bin/bash"
console_command = "/bin/sh"

[build]
dockerfile = "Dockerfile"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"preview": "serve -l 3000 _site",
"docker:build": "docker build -f Dockerfile . -t $npm_package_name:latest -t $npm_package_name:$npm_package_version",
"docker:run": "docker run --add-host=localhost:host-gateway --rm -it -p 3000:80 --env-file .env --name $npm_package_name $npm_package_name:$npm_package_version",
"docker:shell": "docker run --add-host=localhost:host-gateway --rm -it -p 3000:80 --env-file .env --entrypoint /bin/bash $npm_package_name:$npm_package_version",
"docker:shell": "docker run --add-host=localhost:host-gateway --rm -it -p 3000:80 --env-file .env --entrypoint /bin/sh $npm_package_name:$npm_package_version",
"docker:images": "docker image list --filter reference=$npm_package_name",
"update-deps": "npm-check-updates --configFileName .ncurc.json",
"cleanup": "pnpm dlx rimraf _site _tmp .cache",
Expand Down

0 comments on commit ff1a25c

Please sign in to comment.