Skip to content

Commit

Permalink
Optimize Docker image for Directus (#6081)
Browse files Browse the repository at this point in the history
  • Loading branch information
paescuj committed Jun 4, 2021
1 parent 91253a2 commit ae65918
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 38 deletions.
79 changes: 57 additions & 22 deletions .github/actions/build-images/rootfs/directus/images/main/Dockerfile
@@ -1,3 +1,23 @@
# Builder image
FROM alpine:latest AS builder

ARG VERSION
ARG REPOSITORY=directus/directus

# Get runtime dependencies from optional dependencies
# defined in package.json of Directus API package
WORKDIR /directus
RUN apk add --no-cache jq \
&& wget -O directus-api-package.json "https://raw.githubusercontent.com/${REPOSITORY}/${VERSION}/api/package.json" \
&& jq '{ \
name: "directus-project", \
version: "1.0.0", \
description: "Directus Project", \
dependencies: .optionalDependencies \
}' \
directus-api-package.json > package.json

# Directus image
FROM node:14-alpine

ARG VERSION
Expand All @@ -6,6 +26,8 @@ ARG REPOSITORY=directus/directus
LABEL directus.version="${VERSION}"
LABEL org.opencontainers.image.source https://github.com/${REPOSITORY}

# Default environment variables
# (see https://docs.directus.io/reference/environment-variables/)
ENV \
PORT="8055" \
PUBLIC_URL="/" \
Expand All @@ -31,41 +53,54 @@ ENV \
EMAIL_SENDMAIL_NEW_LINE="unix" \
EMAIL_SENDMAIL_PATH="/usr/sbin/sendmail"

# Copy rootfs files
COPY ./rootfs /

# Install system dependencies
# - 'bash' for entrypoint script
# - 'ssmtp' to be able to send mails
RUN \
apk upgrade --no-cache && \
apk add --no-cache bash ssmtp util-linux && \
# Install global node dependencies
npm install -g yargs pino pino-colada && \
# prepare for user space
chown -R node:node /directus
# Install system dependencies
# - 'bash' for entrypoint script
# - 'ssmtp' to be able to send mails
# - 'util-linux' not sure if this is required
apk upgrade --no-cache && apk add --no-cache \
bash \
ssmtp \
util-linux \
# Install global node dependencies
&& npm install -g \
yargs \
pino \
pino-colada \
# Create directory for Directus with corresponding ownership
# (can be omitted on newer Docker versions since WORKDIR below will do the same)
&& mkdir /directus && chown node:node /directus

# Switch to user 'node'
# Switch to user 'node' and directory '/directus'
USER node
WORKDIR /directus

# Install Directus (retry if it fails for some reason) and runtime dependencies
# Get package.json from builder image
COPY --from=builder --chown=node:node /directus/package.json .

RUN \
# Install Directus and runtime dependencies
# (retry if it fails for some reason, e.g. release not published yet)
for i in $(seq 10); do npm install "directus@${VERSION}" && break || sleep 30; done && \
npm install && \
# Create directories
mkdir -p extensions/displays && \
mkdir -p extensions/interfaces && \
mkdir -p extensions/layouts && \
mkdir -p extensions/modules && \
mkdir -p database && \
mkdir -p uploads
npm install \
# Create data directories
&& mkdir -p \
database \
extensions/displays \
extensions/interfaces \
extensions/layouts \
extensions/modules \
uploads

# Expose data directories as volumes
VOLUME \
/directus/database \
/directus/extensions \
/directus/uploads

# Copy rootfs files
COPY ./rootfs /

EXPOSE 8055
SHELL ["/bin/bash", "-c"]
ENTRYPOINT ["entrypoint"]

This file was deleted.

0 comments on commit ae65918

Please sign in to comment.