-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeDockerfile.sh
executable file
·80 lines (67 loc) · 1.58 KB
/
makeDockerfile.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
#!/bin/bash
#write a Dockerfile for an extended image
function printHelp {
echo "write a Dockerfile for an extended image."
echo "options: (with defaults)"
echo " -r [registry] (TODO default)"
echo " -i [image] (TODO default)"
echo " -t [tag]"
echo " -d [build directory] (.)"
}
registry="DEFAULT"
image="DEFAULT"
tag=""
dfiledir="." #dir within which to make dockerfile
#if [[ -z $1 ]]; then
# echo "?"
# exit 0
#fi
while getopts "r:i:t:d:h" opt; do
case $opt in
r)
registry=$OPTARG
;;
i)
image=$OPTARG
;;
t)
tag=$OPTARG
;;
d)
dfiledir=$OPTARG
;;
h)
printHelp
exit 0
;;
esac
done
cd ${dfiledir}
#use existing tag to base image from if none passed in
#if [[ ${tag} == "" ]]; then
#TODO
#fi
#scan dir for bins+libs and write dockerfile cmds
if [[ -f ./Dockerfile ]]; then
d=`date +%s`
echo "backing up old Dockerfile"
cp Dockerfile Dockerfile.${d}.bak
fi
echo "Making Dockerfile!"
echo "FROM ${registry}${image}:${tag}" > Dockerfile
echo "" >> Dockerfile
echo "USER root" >> Dockerfile
echo "" >> Dockerfile
#TODO: insert the logic for your specific application
# below is a sample of a hypothetical file placement
# use a for loop for each string pattern search
# better yet, define a map of search string to path in a config file and use that
for f in `ls libfile*.so 2>/dev/null`; do
#for f in `find . -name "something_*"`; do
echo "COPY ${f} /path/for/${f}" >> Dockerfile
echo "RUN chmod 755 /path/for/${f}" >> Dockerfile
echo "RUN chown user1:group1 /path/for/${f}" >> Dockerfile
done
echo "" >> Dockerfile
echo "USER user1" >> Dockerfile
cd -