-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc.sh
executable file
·130 lines (106 loc) · 3.24 KB
/
doc.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
set -e
###
# This is a wrapper to prep the environment then run the varous docker
# commands to build the docker image, build the react app and run it
# in the container for local dev
#
# It takes a single required argument
#
# image - build the docker container image. This only has to be done once
# or if the Docker file is updated
#
# build - builds the react app inside the container. The local host dir
# is mounted inside the container so the build artifact ends up
# on the local file system
#
# run - runs a Vite dev server inside the container and maps it to
# http://127.0.0.1/
###
# build the docker container image
build_image() {
# get NODE_VERSION from the config
eval $(cicd/pipeline/gen_env_vars.py --env local --conf config.ini --clean-branch local)
docker build --tag tokens-build-container --build-arg NODE_VERSION=$NODE_VERSION .
}
###
# build the node app inside the docker container
build_app() {
# first check if the image exists
image_id=$(docker image ls -qf "reference=tokens-build-container")
if [ -z $image_id ] ; then
echo "The container image needs to be built. use $0 image"
exit 0
fi
write_local_conf
rm -rf dist
docker run --rm -v "$(PWD)":"/build" \
-w /build \
tokens-build-container:latest \
npm install; npm run build
}
###
# write an .env.local file with values from conf.ini for the local build
write_local_conf() {
# get Vite vars from the config
eval $(cicd/pipeline/gen_env_vars.py --env local --conf config.ini --clean-branch local)
# in case there's a production file..
rm -f .env.production
echo Writing local config .env.local
cat << EOF > .env.local
VITE_APP_VERSION=$VITE_APP_VERSION
# ALA OIDC
VITE_OIDC_AUTHORITY=$VITE_OIDC_AUTHORITY
VITE_COGNITO_LOGOUT_URI=$VITE_COGNITO_LOGOUT_URI
VITE_OIDC_REDIRECT_URI=$VITE_OIDC_REDIRECT_URI
VITE_OIDC_LOGOUT_REDIRECT_URI=$VITE_OIDC_LOGOUT_REDIRECT_URI
VITE_TOKENS_API=$VITE_TOKENS_API
EOF
}
###
# Run the node app inside the docker conatiner
run_app() {
# first check if the container is already running
container_id=$(docker container ls -qf "ancestor=tokens-build-container")
if [ ! -z $container_id ] ; then
echo "Server already running on http://127.0.0.1:3000/"
exit 0
fi
docker run --rm -d -v "$(PWD)":"/build" \
-p 127.0.0.1:3000:3000 \
-w /build \
tokens-build-container:latest \
npm run dev
echo "Vite dev server running on http://127.0.0.1:3000/"
}
usage() {
echo "Usage: $0 { image | build | run }"
echo " image - build the docker image"
echo " build - build the react app inside the docker container"
echo " run - run the react app inside the docker container"
}
# Check if an argument was provided
if [ $# -eq 0 ]; then
echo "Error: No argument provided"
usage
exit 1
fi
# Store the argument in a variable
arg=$1
# Use a case statement to determine which function to call
case $arg in
"image")
build_image
;;
"build")
build_app
;;
"run")
run_app
;;
*)
echo "Error: Invalid argument provided"
usage
exit 1
;;
esac