-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild
executable file
·67 lines (48 loc) · 2.15 KB
/
build
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
#!/usr/bin/env bash
set -euox pipefail
# This init script is from https://github.com/vorburger/cloudshell
# Original Author: Michael Vorburger <mike@vorburger.ch> http://www.vorburger.ch
# TODO check if 'podman' is available and use that if so, otherwise run with 'docker'
PODMAN_OR_DOCKER="sudo docker"
function test_container() {
local name=$1
CONTAINER_ID=$(${PODMAN_OR_DOCKER} run --name "${name}"-test -d -eUSER_ID=tester -eUSER_PWD=testit -p 8080 "${name}")
# Test that `whoami` returns "tester"
WHOAMI=$(${PODMAN_OR_DOCKER} exec "${name}"-test /init whoami)
if [ ! "$WHOAMI" = 'tester' ]; then
echo "TEST FAILED, whoami != tester: $WHOAMI"
${PODMAN_OR_DOCKER} rm -f "$CONTAINER_ID"
return 1
fi
# Test that `sudo` works
GROOT=$(${PODMAN_OR_DOCKER} exec "${name}"-test /init sudo echo groot)
if [ ! "$GROOT" = 'groot' ]; then
echo "TEST FAILED, sudo does not work, I am not groot, but: $GROOT"
${PODMAN_OR_DOCKER} rm -f "$CONTAINER_ID"
return 1
fi
HTTP_PORT="$(${PODMAN_OR_DOCKER} ps|grep "${name}"-test|sed 's/.*0.0.0.0://g'|sed 's/->.*//g')"
# Test that HTTP GET without uid & pwd fails
if ! curl --silent --show-error http://localhost:"$HTTP_PORT"; then
echo "TEST FAILED, accessible without BASIC auth"
${PODMAN_OR_DOCKER} rm -f "$CONTAINER_ID"
return 1
fi
# Test that HTTP GET with uid & pwd on BASIC auth returns GoTTY HTML page
HTTP_REPLY=$(curl --user tester:testit --silent --show-error http://localhost:"$HTTP_PORT" | head --lines=1 -)
${PODMAN_OR_DOCKER} rm -f "$CONTAINER_ID"
if [ ! "$HTTP_REPLY" = '<!doctype html>' ]; then
echo "TEST FAILED, not starting with expected <!doctype html>: $HTTP_REPLY"
return 1
fi
echo "TEST PASSED"
return 0
}
shellcheck -a build init
# This helps to really pull the latest (without this, any old one from previous builds is used; at least with podmanm)
${PODMAN_OR_DOCKER} pull debian:latest
${PODMAN_OR_DOCKER} pull fedora:latest
${PODMAN_OR_DOCKER} build -f Dockerfile-Fedora -t cloudshell-fedora .
test_container "cloudshell-fedora"
${PODMAN_OR_DOCKER} build -f Dockerfile-Debian -t cloudshell-debian .
test_container "cloudshell-debian"