aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test/linuxserver/test.sh
blob: 83d6a8ce4419f796aeefbdad0b62ef96915debe1 (plain) (blame)
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
#!/usr/bin/env bash

set -o errexit -o nounset -o pipefail
shopt -s inherit_errexit lastpipe

script_dir="$( dirname -- "${BASH_SOURCE[0]}" )"
script_dir="$( cd -- "$script_dir" && pwd )"
readonly script_dir

script_dir_ownership="$( stat -c '%u:%g' -- "$script_dir" )"
readonly script_dir_ownership

readonly server=10.13.13.1

fix_permissions() {
    chown -R -- "$script_dir_ownership" "$script_dir/example_config"
}

docker_build() {
    docker-compose build --force-rm --progress plain --pull "$@"
}

build_services() {
    echo ------------------------------------------------------------------
    echo Pull third-party images
    echo ------------------------------------------------------------------
    docker-compose pull wg api

    echo ------------------------------------------------------------------
    echo Build wg-api-web
    echo ------------------------------------------------------------------
    docker_build web

    echo ------------------------------------------------------------------
    echo Build peer1
    echo ------------------------------------------------------------------
    docker_build peer1

    echo ------------------------------------------------------------------
    echo docker-compose up
    echo ------------------------------------------------------------------
    docker-compose up -d
}

ping_server() {
    echo ------------------------------------------------------------------
    echo Pinging the server
    echo ------------------------------------------------------------------
    ping -c 5 -W 3 "$server"
}

cleanup() {
    echo ------------------------------------------------------------------
    echo Cleaning up
    echo ------------------------------------------------------------------
    docker-compose down -v --remove-orphans
    fix_permissions
}

main() {
    cd -- "$script_dir"
    trap cleanup EXIT

    fix_permissions
    if ping_server; then
        echo "Should've failed to ping the server!" >&2
        exit 1
    fi
    build_services
    sleep 3
    ping_server
    "$script_dir/../check_web.sh"
}

main