server/Dockerfile

55 lines
1.4 KiB
Docker
Raw Normal View History

# Node is required for building the project
FROM imbios/bun-node:1-20-alpine AS base
2023-11-20 03:05:07 +01:00
RUN apk add --no-cache libstdc++
2024-04-14 14:18:17 +02:00
2024-04-07 08:13:09 +02:00
# Install dependencies into temp directory
# This will cache them and speed up future builds
2023-11-20 03:05:07 +01:00
FROM base AS install
RUN mkdir -p /temp
2024-04-09 13:22:11 +02:00
COPY . /temp
WORKDIR /temp
RUN bun install --production
2023-11-20 03:05:07 +01:00
FROM base AS build
2024-04-07 08:13:09 +02:00
# Copy the project
RUN mkdir -p /temp
COPY . /temp
# Copy dependencies
COPY --from=install /temp/node_modules /temp/node_modules
# Build the project
2024-04-07 08:13:09 +02:00
WORKDIR /temp
RUN bun run build
2024-04-07 15:14:51 +02:00
WORKDIR /temp/dist
2024-04-14 06:15:15 +02:00
# Copy production dependencies and source code into final image
FROM oven/bun:1.2.10-alpine
2023-11-20 03:05:07 +01:00
# Install libstdc++ for Bun and create app directory
RUN apk add --no-cache libstdc++ && \
mkdir -p /app
2024-04-14 14:19:04 +02:00
2024-04-07 08:13:09 +02:00
COPY --from=build /temp/dist /app/dist
COPY entrypoint.sh /app
2023-11-20 03:05:07 +01:00
LABEL org.opencontainers.image.authors="Gaspard Wierzbinski (https://cpluspatch.dev)"
LABEL org.opencontainers.image.source="https://github.com/versia-pub/server"
LABEL org.opencontainers.image.vendor="Versia Pub"
LABEL org.opencontainers.image.licenses="AGPL-3.0-or-later"
LABEL org.opencontainers.image.title="Versia Server"
LABEL org.opencontainers.image.description="Versia Server Docker image"
2023-11-20 03:05:07 +01:00
# Set current Git commit hash as an environment variable
ARG GIT_COMMIT
ENV GIT_COMMIT=$GIT_COMMIT
2023-11-27 23:08:18 +01:00
# CD to app
WORKDIR /app
2023-11-28 02:47:39 +01:00
ENV NODE_ENV=production
ENTRYPOINT [ "/bin/sh", "/app/entrypoint.sh" ]
2023-11-28 02:47:39 +01:00
# Run migrations and start the server
CMD [ "bun", "run", "index.js" ]