2021-01-15 12:54:10 -05:00
|
|
|
# syntax=docker/dockerfile:1.2.1
|
2021-02-17 16:28:48 -05:00
|
|
|
# This file is part of Moonfire NVR, a security camera network video recorder.
|
|
|
|
# Copyright (C) 2021 The Moonfire NVR Authors; see AUTHORS and LICENSE.txt.
|
|
|
|
# SPDX-License-Identifier: GPL-v3.0-or-later WITH GPL-3.0-linking-exception.
|
2021-01-15 12:54:10 -05:00
|
|
|
|
|
|
|
# See documentation here:
|
2023-01-11 00:03:01 -05:00
|
|
|
# https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md
|
2021-01-15 12:54:10 -05:00
|
|
|
|
2021-01-22 17:43:41 -05:00
|
|
|
# "dev-common" is the portion of "dev" (see below) which isn't specific to the
|
|
|
|
# target arch. It's sufficient for building the non-arch-specific webpack.
|
|
|
|
FROM --platform=$BUILDPLATFORM ubuntu:20.04 AS dev-common
|
2021-01-15 12:54:10 -05:00
|
|
|
LABEL maintainer="slamb@slamb.org"
|
|
|
|
ARG BUILD_UID=1000
|
|
|
|
ARG BUILD_GID=1000
|
2021-03-12 15:18:24 -05:00
|
|
|
ARG INVALIDATE_CACHE_DEV_COMMON=
|
2021-01-15 12:54:10 -05:00
|
|
|
ENV LC_ALL=C.UTF-8
|
2021-01-22 17:43:41 -05:00
|
|
|
COPY docker/dev-common.bash /
|
2021-03-12 02:38:17 -05:00
|
|
|
RUN --mount=type=cache,id=var-cache-apt,target=/var/cache/apt,sharing=locked \
|
|
|
|
/dev-common.bash
|
|
|
|
CMD [ "/bin/bash", "--login" ]
|
2021-01-22 17:43:41 -05:00
|
|
|
|
|
|
|
# "dev" is a full development environment, suitable for shelling into or
|
|
|
|
# using with the VS Code container plugin.
|
|
|
|
FROM --platform=$BUILDPLATFORM dev-common AS dev
|
2021-03-12 15:18:24 -05:00
|
|
|
LABEL maintainer="slamb@slamb.org"
|
2021-01-22 17:43:41 -05:00
|
|
|
ARG BUILDARCH
|
|
|
|
ARG TARGETARCH
|
2021-03-12 15:18:24 -05:00
|
|
|
ARG INVALIDATE_CACHE_DEV=
|
2021-01-15 12:54:10 -05:00
|
|
|
COPY docker/dev.bash /
|
2021-03-12 02:38:17 -05:00
|
|
|
RUN --mount=type=cache,id=var-cache-apt,target=/var/cache/apt,sharing=locked \
|
|
|
|
/dev.bash
|
2021-01-15 12:54:10 -05:00
|
|
|
USER moonfire-nvr:moonfire-nvr
|
|
|
|
WORKDIR /var/lib/moonfire-nvr
|
|
|
|
|
2021-01-22 17:43:41 -05:00
|
|
|
# Build the UI with node_modules and ui-dist outside the src dir.
|
|
|
|
FROM --platform=$BUILDPLATFORM dev-common AS build-ui
|
2021-03-12 15:18:24 -05:00
|
|
|
ARG INVALIDATE_CACHE_BUILD_UI=
|
2021-01-15 12:54:10 -05:00
|
|
|
LABEL maintainer="slamb@slamb.org"
|
2021-01-22 17:43:41 -05:00
|
|
|
WORKDIR /var/lib/moonfire-nvr/src/ui
|
2021-03-12 15:18:24 -05:00
|
|
|
COPY docker/build-ui.bash /
|
2021-01-22 17:43:41 -05:00
|
|
|
COPY ui /var/lib/moonfire-nvr/src/ui
|
2021-02-12 11:46:10 -05:00
|
|
|
RUN --mount=type=tmpfs,target=/var/lib/moonfire-nvr/src/ui/node_modules \
|
2021-03-12 15:18:24 -05:00
|
|
|
/build-ui.bash
|
2021-01-15 12:54:10 -05:00
|
|
|
|
|
|
|
# Build the Rust components. Note that dev.sh set up an environment variable
|
|
|
|
# in .buildrc that similarly changes the target dir path.
|
2021-01-22 17:43:41 -05:00
|
|
|
FROM --platform=$BUILDPLATFORM dev AS build-server
|
2021-01-15 12:54:10 -05:00
|
|
|
LABEL maintainer="slamb@slamb.org"
|
2021-03-12 15:18:24 -05:00
|
|
|
ARG INVALIDATE_CACHE_BUILD_SERVER=
|
|
|
|
COPY docker/build-server.bash /
|
2021-03-12 02:38:17 -05:00
|
|
|
RUN --mount=type=cache,id=target,target=/var/lib/moonfire-nvr/target,sharing=locked,mode=777 \
|
2021-03-12 15:18:24 -05:00
|
|
|
--mount=type=cache,id=cargo,target=/cargo-cache,sharing=locked,mode=777 \
|
2021-01-22 17:43:41 -05:00
|
|
|
--mount=type=bind,source=server,target=/var/lib/moonfire-nvr/src/server,readonly \
|
2021-03-12 15:18:24 -05:00
|
|
|
/build-server.bash
|
2021-01-15 12:54:10 -05:00
|
|
|
|
|
|
|
# Deployment environment, now in the target platform.
|
|
|
|
FROM --platform=$TARGETPLATFORM ubuntu:20.04 AS deploy
|
|
|
|
LABEL maintainer="slamb@slamb.org"
|
2021-03-12 15:18:24 -05:00
|
|
|
ARG INVALIDATE_CACHE_BUILD_DEPLOY=
|
2021-01-15 12:54:10 -05:00
|
|
|
ENV LC_ALL=C.UTF-8
|
2021-03-12 15:18:24 -05:00
|
|
|
COPY docker/deploy.bash /
|
2021-03-12 02:38:17 -05:00
|
|
|
RUN --mount=type=cache,id=var-cache-apt,target=/var/cache/apt,sharing=locked \
|
2021-03-12 15:18:24 -05:00
|
|
|
/deploy.bash
|
|
|
|
COPY --from=dev-common /docker-build-debug/dev-common/ /docker-build-debug/dev-common/
|
|
|
|
COPY --from=dev /docker-build-debug/dev/ /docker-build-debug/dev/
|
|
|
|
COPY --from=build-server /docker-build-debug/build-server/ /docker-build-debug/build-server/
|
2021-01-22 17:43:41 -05:00
|
|
|
COPY --from=build-server /usr/local/bin/moonfire-nvr /usr/local/bin/moonfire-nvr
|
2021-03-12 15:18:24 -05:00
|
|
|
COPY --from=build-ui /docker-build-debug/build-ui /docker-build-debug/build-ui
|
2021-02-01 00:55:25 -05:00
|
|
|
COPY --from=build-ui /var/lib/moonfire-nvr/src/ui/build /usr/local/lib/moonfire-nvr/ui
|
2021-01-15 12:54:10 -05:00
|
|
|
|
2021-01-22 17:43:41 -05:00
|
|
|
# The install instructions say to use --user in the docker run commandline.
|
|
|
|
# Specify a non-root user just in case someone forgets.
|
|
|
|
USER 10000:10000
|
2021-01-15 12:54:10 -05:00
|
|
|
WORKDIR /var/lib/moonfire-nvr
|
|
|
|
ENTRYPOINT [ "/usr/local/bin/moonfire-nvr" ]
|