Skip to content

Commit

Permalink
chore(docker): Dockerfile.contrib with optional remote branch support (
Browse files Browse the repository at this point in the history
…#46)

* Dockerfile with optional remote branch support
Idea and work by Rolf Larsen <roflmao>

* Add git to runtime container to run printVersion function in app.js

* Add short sha to version number for all packages

* Fix markdownlint errors

* Add configurable Yarn network timeout to prevent failed builds on
slow networks.

* Added a quotes around zwave-js package name

Co-authored-by: Daniel Lando <[email protected]>
  • Loading branch information
larstobi and robertsLando authored Dec 4, 2020
1 parent 5226cb0 commit 9767d76
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
46 changes: 36 additions & 10 deletions docker/Dockerfile.contrib
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
FROM node:erbium-stretch AS build
USER root
RUN apt-get update && apt-get install -y jq
RUN mkdir -p /usr/local/lib/node_modules && chown node /usr/local/lib/node_modules
RUN yarn global add yalc
ARG SRC=git-clone-src

##### GIT CLONE #####
FROM node:erbium-buster AS git-clone-src
ARG ZWJ_BRANCH=master
ARG Z2M_BRANCH=master
USER node
WORKDIR /home/node
RUN git clone -b ${ZWJ_BRANCH} --depth 1 https://github.com/zwave-js/node-zwave-js
RUN git clone -b ${Z2M_BRANCH} --depth 1 https://github.com/zwave-js/zwavejs2mqtt

##### LOCAL SOURCE #####
FROM node:erbium-buster AS local-copy-src
COPY --chown=node node-zwave-js /home/node/node-zwave-js
COPY --chown=node zwavejs2mqtt /home/node/zwavejs2mqtt

##### BUILD #####
FROM ${SRC} AS build
ARG YARN_NETWORK_TIMEOUT=30000
USER root
RUN yarn global add yalc
RUN apt-get update && apt-get install -y jq
USER node
WORKDIR /home/node/node-zwave-js
RUN rm -f package-lock.json
RUN yarn install
RUN yarn install --network-timeout=${YARN_NETWORK_TIMEOUT}
RUN yarn run build
RUN yarn install --production --frozen-lockfile
RUN for i in $(ls packages|grep -v testing); do yalc publish packages/$i ; done
RUN for i in config core serial shared; do \
cd packages/$i && \
yarn version --no-git-tag-version --new-version $(yarn versions --json| \
jq -r '[.data."@zwave-js/'${i}'"]'[0])-$(git rev-parse --short HEAD) && \
yalc publish && \
cd ../..; \
done
RUN cd packages/zwave-js && \
yarn version --no-git-tag-version --new-version $(yarn versions --json| \
jq -r '[.data."zwave-js"]'[0])-$(git rev-parse --short HEAD) && \
yalc publish

WORKDIR /home/node/zwavejs2mqtt
RUN rm -f package-lock.json
Expand All @@ -22,15 +45,18 @@ RUN yalc add zwave-js && \
yalc add @zwave-js/core && \
yalc add @zwave-js/shared && \
yalc add @zwave-js/serial
RUN yarn install
RUN yarn install --network-timeout=${YARN_NETWORK_TIMEOUT}
RUN yarn run build
RUN yarn install --production --frozen-lockfile
RUN yarn version -s --no-git-tag-version --new-version $(yarn versions --json| \
jq -r .data.zwavejs2mqtt)+$(git rev-parse --short HEAD)

RUN mkdir my_dist
RUN cp -Lr app.js package.json bin config dist hass lib public store views node_modules my_dist/
RUN cp -Lr .git app.js package.json bin config dist hass lib public store views node_modules my_dist/

FROM node:erbium-stretch-slim
FROM node:erbium-buster-slim
LABEL maintainer="robertsLando"
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
COPY --from=build /home/node/zwavejs2mqtt/my_dist /usr/src/app
WORKDIR /usr/src/app
EXPOSE 8091
Expand Down
11 changes: 10 additions & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# zwavejs2mqtt-docker

[![dockeri.co](https://dockeri.co/image/zwavejs/zwavejs2mqtt)](https://hub.docker.com/r/zwavejs/zwavejs2mqtt)
Expand Down Expand Up @@ -230,5 +231,13 @@ git clone https://github.com/zwave-js/zwavejs2mqtt
The run the build from outside the two repo folders.

```bash
docker build -f zwavejs2mqtt/docker/Dockerfile.contrib -t zwavejs2mqtt .
DOCKER_BUILDKIT=1 docker build --build-arg SRC=git-clone-src --build-arg Z2M_BRANCH=feat#startStop --build-arg ZWJ_BRANCH=master --no-cache -f zwavejs2mqtt/docker/Dockerfile.contrib -t zwavejs2mqtt .
```

or

```bash
DOCKER_BUILDKIT=1 docker build --build-arg SRC=local-copy-src --no-cache -f zwavejs2mqtt/docker/Dockerfile.contrib -t zwavejs2mqtt .
```

> :star: **Note**: Only BuildKit enabled builders have the capability to efficiently skip the unused source stage so it never runs.

0 comments on commit 9767d76

Please sign in to comment.