Skip to content

Commit

Permalink
Merge pull request #37 from ZIMkaRU/feature/isolate-electron-builder-…
Browse files Browse the repository at this point in the history
…env-into-docker-containers

Isolate electron builder env into docker containers
  • Loading branch information
prdn authored Apr 14, 2020
2 parents c034c7a + 91c5fc6 commit 3c13407
Show file tree
Hide file tree
Showing 11 changed files with 323 additions and 90 deletions.
16 changes: 16 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
**/node_modules
**/.env
bfx-reports-framework/db/*.db
bfx-reports-framework/db/*.json
bfx-reports-framework/config/*.json
bfx-reports-framework/config/facs/*.json
bfx-reports-framework/logs/*.log
bfx-reports-framework/csv
bfx-report-ui/build
bfx-report-ui/bfx-report-express/logs/*.log
bfx-report-ui/bfx-report-express/config/*.json
docker-compose.yaml
Dockerfile.linux-builder
Dockerfile.win-builder
Dockerfile.mac-builder
dist
11 changes: 11 additions & 0 deletions Dockerfile.linux-builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM electronuserland/builder:10

RUN apt-get install -y --no-install-recommends \
p7zip-full \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

COPY . .

ENTRYPOINT ["./init.sh"]
CMD ["-p", "linux", "-u"]
11 changes: 11 additions & 0 deletions Dockerfile.mac-builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM electronuserland/builder:10

RUN apt-get install -y --no-install-recommends \
p7zip-full \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

COPY . .

ENTRYPOINT ["./init.sh"]
CMD ["-p", "mac", "-u"]
6 changes: 6 additions & 0 deletions Dockerfile.ui-builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM electronuserland/builder:10

COPY . .

ENTRYPOINT ["./build-ui.sh"]
CMD ["-i"]
11 changes: 11 additions & 0 deletions Dockerfile.win-builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM electronuserland/builder:wine-05.18

RUN apt-get update && apt-get install -y --no-install-recommends \
p7zip-full \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

COPY . .

ENTRYPOINT ["./init.sh"]
CMD ["-p", "win", "-u"]
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,33 @@ npm run electron

### Build distributions

For doing builds for other platforms please have “Multi Platform Build” in consideration: https://www.electron.build/multi-platform-build <br/>
For doing builds for other platforms please have “Multi Platform Build” in consideration: [electron-builder documentation](https://www.electron.build/multi-platform-build)

#### Requirements

- [Install Docker](https://docs.docker.com/engine/install)
- [Install Docker Compose](https://docs.docker.com/compose/install/#install-compose-on-linux-systems)
- For Linux, if you don’t want to preface the docker command with `sudo`, create a Unix group called docker and add users to it, [check the documentation](https://docs.docker.com/engine/install/linux-postinstall)

For creating the distributions please run the following commands, after the execution is finished the file would be in */dist* folder

- Individual:

```console
#Distribution for Linux
npm run dist-linux
docker-compose up --build --force-recreate ui-builder linux-builder

#Distribution for Windows
npm run dist-win
docker-compose up --build --force-recreate ui-builder win-builder

#Distribution for MacOs
npm run dist-mac
docker-compose up --build --force-recreate ui-builder mac-builder
```

- Linux + Windows + MacOs:

```console
npm start
docker-compose up --build --force-recreate
```

## Export CSV reports
Expand Down
80 changes: 80 additions & 0 deletions build-ui.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash

set -x

export NODE_PATH=src/
export PUBLIC_URL=/
export REACT_APP_PLATFORM=localhost
export REACT_APP_TITLE=Bitfinex Reports
export REACT_APP_LOGO_PATH=favicon.ico
export REACT_APP_ELECTRON=true

ROOT=$PWD
frontendFolder="$ROOT/bfx-report-ui"
uiBuildFolder=/ui-build
uiReadyFile="$uiBuildFolder/READY"

programname=$0
isDevEnv=0
isInitedSubmodules=0

