-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathlocal-configure.sh
executable file
·122 lines (97 loc) · 3.71 KB
/
local-configure.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
#!/bin/bash
################################################################################
# Generate local build scripts
################################################################################
# debug
set -ex
# read profile from first argument
PROFILE="$1"
# verify profile
[ -n "$PROFILE" ]
[ -f "Dockerfile.$PROFILE" ]
# enable aliases below
shopt -s expand_aliases
# use typical macos aliases
which -s gsed && alias sed=gsed || true
# use this directory for build
WORKDIR=build.$PROFILE
# add bootstrap code to build shell script
cat << EOF > local-build.$PROFILE.sh
#!/bin/bash
# debug
set -ex
# enable aliases below
shopt -s expand_aliases
# use typical macos aliases
which -s gsed && alias sed=gsed || true
which -s grealpath && alias realpath=grealpath || true
which -s gsha512sum && alias sha512sum=gsha512sum || true
which -s mkisofs && alias genisoimage=mkisofs || true
# create build directory
mkdir -p "$WORKDIR"
# clean build directory
rm -rf "$WORKDIR"/{Dockerfile,*.iso,*.bat,*.sh,support,install,virtio}
# copy build context
cp -rfv support files "$WORKDIR"
################################################################################
# Code below is autogenerated from Dockerfile.$PROFILE file
################################################################################
EOF
# use regexp magic to convert Dockerfile to shell script for local execution
cat Dockerfile.$PROFILE \
| sed -e 's!^RUN !!g' \
-e 's!^\(ARG\|ENV\) \(.*\)=\(.*\)$!\2=${\2-\3}!g' \
-e 's!^\(ARG\|ENV\) !# \0!g' \
-e 's!^FROM !# \0!g' \
-e 's!^LABEL !# \0!g' \
-e 's!^ENTRYPOINT !# \0!g' \
-e 's!^EXPOSE !# \0!g' \
-e 's!^COPY !cp -f ./!g' \
-e 's!^WORKDIR \(.*\)$!mkdir -p "'$WORKDIR'" \&\& cd "'$WORKDIR'"!g' \
-e 's!yum !true \0!g' \
-e 's!set !true \0!g' \
-e '/^qemu-img create.*$/a if which -s vncviewer; then (sleep 5; vncviewer localhost:$VNC_PORT) & fi' \
-e '/^QEMU_SRC_URL=/,/^$/d' \
-e '/^HEALTHCHECK /,/^$/d' \
>> local-build.$PROFILE.sh
# homebrew's qemu doesn't support aio=native by default
if [ `uname` = "Darwin" ]; then
sed -i -e 's!,aio=native!!g' local-build.$PROFILE.sh
fi
# homebrew's qemu doesn't support qxl by default
if [ `uname` = "Darwin" ]; then
sed -i -e 's!-qxl!-cirrus!g' local-build.$PROFILE.sh
fi
# mark build shell script executable
chmod +x local-build.$PROFILE.sh
# add header into generated Dockerfile
cat << EOF > local-build.$PROFILE.docker
################################################################################
# Code below is autogenerated from Dockerfile.$PROFILE file
################################################################################
EOF
# generate trimmed down Dockerfile that assumes that system.qcow2 is already built
cat Dockerfile.$PROFILE \
| sed -e '/^ARG WIN_ISO_FILE=/,/RUN rm -f install\.iso/d' \
-e '/^COPY support\/start-node/a COPY system.qcow2 .' \
-e 's/^FROM .*$/FROM amazonlinux:2/g' \
-e '/RUN \[ -n "\$PRODUCT_KEY" \]/d' \
>> local-build.$PROFILE.docker
# disable debugging mode
set +x
# show build instructions
echo
echo "################################################################################"
echo "# Local build scripts have been successfully generated"
echo "################################################################################"
echo
echo "Review produced local build scripts (IMPORTANT):"
echo " less ./local-build.$PROFILE.sh"
echo " less ./local-build.$PROFILE.docker"
echo
echo "Run local build script:"
echo " PRODUCT_KEY=ABCDE-ABCDE-ABCDE-ABCDE-ABCDE ./local-build.$PROFILE.sh"
echo
echo "Finish in Docker:"
echo " docker build -f local-build.$PROFILE.docker -t $PROFILE build.$PROFILE"
echo