-
Notifications
You must be signed in to change notification settings - Fork 36
/
buildProjectImages.sh
executable file
·186 lines (125 loc) · 3.39 KB
/
buildProjectImages.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/bash
# Builds a project that is in the project subdirectory. It always uses
# a local pentaho server image to build from, so that has to exist previously
# 1. Check if we have local images; if not, send to listBuilds
# 2. List the projects we have; Ask to select one
# 3. After selecting a project, select the base image to use
# 4. Dynamically change the project-specific dockerfile to change the FROM
# 5. Zip the solutions and prepare to drop them in default-content
# 6. Find a way to create the datasources. Maybe with the patches?
# 7. Build it
BASEDIR=$(dirname $0)
cd $BASEDIR
PROJECTS_DIR="projects"
# 1. Search for what we have
IMAGES=$( docker images | egrep '^baserver-' | cut -d' ' -f 1 )
if (( $(grep -c . <<< "$IMAGES" ) == 0 ))
then
echo No valid local images found. Please create one
exit 1
fi
# 2. List the projects; Choose one
PROJECTS=$(ls -d -1 $PROJECTS_DIR/*/)
if (( $(grep -c . <<< "$PROJECTS" ) == 0 ))
then
echo No projects found in the $PROJECTS_DIR directory. Maybe you forgot to link / clone?
exit 1
fi
echo
echo "Choose a project to build an image for:"
echo
IFS=$'\n';
n=-1
for project in $PROJECTS
do
((n++))
projectname=$(echo $project | rev | cut -d/ -f2 | rev)
echo " [$n] $projectname"
PROJECT_LIST[$n]=$projectname
done;
echo
# Which version do you want to start?
read -e -p "> Choose project: " PROJECTNO
PROJECTNO=${PROJECTNO:-"-1"}
if [ $PROJECTNO == "-1" ]
then
echo Invalid selection
exit 1;
fi
project=${PROJECT_LIST[$PROJECTNO]}
if [ -z $project ]
then
echo Invalid selection [$PROJECTNO]
exit 1
fi
# 3. Select the base image to use
echo
echo Select the image to use for the project
echo
IFS=$'\n';
n=-1
for image in $IMAGES
do
((n++))
echo " [$n] $image"
IMAGE[$n]=$image
done;
echo
# Which version do you want to start?
read -e -p "> Choose image: " IMAGENO
IMAGENO=${IMAGENO:-"-1"}
if [ $IMAGENO == "-1" ]
then
echo Invalid selection
exit 1;
fi
image=${IMAGE[$IMAGENO]}
if [ -z $image ]
then
echo Invalid selection [$IMAGENO]
exit 1
fi
echo you chose: Project: $project, Image: $image
# 4. Dynamically change the project-specific dockerfile to change the FROM
tmpDir=tmp/buildProjectTmp
# We'll use one of two things: If we have a project-specific Dockerfile, we'll
# go for that one; if not, we'll use a default.
# We'll also build a tmp dir for processing the stuff
if [ -d $tmpDir ]
then
rm -rf $tmpDir
fi
mkdir -p $tmpDir
if [ -f $PROJECTS_DIR/$project/_dockerfiles/Dockerfile ]
then
echo " Found a project specific dockerfile. That's what we'll use"
cp -r $PROJECTS_DIR/$project/_dockerfiles/* $tmpDir
else
echo " Project specific dockerfile not found. Using default"
cp -r dockerfiles/buildProject/* $tmpDir
fi
sed -i '' -e "s/BUILDPROJECTFROMIMAGE/$image/" $tmpDir/Dockerfile
# 5. Zip the solutions and prepare to drop them in default-content
echo
echo Adding the structure to the build
echo
solutionTmpDir=$tmpDir/solutionDir
mkdir $solutionTmpDir
cp -R $PROJECTS_DIR/$project/solution/* $solutionTmpDir/
pushd $solutionTmpDir
zip -r ../solution.zip *
popd
DOCKERTAG=$(echo pdu-$project-$image | tr '[:upper:]' '[:lower:]')
echo
echo All set - building docker image $DOCKERTAG
echo
# 6. Find a way to create the datasources. Maybe with the patches?
# 7. Build it
docker build --no-cache -t $DOCKERTAG $tmpDir
# 8. Clean it
rm -rf $tmpDir
echo
echo Project image built successfully
echo
cd $BASEDIR
exit 0