rm -rf $uiBuildFolder/*

function usage {
echo "Usage: $programname [-d] | [-h]"
echo " -d turn on developer environment"
echo " -h display help"
exit 1
}

while [ "$1" != "" ]; do
case $1 in
-d | --dev ) isDevEnv=1
;;
-i | --init ) isInitedSubmodules=1
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done

if [ $isDevEnv != 0 ]; then
echo "Developer environment is turned on"
fi

if [ $isInitedSubmodules != 0 ]; then
git submodule foreach --recursive git git clean -fdx
git submodule foreach --recursive git reset --hard HEAD
git submodule sync
git submodule update --init --recursive
git config url."https://github.com/".insteadOf [email protected]:
git pull --recurse-submodules
git submodule update --remote --recursive
fi

cd $frontendFolder

if ! [ -s "$frontendFolder/package.json" ]; then
exit 1
fi

npm i

sed -i -e "s/API_URL: .*,/API_URL: \'http:\/\/localhost:34343\/api\',/g" $frontendFolder/src/var/config.js
sed -i -e "s/WS_ADDRESS: .*,/WS_ADDRESS: \'ws:\/\/localhost:34343\/ws\',/g" $frontendFolder/src/var/config.js

if [ $isDevEnv != 0 ]; then
sed -i -e "s/KEY_URL: .*,/KEY_URL: \'https:\/\/test.bitfinex.com\/api\',/g" $frontendFolder/src/var/config.js
fi

sed -i -e "s/showAuthPage: .*,/showAuthPage: true,/g" $frontendFolder/src/var/config.js
sed -i -e "s/showSyncMode: .*,/showSyncMode: true,/g" $frontendFolder/src/var/config.js
sed -i -e "s/showFrameworkMode: .*,/showFrameworkMode: true,/g" $frontendFolder/src/var/config.js
npm run build

mv -f $frontendFolder/build/* $uiBuildFolder
touch $uiReadyFile
57 changes: 57 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
version: '3.7'

services:
ui-builder:
container_name: ui-builder
build:
context: .
dockerfile: Dockerfile.ui-builder
volumes:
- ui-build:/ui-build

linux-builder:
container_name: linux-builder
build:
context: .
dockerfile: Dockerfile.linux-builder
environment:
ELECTRON_CACHE: /root/.cache/electron
ELECTRON_BUILDER_CACHE: /root/.cache/electron-builder
volumes:
- ui-build:/ui-build
- ./dist:/dist
- electron-cache:/root/.cache/electron
- electron-builder-cache:/root/.cache/electron-builder

win-builder:
container_name: win-builder
build:
context: .
dockerfile: Dockerfile.win-builder
environment:
ELECTRON_CACHE: /root/.cache/electron
ELECTRON_BUILDER_CACHE: /root/.cache/electron-builder
volumes:
- ui-build:/ui-build
- ./dist:/dist
- electron-cache:/root/.cache/electron
- electron-builder-cache:/root/.cache/electron-builder

mac-builder:
container_name: mac-builder
build:
context: .
dockerfile: Dockerfile.mac-builder
environment:
ELECTRON_CACHE: /root/.cache/electron
ELECTRON_BUILDER_CACHE: /root/.cache/electron-builder
volumes:
- ui-build:/ui-build
- ./dist:/dist
- electron-cache:/root/.cache/electron
- electron-builder-cache:/root/.cache/electron-builder

volumes:
ui-build:
electron-cache:
electron-builder-cache:
113 changes: 83 additions & 30 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@

set -x

export NODE_PATH=src/
export PUBLIC_URL=/
export REACT_APP_PLATFORM=localhost
export REACT_APP_TITLE=Bitfinex Reports
export REACT_APP_LOGO_PATH=favicon.ico
export REACT_APP_ELECTRON=true

ROOT=$PWD

programname=$0
isDevEnv=0
isNotSkippedReiDeps=1
targetPlatform=0
isSkippedUIBuild=0

function usage {
echo "Usage: $programname [-d] | [-h]"
Expand All @@ -22,12 +17,37 @@ function usage {
exit 1
}

function getConfValue {
local dep=""
local value=""

if [ $# -ge 1 ]
then
dep=$1
else
exit 1
fi

version=$(cat $ROOT/package.json \
| grep \"$dep\" \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| tr -d '[[:space:]]')

echo $version
}

while [ "$1" != "" ]; do
case $1 in
-d | --dev ) isDevEnv=1
;;
-s | --skip-rei-deps ) isNotSkippedReiDeps=0
;;
-p | --target-platform ) targetPlatform=$2; shift
;;
-u | --skip-ui-build ) isSkippedUIBuild=1
;;
-h | --help ) usage
exit
;;
Expand All @@ -44,38 +64,31 @@ fi
frontendFolder="$ROOT/bfx-report-ui"
expressFolder="$frontendFolder/bfx-report-express"
backendFolder="$ROOT/bfx-reports-framework"
uiBuildFolder=/ui-build
uiReadyFile="$uiBuildFolder/READY"

rm -rf $frontendFolder
rm -rf $backendFolder
mkdir $frontendFolder
mkdir $backendFolder
mkdir $ROOT/dist 2>/dev/null
chmod a+xwr $ROOT/dist 2>/dev/null

git submodule foreach --recursive git clean -fdx
git submodule foreach --recursive git reset --hard HEAD
git submodule sync
git submodule update --init --recursive
git config url."https://github.com/".insteadOf [email protected]:
git pull --recurse-submodules
git submodule update --remote
git submodule update --remote --recursive

cd $frontendFolder
if [ $isSkippedUIBuild == 0 ]
then
devFlag=""

git submodule sync
git submodule update --init --recursive
git pull --recurse-submodules
git submodule update --remote
npm i

sed -i -e "s/API_URL: .*,/API_URL: \'http:\/\/localhost:34343\/api\',/g" $frontendFolder/src/var/config.js
sed -i -e "s/WS_ADDRESS: .*,/WS_ADDRESS: \'ws:\/\/localhost:34343\/ws\',/g" $frontendFolder/src/var/config.js
echo "SKIP_PREFLIGHT_CHECK=true" >> $frontendFolder/.env
if [ $isDevEnv == 0 ]; then
devFlag="-d"
fi

if [ $isDevEnv != 0 ]; then
sed -i -e "s/KEY_URL: .*,/KEY_URL: \'https:\/\/test.bitfinex.com\/api\',/g" $frontendFolder/src/var/config.js
bash ./build-ui.sh $devFlag
fi

sed -i -e "s/showAuthPage: .*,/showAuthPage: true,/g" $frontendFolder/src/var/config.js
sed -i -e "s/showSyncMode: .*,/showSyncMode: true,/g" $frontendFolder/src/var/config.js
sed -i -e "s/showFrameworkMode: .*,/showFrameworkMode: true,/g" $frontendFolder/src/var/config.js
npm run build

cp $expressFolder/config/default.json.example $expressFolder/config/default.json

cd $backendFolder
Expand All @@ -93,5 +106,45 @@ fi
cd $ROOT

if [ $isNotSkippedReiDeps != 0 ]; then
bash ./reinstall-deps.sh
if [ $targetPlatform != 0 ]
then
bash ./reinstall-deps.sh $targetPlatform

if [ $isSkippedUIBuild != 0 ]
then
while !(test -f "$uiReadyFile"); do
sleep 0.5
done
fi

mkdir $frontendFolder/build 2>/dev/null
rm -rf $frontendFolder/build/*
cp -avr $uiBuildFolder/* $frontendFolder/build
chmod -R a+xwr $frontendFolder/build
./node_modules/.bin/electron-builder build --$targetPlatform
chmod -R a+xwr ./dist

productName=$(getConfValue "productName")
version=$(getConfValue "version")
arch="x64"

unpackedFolder=$(ls -d $ROOT/dist/*/ | grep $targetPlatform | head -1)
zipFile="$ROOT/dist/$productName-$version-$arch-$targetPlatform.zip"

if ! [ -d $unpackedFolder ]; then
exit 1
fi

cd $unpackedFolder
7z a -tzip $zipFile . -mmt | grep -v "Compressing"
cd $ROOT

rm -rf /dist/*$targetPlatform*
mv -f ./dist/*$targetPlatform*.zip /dist
chmod -R a+xwr /dist 2>/dev/null

exit 0
else
bash ./reinstall-deps.sh
fi
fi
Loading

0 comments on commit 3c13407

Please sign in to comment.