forked from yao-pkg/pkg-binaries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·168 lines (154 loc) · 3.27 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
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
#!/bin/bash
set -e
# One line usage: ./build.sh <arch> <nodeVersion> <os>
# arch: arm32v6 | arm32v7 | arm64
# node: node<version>
# os: linux | alpine
#
if [ ! -z "$1" ]; then
if [ "$1" == "arm32v7" ]; then
arch=arm32v7
pkg_arch=armv7
platform="linux/arm/v7"
elif [ "$1" == "arm32v6" ]; then
arch=arm32v6
pkg_arch=armv6
platform="linux/arm/v6"
elif [ "$1" == "arm64" ]; then
arch=arm64v8
pkg_arch=arm64
platform="linux/arm64"
else
echo '####################'
echo '## Invalid arch ##'
echo '####################'
exit
fi
pkg_node=$2
if [ "$3" == "linux" ]; then
pkg_os=linux
tag="node:latest"
dependencies="apt-get update \&\& apt-get install -y --no-install-recommends wget build-essential git"
elif [ "$3" == "alpine" ]; then
pkg_os=alpine
tag="node:alpine"
dependencies="apk update \&\& apk --no-cache add git wget build-base python paxctl linux-headers"
else
echo '####################'
echo '## Invalid OS ##'
echo '####################'
exit
fi
else
PS3="Architecture: >"
options=(
"arm32v6"
"arm32v7"
"arm64"
)
echo ''
select option in "${options[@]}"; do
case "$REPLY" in
1)
arch=arm32v6
pkg_arch=armv6
platform="linux/arm/v6"
break
;;
2)
arch=arm32v7
pkg_arch=armv7
platform="linux/arm/v7"
break
;;
3)
arch=arm64v8
pkg_arch=arm64
platform="linux/arm64"
break
;;
*)
echo '####################'
echo '## Invalid option ##'
echo '####################'
exit
esac
done
PS3="NodeJS version: >"
options=(
"Node 8 LTS (Carbon)"
"Node 10 LTS (Dubnium) "
"Node 12 LTS (Current)"
)
echo ''
select option in "${options[@]}"; do
case "$REPLY" in
1)
pkg_node=node8
break
;;
2)
pkg_node=node10
break
;;
3)
pkg_node=node12
break
;;
*)
echo '####################'
echo '## Invalid option ##'
echo '####################'
exit
esac
done
PS3="OS version: >"
options=(
"linux"
"alpine"
)
echo ''
select option in "${options[@]}"; do
case "$REPLY" in
1)
pkg_os=linux
tag="node:latest"
dependencies="apt-get update \&\& apt-get install -y --no-install-recommends wget build-essential git"
break
;;
2)
pkg_os=alpine
tag="node:alpine"
dependencies="apk update \&\& apk --no-cache add git wget build-base python paxctl linux-headers"
break
;;
*)
echo '####################'
echo '## Invalid option ##'
echo '####################'
exit
esac
done
fi
cp Dockerfile.cross Dockerfile.build
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i "" "s|__TAG__|${tag}|g" Dockerfile.build
sed -i "" "s|__DEPENDENCIES__|${dependencies}|g" Dockerfile.build
else
sed -i "s|__TAG__|${tag}|g" Dockerfile.build
sed -i "s|__DEPENDENCIES__|${dependencies}|g" Dockerfile.build
fi
docker buildx build --progress plain -f Dockerfile.build \
--platform $platform \
--build-arg PKG_NODE="$pkg_node" \
--build-arg PKG_OS="$pkg_os" \
--build-arg PKG_ARCH="$pkg_arch" \
--load \
-t ${arch}/pkgbinaries:${pkg_os}-${pkg_node} .
APP=$(docker run --rm -it -d ${arch}/pkgbinaries:${pkg_os}-${pkg_node})
mkdir -p tmp
docker cp $APP:/fetched/ ./tmp/
docker kill $APP
mv tmp/fetched/v*/built* ./
rename 's/built/fetched/g' *
rm -rf tmp Dockerfile.build