Skip to content

Commit c2abd73

Browse files
authored
Merge pull request #58 from mu-semtech/feature/rsync-to-improve-reload-time
Use rsync to improve reload time in development mode
2 parents 5a0bdc9 + 4e9a386 commit c2abd73

File tree

4 files changed

+37
-27
lines changed

4 files changed

+37
-27
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM node:18-bookworm
22

33
LABEL maintainer="madnificent@gmail.com"
44

5-
RUN apt-get update && apt-get -y upgrade && apt-get -y install git openssh-client
5+
RUN apt-get update && apt-get -y upgrade && apt-get -y install git openssh-client rsync
66

77
ENV MU_SPARQL_ENDPOINT 'http://database:8890/sparql'
88
ENV MU_APPLICATION_GRAPH 'http://mu.semte.ch/application'

helpers.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Regular rsync command using options optimized to copy local files or files
2+
# from mounted volumes in a Docker container
3+
# Additional rsync options can be passed as argument
4+
function docker-rsync() {
5+
# Common use:
6+
# SOURCE_DIR=$1
7+
# TARGET_DIR=$2
8+
#
9+
# As a reminder if SOURCE_DIR ends with '/', it copies the files from SOURCE_DIR into
10+
# TARGET_DIR. If it doesn't end with '/', it copies SOURCE_DIR itself into TARGET_DIR.
11+
12+
# Used rsync options:
13+
# -a: archive, -H: preserve hard links, -A: preserve ACL, -W: no delta transfer
14+
# -X: extended attributes, -S: efficient sparse files
15+
# --numeric-ids: use uuid by number instead of by name
16+
# --info: silent output
17+
# --no-compress: no compression algorithm
18+
rsync -aHAWXS --numeric-ids --info= --no-compress $@
19+
}

run-development.sh

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
source ./helpers.sh
4+
35
# We want to run from /app but don't want to touch that folder.
46
#
57
# - node_modules which were already available in the mounted sources
@@ -17,27 +19,22 @@ cd /usr/src/app/
1719
# Install dependencies
1820
######################
1921

20-
## Check if package existed and did not change since previous build (/usr/src/app/app/ is copied later in this script, at first run from the template itself it doesn't exist but that's fine for comparison)
22+
## Check if package.json existed and did not change since previous build (/usr/src/app/app/ is copied later in this script, at first run from the template itself it doesn't exist but that's fine for comparison)
2123
cmp -s /app/package.json /usr/src/app/app/package.json
2224
CHANGE_IN_PACKAGE_JSON="$?"
2325

24-
## Copy node_modules to temporary location so we can reuse them, this occurs when the mountend sources have a node_modules and/or on restart
25-
rm -Rf /tmp/node_modules
26-
if [ -d /usr/src/app/app/node_modules/ ]
27-
then
28-
mv ./app/node_modules /tmp/node_modules
29-
fi
30-
## Remove app folder if exists
31-
rm -rf ./app
32-
mkdir ./app
33-
if [ -d /tmp/node_modules/ ]
26+
## Ensure we _sync_ the sources from the hosted app and _copy_ the node_modules.
27+
##
28+
## We don't want to do --delete on the node_modules because this allows us
29+
## to depend on the node_modules installed in an earlier update cycle as well as
30+
## taking node_modules from the hosted app into account.
31+
docker-rsync --delete --exclude node_modules /app/ /usr/src/app/app/
32+
if [ -d /app/node_modules/ ]
3433
then
35-
mv /tmp/node_modules ./app/;
34+
docker-rsync /app/node_modules /usr/src/app/app/
3635
fi
3736

38-
## Copy app folder and config folder (including node_modules so host node_modules win)
39-
cp -rf /app ./
40-
37+
## Copy config folder
4138
if [[ "$(ls -A /config/ 2> /dev/null)" ]]
4239
then
4340
mkdir -p ./app/config/

transpile-sources.sh

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
source ./helpers.sh
4+
35
####
46
#### BUILDS SOURCES
57
####
@@ -52,10 +54,7 @@ cd /usr/src/processing/
5254
mkdir typescript-transpilation build
5355
cp -R ./app/* build
5456

55-
cd coffeescript-transpilation
56-
find . -type d -exec mkdir -p ../build/{} \;
57-
find . -type f -exec cp "{}" ../build/{} \;
58-
cd ..
57+
docker-rsync /usr/src/processing/coffeescript-transpilation/ /usr/src/processing/build/
5958

6059
/usr/src/app/node_modules/.bin/babel \
6160
./build/ \
@@ -70,10 +69,7 @@ mv typescript-transpilation /usr/src/build
7069
# have built the sources coffeescript generated, but these sources were
7170
# already node compliant. We could make coffeescript emit ES6 and
7271
# transpile them to nodejs in this step, but that breaks SourceMaps.
73-
cd coffeescript-transpilation
74-
find . -type d -exec mkdir -p /usr/src/build/{} \;
75-
find . -type f -exec cp "{}" /usr/src/build/{} \;
76-
cd ..
72+
docker-rsync /usr/src/processing/coffeescript-transpilation/ /usr/src/build/
7773

7874

7975
##############
@@ -87,9 +83,7 @@ cp -R /usr/src/processing/node_modules /usr/src/build/
8783
## app modules
8884
if [ -d /usr/src/processing/app/node_modules ]
8985
then
90-
cd /usr/src/processing/app/
91-
find node_modules/ -type d -exec mkdir -p /usr/src/build/{} \;
92-
find node_modules/ -type f -exec cp "{}" /usr/src/build/{} \;
86+
docker-rsync /usr/src/processing/app/node_modules /usr/src/build/
9387
fi
9488

9589
## mu helpers

0 commit comments

Comments
 (0)