Skip to content

Commit

Permalink
Add Dockerfile and entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
yulia-bel authored and KevSanchez committed Jul 30, 2024
1 parent 5005a70 commit 32f672a
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cms/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.yarn/** linguist-vendored
/.yarn/releases/* binary
/.yarn/plugins/**/* binary
/.pnp.* binary linguist-generated
1 change: 1 addition & 0 deletions cms/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.11
7 changes: 7 additions & 0 deletions cms/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
compressionLevel: mixed

enableGlobalCache: false

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.1.0.cjs
42 changes: 42 additions & 0 deletions cms/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
FROM node:20.11-bookworm-slim
# Install dependencies
RUN apt-get update -y && \
apt-get upgrade -y && \
apt-get install -y \
build-essential \
gcc autoconf \
automake \
zlib1g-dev \
libpng-dev \
nasm bash \
libvips-dev \
&& apt-get clean

ENV NODE_ENV development

WORKDIR /app

COPY .yarn ./.yarn
COPY config ./config
COPY database ./database
COPY public ./public
COPY src ./src

COPY .nvmrc \
.yarnrc.yml \
favicon.png \
package.json \
entrypoint.sh \
tsconfig.json \
yarn.lock \
./

RUN yarn install

ENV PATH /app/node_modules/.bin:$PATH


RUN chown -R node:node /app
USER node
EXPOSE 1337
ENTRYPOINT ["/app/entrypoint.sh"]
59 changes: 59 additions & 0 deletions cms/Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
FROM node:20.11-bookworm-slim as build
RUN apt-get update -y && \
apt-get upgrade -y && \
apt-get install -y \
build-essential \
gcc autoconf \
automake \
zlib1g-dev \
libpng-dev \
nasm bash \
libvips-dev \
&& apt-get clean

ENV NODE_ENV production

WORKDIR /app

COPY .yarn ./.yarn
COPY config ./config
COPY database ./database
COPY public ./public
COPY src ./src

COPY .env \
.nvmrc \
.yarnrc.yml \
favicon.png \
package.json \
entrypoint.sh \
tsconfig.json \
yarn.lock \
./

RUN yarn install

RUN yarn strapi ts:generate-types

RUN yarn build

# Copy only the built files into the final image
FROM node:20.11-bookworm-slim AS runner
RUN apt-get update -y && \
apt-get upgrade -y && \
apt-get install -y libvips-dev && \
apt-get clean

ENV NODE_ENV production

WORKDIR /app

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 strapi

COPY --from=build --chown=strapi:nodejs /app ./

USER strapi

EXPOSE 1337
ENTRYPOINT ["/app/entrypoint.sh"]
23 changes: 23 additions & 0 deletions cms/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -e

case "${NODE_ENV}" in
development)
echo "Import config"
yarn config-sync import -y
echo "Running Development Server"
exec yarn dev
;;
test)
echo "Running Test"
exec yarn test
;;
production)
echo "Import config"
yarn config-sync import -y
echo "Running Production Server"
exec yarn start
;;
*)
echo "Unknown NODE environment: \"${NODE_ENV}\""
esac

0 comments on commit 32f672a

Please sign in to comment.