OILS / test / alpine.sh View on Github | oils.pub

327 lines, 127 significant
1#!/usr/bin/env bash
2#
3# Make an Alpine Linux chroot and run Oils within it.
4#
5# Usage:
6# test/alpine.sh <function name>
7#
8# Use Cases:
9# - _chroot/alpine-oils-tar
10# Test if the oil tarball can be configured/compiled/installed inside a
11# minimal Linux distro. This is tested with EACH RELEASE.
12# - _chroot/alpine-oils-spec
13# Test how the spec tests run (gawk and zip deps)
14# - _chroot/alpine-distro-build
15# Test if Oil can run Alpine's own package manager and scripts (not done yet)
16#
17# Examples:
18#
19# 1. To make oils-tar env:
20#
21# $0 download
22# $0 extract-oils-tar
23# $0 setup-dns
24# $0 add-oils-tar-deps
25#
26# One of:
27# devtools/release-native.sh make-tar
28# devtools/release.sh py-tarball
29#
30# $0 copy-tar
31# $0 test-tar
32#
33# 1. To make a spec test env:
34#
35# $0 download
36# $0 extract-oils-spec
37# $0 setup-dns
38# $0 add-oils-spec-deps
39#
40# $0 copy-tar _chroot/alpine-oils-spec # TODO: copy arbitrary tarball
41# TODO: set up non-root user
42#
43# $0 make-oils-spec
44# $0 copy-oils-spec
45#
46# Now enter the chroot:
47#
48# test/alpine.sh interactive _chroot/alpine-oils-spec
49# bash # if you prefer, use bash inside
50#
51# cd src/
52# tar -x -z < oils-ref-$VERSION.tar.gz
53# cd oil-$VERSION/
54# ./configure && make && sudo ./install
55#
56# cd ~/src/oils-spec
57# tar -x < oils-spec.tar
58#
59# test/spec-alpine.sh all
60# test/spec-alpine.sh archive-results
61#
62# TODO: Automate this more with an arbitrary tarball.
63#
64# Now again OUTSIDE:
65#
66# test/alpine.sh copy-wwz
67# test/alpine.sh publish
68
69set -o nounset
70set -o pipefail
71set -o errexit
72
73readonly ROOTFS_URL='http://dl-cdn.alpinelinux.org/alpine/v3.11/releases/x86_64/alpine-minirootfs-3.11.3-x86_64.tar.gz'
74
75readonly CHROOT_OILS_TAR=_chroot/alpine-oils-tar
76readonly CHROOT_OILS_SPEC=_chroot/alpine-oils-spec
77readonly CHROOT_DISTRO_BUILD=_chroot/alpine-distro-build
78
79download() {
80 wget --no-clobber --directory _tmp $ROOTFS_URL
81}
82
83_extract() {
84 local dest=$1
85
86 local tarball=_tmp/$(basename $ROOTFS_URL)
87
88 mkdir -p $dest
89 # Must be run as root
90 tar --extract --gzip --verbose --directory $dest < $tarball
91
92 du --si -s $dest
93}
94extract-oils-tar() { sudo $0 _extract $CHROOT_OILS_TAR; }
95extract-oils-spec() { sudo $0 _extract $CHROOT_OILS_SPEC; }
96extract-distro-build() { sudo $0 _extract $CHROOT_DISTRO_BUILD; }
97
98# Without this, you can't 'su myusername'. It won't be able to execute bash.
99chmod-chroot() {
100 local dest=${1:-$CHROOT_OILS_TAR}
101 sudo chmod 755 $dest
102}
103
104# add DNS -- for package manager
105
106_setup-dns() {
107 local chroot_dir=${1:-$CHROOT_OILS_TAR}
108 cat >$chroot_dir/etc/resolv.conf <<EOF
109nameserver 8.8.8.8
110nameserver 8.8.4.4
111EOF
112}
113setup-dns() { sudo $0 _setup-dns "$@"; }
114
115#
116# Deps for different chroots
117#
118
119# 106 MiB as of 7/7/2017.
120add-oils-tar-deps() {
121 local chroot_dir=${1:-$CHROOT_OILS_TAR}
122 sudo chroot $chroot_dir /bin/sh <<EOF
123apk update
124apk add bash make gcc g++ musl-dev
125EOF
126}
127
128# Additions:
129# python2, gawk: to run spec tests
130# zip: for publishing it
131
132# 3/6/2020: 154 MiB
133add-oils-spec-deps() {
134 local chroot_dir=${1:-$CHROOT_OILS_SPEC}
135 sudo chroot $chroot_dir /bin/sh <<EOF
136apk update
137apk add bash make gcc musl-dev python2 gawk zip
138EOF
139}
140
141# alpine-sdk scripts are /bin/sh busybox scripts!
142# Executing busybox-1.26.2-r5.trigger
143# Executing ca-certificates-20161130-r2.trigger
144# OK: 195 MiB in 72 packages
145#
146# Hm they still have triggers...
147# 72 packages. bash/readline are installed!
148
149add-alpine-sdk() {
150 local chroot_dir=${1:-$CHROOT_DISTRO_BUILD}
151 sudo chroot $chroot_dir /bin/sh <<EOF
152apk update
153apk add bash alpine-sdk
154EOF
155}
156
157#
158# Admin
159#
160
161list-packages() {
162 local chroot_dir=${1:-$CHROOT_DISTRO_BUILD}
163 sudo chroot $chroot_dir apk info
164}
165
166destroy-chroot() {
167 local chroot_dir=${1:-$CHROOT_OILS_TAR}
168 sudo rm -r -rf $chroot_dir
169}
170
171# Interactive /bin/sh.
172enter-chroot() {
173 local chroot_dir=${1:-$CHROOT_OILS_TAR}
174 shift
175 sudo chroot $chroot_dir "$@"
176}
177
178interactive() {
179 local chroot_dir=${1:-$CHROOT_OILS_TAR}
180 enter-chroot $chroot_dir /bin/sh
181}
182
183#
184# oils-tar functions
185#
186
187readonly OILS_VERSION=$(head -n 1 oils-version.txt)
188
189_copy-tar() {
190 local chroot_dir=${1:-$CHROOT_OILS_TAR}
191 local name=${2:-oils-for-unix}
192 local version=${3:-$OILS_VERSION}
193
194 local dest=$chroot_dir/src
195 rm -r -f $dest # make sure it's empty
196 mkdir -p $dest
197 cp -v _release/$name-$version.tar.gz $dest
198}
199
200copy-tar() {
201 sudo $0 _copy-tar "$@"
202}
203
204_test-tar() {
205 local chroot_dir=${1:-$CHROOT_OILS_TAR}
206 local name=${2:-oils-for-unix}
207 local version=${3:-$OILS_VERSION}
208 local target=_bin/${name}.ovm
209
210 # TODO:
211 # - Run soil/cpp-tarball.sh build-static
212 # - Then publish this musl build!
213
214 enter-chroot "$chroot_dir" /bin/sh -c '
215set -e
216
217name=$1
218version=$2
219target=$3
220
221cd src
222tar --extract -z < $name-$version.tar.gz
223cd $name-$version
224./configure
225
226# Build the tar
227if test $name = oils-ref; then
228 time make $target
229 $target --version
230else
231 _build/oils.sh
232 _bin/cxx-opt-sh/osh --version
233fi
234
235./install
236echo
237echo "*** Running osh"
238
239osh --version
240echo status=$?
241echo
242
243ldd $(which osh)
244
245echo DONE
246' dummy "$name" "$version" "$target"
247}
248
249test-tar() {
250 sudo $0 _test-tar "$@"
251}
252
253copy-static() {
254 local chroot_dir=${1:-$CHROOT_OILS_TAR}
255 local dir=_tmp/musl
256 mkdir -p $dir
257 cp -v \
258 $CHROOT_OILS_TAR/src/oils-for-unix-$OILS_VERSION/_bin/cxx-opt-sh/oils-for-unix.static* \
259 $dir
260}
261
262
263#
264# cpp tarball
265#
266
267copy-cpp-tar() {
268 copy-tar '' oils-for-unix
269}
270
271test-cpp-tar() {
272 test-tar '' oils-for-unix
273}
274
275#
276# oils-spec functions
277#
278
279# Spec tests
280make-oils-spec() {
281 # TODO: maybe get rid of doctools
282 # test/spec.sh is just for reference
283 # web/*.css dir because we want the end user to be able to see it
284 find \
285 benchmarks/time_.py \
286 test/sh_spec.py doctools/{html_head,doc_html,__init__}.py \
287 test/{common,spec-common,spec,spec-alpine,spec-runner}.sh \
288 spec/ \
289 web/*.css \
290 -type f \
291 | xargs tar --create > _tmp/oils-spec.tar
292}
293
294_copy-oils-spec() {
295 local dest=$CHROOT_OILS_SPEC/src/oils-spec
296 mkdir -p $dest
297 cp -v _tmp/oils-spec.tar $dest
298}
299copy-oils-spec() { sudo $0 _copy-oils-spec "$@"; }
300
301
302copy-wwz() {
303 ### Take results out of chroot
304
305 local out=_tmp/spec-results
306 mkdir -p $out
307 cp -v _chroot/alpine-oils-spec/src/oils-spec/*.wwz $out
308 ls -l $out
309}
310
311publish() {
312 ### Publish results to oilshell.org/spec-results
313 # similar to web/publish.sh
314
315 local user=$1
316 local host=$user.org
317
318 local path=$2
319
320 local dest='oilshell.org/spec-results'
321 ssh $user@$host mkdir --verbose -p $dest
322 scp $path $user@$host:$dest
323
324 echo "Visit http://$dest/$(basename $path)/"
325}
326
327"$@"