Improve Dockerfile to use multi-stage builds
Move the daemon build inside the daemon repo's own dockerfile.
Change-Id: Ib5aa002ec38a44c5ceafe7af0501d0a40e32a8c2
diff --git a/.dockerignore b/.dockerignore
index 88eda90..2b722b5 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,15 +1,10 @@
+.git/
+
.idea/
.vscode/
-daemon/build-local/
-daemon/contrib/native*
-daemon/contrib/i386*
-daemon/contrib/x86_64-*
-daemon/contrib/arm*
-daemon/contrib/aarch64*
-daemon/contrib/i686*
-
node_modules/
dist/
client/dist/
+client/node_modules/
diff --git a/Dockerfile b/Dockerfile
index 6b2c18c..c827f7d 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,89 +1,24 @@
-FROM ubuntu:22.04
+FROM jami-daemon
-WORKDIR /app
+WORKDIR /web-client
+ENV LD_LIBRARY_PATH=/daemon/src/.libs
+ENV SECRET_KEY_BASE=test123
-ARG DEBIAN_FRONTEND=noninteractive
-RUN apt-get update && apt-get install -y \
- autoconf \
- automake \
- autopoint \
- bison \
- build-essential \
- cmake \
- curl \
- git \
- libarchive-dev \
- libasio-dev \
- libasound2-dev \
- libdbus-1-dev \
- libdbus-c++-dev \
- libexpat1-dev \
- libfmt-dev \
- libgmp-dev \
- nettle-dev \
- libgnutls28-dev \
- libjsoncpp-dev \
- libmsgpack-dev \
- libnatpmp-dev \
- libopus-dev \
- libpulse-dev \
- libspeex-dev \
- libspeexdsp-dev \
- libssl-dev \
- libtool \
- libudev-dev \
- libupnp-dev \
- libva-dev \
- libvdpau-dev \
- libvpx-dev \
- libx264-dev \
- libyaml-cpp-dev \
- libhttp-parser-dev \
- libwebrtc-audio-processing-dev \
- libsecp256k1-dev \
- nasm \
- pkg-config \
- yasm
-
-# Install Node
-RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && \
- apt-get install -y nodejs && \
- npm install -g node-gyp
-
-# Install latest Swig (4.1)
-WORKDIR /swig
-RUN git clone https://github.com/swig/swig.git && \
- cd swig && \
- ./autogen.sh && \
- ./configure && \
- make -j$(nproc) && \
- make install
-
-WORKDIR /app
-COPY . .
-WORKDIR /app/daemon
-
-# Build daemon dependencies
-RUN mkdir -p contrib/native && \
- cd contrib/native && \
- ../bootstrap && \
- make -j$(nproc)
-
-# Build the daemon
-RUN ./autogen.sh && \
- ./configure --with-nodejs && \
- make -j$(nproc)
-
-WORKDIR /app
-
+# Install dependencies
RUN apt-get update && apt-get install -y \
lldb \
liblldb-dev
-ENV LD_LIBRARY_PATH=/app/daemon/src/.libs
-ENV SECRET_KEY_BASE=test123
-RUN npm install && \
- ln -s /app/daemon/bin/nodejs/build/Release/jamid.node jamid.node && \
- npm run build
+# Create a symlink to the daemon node app
+RUN ln -s /daemon/bin/nodejs/build/Release/jamid.node jamid.node
+
+COPY package*.json ./
+COPY client/package*.json client/
+
+RUN npm ci
+
+COPY . .
+
+RUN npm run build
CMD ["npm", "start"]
diff --git a/README.md b/README.md
index e8315d4..1cf3b63 100644
--- a/README.md
+++ b/README.md
@@ -26,15 +26,32 @@
You may run the web server in a Docker container. This will automatically build the daemon and do the necessary linking.
+## 1. Build the daemon
+
```bash
-docker build -t jami-web .
-docker run -it -p 3000:3000 jami-web
+cd daemon
+docker build --build-arg config_args="--with-nodejs" -t jami-daemon .
+cd ..
+```
+
+## 2. Build and run the web server and client
+
+```bash
+docker build --tag jami-web .
+docker run -it \
+ -p 3000:3000 \
+ --volume $(pwd)/client:/web-client/client \
+ jami-web
```
## Using [docker-compose](docker run -p 3000:3000 -it jami-project)
This will use a [Docker Volume](https://docs.docker.com/storage/volumes/) to enable auto-refresh when you change a file.
```bash
+# First build the daemon if necessary
+docker-compose build jami-daemon
+
+# Then build the project and start the container
docker-compose build
docker-compose up
```
diff --git a/daemon b/daemon
index 206112b..0ac8c23 160000
--- a/daemon
+++ b/daemon
@@ -1 +1 @@
-Subproject commit 206112b5794d754c426dac91cbda9094daf6cd42
+Subproject commit 0ac8c2341f4974d9077dc6bb9d0706108d8b8dc6
diff --git a/docker-compose.yml b/docker-compose.yml
index 97e4ecb..3a896aa 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,11 +1,21 @@
-version: "3"
+version: "3.9"
services:
jami-web:
- build: .
image: jami-web
+ build: .
volumes:
- - ./client:/app/client
+ - ./client:/web-client/client # Add bind mount to hot-reload client
+ - /web-client/client/node_modules/ # Ignore node_modules from bind mount
ports:
- "3000:3000"
stdin_open: true
+ depends_on:
+ - jami-daemon
+
+ jami-daemon:
+ image: jami-daemon
+ build:
+ context: ./daemon
+ args:
+ config_args: "--with-nodejs"