forked from Sunbird-Ed/SunbirdEd-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
102 lines (93 loc) · 3.24 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
STARTTIME=$(date +%s)
echo "Starting portal build from build.sh"
set -euo pipefail
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
build_tag=$1
name=player
node=$2
org=$3
buildDockerImage=$4
buildCdnAssests=$5
echo "buildDockerImage: " $buildDockerImage
echo "buildCdnAssests: " $buildCdnAssests
if [ $buildCdnAssests == true ]
then
cdnUrl=$6
echo "cdnUrl: " $cdnUrl
fi
commit_hash=$(git rev-parse --short HEAD)
nvm install 12.16.1 # same is used in client and server
cd src/app
mkdir -p app_dist/ # this folder should be created prior server and client build
rm -rf dist-cdn # remove cdn dist folder
# function to run client build for docker image
build_client_docker(){
echo "starting client local prod build"
npm run build # Angular prod build
echo "completed client local prod build"
cd ..
mv app_dist/dist/index.html app_dist/dist/index.ejs # rename index file
}
# function to run client build for cdn
build_client_cdn(){
echo "starting client cdn prod build"
npm run build-cdn -- --deployUrl $cdnUrl # prod command
export sunbird_portal_cdn_url=$cdnUrl # required for inject-cdn-fallback task
npm run inject-cdn-fallback
echo "completed client cdn prod build"
}
# function to run client build
build_client(){
echo "Building client in background"
nvm use 12.16.1
cd client
echo "starting client yarn install"
yarn install --no-progress --production=true
echo "completed client yarn install"
if [ $buildDockerImage == true ]
then
build_client_docker & # run client local build in background
fi
if [ $buildCdnAssests == true ]
then
build_client_cdn & # run client local build in background
fi
wait # wait for both build to complete
echo "completed client post_build"
}
# function to run server build
build_server(){
echo "Building server in background"
echo "copying requied files to app_dist"
cp -R libs helpers proxy resourcebundles package.json framework.config.js sunbird-plugins routes constants controllers server.js ./../../Dockerfile app_dist
cd app_dist
nvm use 12.16.1
echo "starting server yarn install"
yarn install --no-progress --production=true
echo "completed server yarn install"
node helpers/resourceBundles/build.js -task="phraseAppPull"
}
build_client & # run client build in background
if [ $buildDockerImage == true ]
then
build_server & # run client build in background
fi
## wait for both build to complete
wait
BUILD_ENDTIME=$(date +%s)
echo "Client and Server Build complete Took $[$BUILD_ENDTIME - $STARTTIME] seconds to complete."
if [ $buildDockerImage == true ]
then
cd app_dist
sed -i "/version/a\ \"buildHash\": \"${commit_hash}\"," package.json
echo "starting docker build"
docker build --no-cache --label commitHash=$(git rev-parse --short HEAD) -t ${org}/${name}:${build_tag} .
echo "completed docker build"
cd ../../..
echo {\"image_name\" : \"${name}\", \"image_tag\" : \"${build_tag}\",\"commit_hash\" : \"${commit_hash}\", \"node_name\" : \"$node\"} > metadata.json
fi
ENDTIME=$(date +%s)
echo "build completed. Took $[$ENDTIME - $STARTTIME] seconds."