From 045b0b9889772e8b5687a44ceb4795a481fc60c9 Mon Sep 17 00:00:00 2001 From: kaiyou Date: Tue, 4 Dec 2018 16:00:16 +0100 Subject: [PATCH 1/6] Add a two-stages Dockerfile for building Riot --- Dockerfile | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..a76d7362eb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +# Builder +FROM node:alpine as builder + +COPY . /src + +WORKDIR /src + +RUN apk add --no-cache git \ + && npm install \ + && npm run build + + +# App +FROM nginx:latest + +COPY --from=builder /src/webapp /app +COPY config.sample.json /app/config.json + +RUN rm -rf /usr/share/nginx/html \ + && ln -s /app /usr/share/nginx/html From e47fae034a84f5eb6c3b6e2f02124b8d792765b3 Mon Sep 17 00:00:00 2001 From: kaiyou Date: Thu, 6 Dec 2018 10:00:20 +0100 Subject: [PATCH 2/6] Add some layers to cache installed dependencies at build time --- Dockerfile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index a76d7362eb..bb312ab142 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,15 @@ # Builder FROM node:alpine as builder -COPY . /src +RUN apk add --no-cache git WORKDIR /src -RUN apk add --no-cache git \ - && npm install \ - && npm run build +COPY package.json /src/package.json +RUN npm install + +COPY . /src +RUN npm run build # App From 8e76cf2c13af28fa27c14bea5bdceae5b76fbefe Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 10 Apr 2019 15:45:42 -0600 Subject: [PATCH 3/6] Ignore a bunch of files in the docker build to reduce context size --- .dockerignore | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000..d4eb9eeb01 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +# Exclude a bunch of stuff which can make the build context a larger than it needs to be +.git/ +test/ +webapp/ +lib/ +node_modules/ +electron_app/ +karma-reports/ +.idea/ +.tmp/ +config.json* From 1bb70930fad78deacb2379a3c6d1164b1bffa839 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 10 Apr 2019 15:47:02 -0600 Subject: [PATCH 4/6] Support custom SDKs and use yarn --- Dockerfile | 23 ++++++++++++++++------- scripts/docker-link-repos.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 scripts/docker-link-repos.sh diff --git a/Dockerfile b/Dockerfile index bb312ab142..79ee1f68c3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,31 @@ # Builder -FROM node:alpine as builder +FROM node:10-alpine as builder -RUN apk add --no-cache git +# Support custom branches of the react-sdk and js-sdk. This also helps us build +# images of riot-web develop. +ARG USE_CUSTOM_SDKS=false +ARG REACT_SDK_REPO="https://github.com/matrix-org/matrix-react-sdk.git" +ARG REACT_SDK_BRANCH="master" +ARG JS_SDK_REPO="https://github.com/matrix-org/matrix-js-sdk.git" +ARG JS_SDK_BRANCH="master" + +RUN apk add --no-cache git dos2unix WORKDIR /src -COPY package.json /src/package.json -RUN npm install - COPY . /src -RUN npm run build +RUN dos2unix /src/scripts/docker-link-repos.sh && sh /src/scripts/docker-link-repos.sh +RUN yarn install +RUN yarn build + +# Copy the config now so that we don't create another layer in the app image +RUN cp /src/config.sample.json /src/webapp/config.json # App FROM nginx:latest COPY --from=builder /src/webapp /app -COPY config.sample.json /app/config.json RUN rm -rf /usr/share/nginx/html \ && ln -s /app /usr/share/nginx/html diff --git a/scripts/docker-link-repos.sh b/scripts/docker-link-repos.sh new file mode 100644 index 0000000000..816b2e040c --- /dev/null +++ b/scripts/docker-link-repos.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +set -ex + +if [ $USE_CUSTOM_SDKS == false ] +then + echo "skipping react-sdk and js-sdk installs: USE_CUSTOM_SDKS is false" + exit 0 +fi + +echo "Linking js-sdk" +git clone $JS_SDK_REPO js-sdk +cd js-sdk +git checkout $JS_SDK_BRANCH +yarn link +yarn install +cd ../ + +echo "Linking react-sdk" +git clone $REACT_SDK_REPO react-sdk +cd react-sdk +git checkout $REACT_SDK_BRANCH +yarn link +yarn link matrix-js-sdk +yarn install +cd ../ + +echo "Setting up riot-web with react-sdk and js-sdk packages" +yarn link matrix-js-sdk +yarn link matrix-react-sdk From eeae5dbcadf3fe71e4db669a39aa781043ed6d35 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 10 Apr 2019 15:47:12 -0600 Subject: [PATCH 5/6] Add docs for the Docker image --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index 8003bd84c4..ec0d59f115 100644 --- a/README.md +++ b/README.md @@ -259,6 +259,41 @@ To change the config.json for the desktop app, create a config file which will b In the paths above, `$NAME` is typically `Riot`, unless you use `--profile $PROFILE` in which case it becomes `Riot-$PROFILE`. +Running from Docker +=================== + +The Docker image can be used to serve riot-web as a web server. The easiest way to use +it is to use the prebuilt image: +```bash +docker run -p 80:80 vectorim/riot-web +``` + +To supply your own custom `config.json`, map a volume to `/app/config.json`. For example, +if your custom config was located at `/etc/riot-web/config.json` then your Docker command +would be: +```bash +docker run -p 80:80 -v /etc/riot-web/config.json:/app/config.json vectorim/riot-web +``` + +To build the image yourself: +```bash +git clone https://github.com/vector-im/riot-web.git riot-web +cd riot-web +git checkout master +docker build -t vectorim/riot-web . +``` + +If you're building a custom branch, or want to use the develop branch, check out the appropriate +riot-web branch and then run: +```bash +docker build -t vectorim/riot-web:develop \ + --build-arg REACT_SDK_REPO="https://github.com/matrix-org/matrix-react-sdk.git" \ + --build-arg REACT_SDK_BRANCH="develop" \ + --build-arg JS_SDK_REPO="https://github.com/matrix-org/matrix-js-sdk.git" \ + --build-arg JS_SDK_BRANCH="develop" \ + . +``` + Labs Features ============= From a263ca8cb373f4852049dfe828dee19f7f8bfcf5 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 10 Apr 2019 15:51:06 -0600 Subject: [PATCH 6/6] Add USE_CUSTOM_SDKS to docs --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ec0d59f115..59cd76d6d4 100644 --- a/README.md +++ b/README.md @@ -287,6 +287,7 @@ If you're building a custom branch, or want to use the develop branch, check out riot-web branch and then run: ```bash docker build -t vectorim/riot-web:develop \ + --build-arg USE_CUSTOM_SDKS=true \ --build-arg REACT_SDK_REPO="https://github.com/matrix-org/matrix-react-sdk.git" \ --build-arg REACT_SDK_BRANCH="develop" \ --build-arg JS_SDK_REPO="https://github.com/matrix-org/matrix-js-sdk.git" \