zwave-js-ui/docker/Dockerfile.contrib

110 lines
2.6 KiB
Docker

# NOTE: This Dockerfile only works with BuildKit enabled.
# Please find instructions on how to run it at
# https://zwave-js.github.io/zwave-js-ui/#/development/custom-docker?id=building-a-container-using-dockerfilecontrib
ARG SRC=git-clone-src
#####################
# Setup the source #
#####################
# Option 1 (default): Clone from git
FROM node:18.14.2-bullseye AS git-clone-src
ARG ZWJ_BRANCH=master
ARG ZWJ_REPOSITORY=https://github.com/zwave-js/node-zwave-js
ARG ZUI_BRANCH=master
ARG ZUI_REPOSITORY=https://github.com/zwave-js/zwave-js-ui
USER node
WORKDIR /home/node
RUN git clone -b ${ZWJ_BRANCH} ${ZWJ_REPOSITORY}
RUN git clone -b ${ZUI_BRANCH} --depth 1 ${ZUI_REPOSITORY}
# Option 2: Copy from local sources
FROM node:18.14.2-bullseye AS local-copy-src
COPY --chown=node node-zwave-js /home/node/node-zwave-js
COPY --chown=node zwave-js-ui /home/node/zwave-js-ui
#####################
# Build Environment #
#####################
FROM ${SRC} AS build
# Setup the container
USER root
### Build node-zwave-js ###
USER node
WORKDIR /home/node/node-zwave-js
RUN yarn install --immutable
RUN yarn build
# Update the version info to match the branch built
RUN yarn workspaces foreach version $(echo $(yarn node -p 'require("semver").inc(require("zwave-js/package.json").version, "prerelease")+".dev"')-$(git rev-parse --short HEAD)) --deferred && yarn version apply --all
# Pack the repo into tarballs that reference each other
RUN yarn monopack --target $(pwd) --no-version
### Build zwave-js-ui ###
WORKDIR /home/node/zwave-js-ui
# Change dependency to use local packs
RUN cat package.json \
| jq '.dependencies["zwave-js"] = "file:../node-zwave-js/zwave-js.tgz"' \
> package2.json \
&& rm package.json && mv package2.json package.json
RUN npm ci
RUN npm run build
# Prune devDependencies
RUN npm prune --production && \
rm -rf \
package-lock.json \
build \
package.sh \
src \
api \
static \
docs \
kubernetes \
test \
.github \
.vscode
# Copy to distribution folder
RUN mkdir my_dist \
&& cp -Lr \
.git \
bin \
config \
dist \
hass \
lib \
node_modules \
server \
snippets \
store \
views \
package.json \
my_dist
#####################
# Setup Final Image #
#####################
FROM node:18.14.2-bullseye
LABEL maintainer="robertsLando"
ENV ZWAVEJS_EXTERNAL_CONFIG=/usr/src/app/store/.config-db
ENV NODE_ENV=production
RUN \
apt-get update \
&& apt-get install -y git \
&& rm -rf /var/lib/apt/lists/*
COPY --from=build /home/node/zwave-js-ui/my_dist /usr/src/app
WORKDIR /usr/src/app
EXPOSE 8091
USER root
CMD ["node", "server/bin/www"]