aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/dev.sh
blob: 490021f23499e9a3a1c008171fdd56c113fd53d0 (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
#!/usr/bin/env sh

# Sets up a development environment and runs a shell in a docker container.
# Usage: dev.sh [--build [--clean]] [ash_args ...]

if [ "$1" = "--build" ]; then
    shift
    printf "Building pythondiscord/snekbox-venv:dev..."

    docker build \
        -t pythondiscord/snekbox-venv:dev \
        -f docker/venv.Dockerfile \
        --build-arg DEV=1 \
        -q \
        . \
        >/dev/null \
    && printf " done!\n" || exit "$?"

    if [ "$1" = "--clean" ]; then
        shift
        dangling_imgs=$(docker images -f "dangling=true" -q)

        if [ -n "${dangling_imgs}" ]; then
            printf "Removing dangling images..."

            docker rmi $dangling_imgs >/dev/null \
            && printf " done!\n" || exit "$?"
        fi
    fi
fi

docker run \
    -it \
    --rm \
    --privileged \
    --network host \
    -h pdsnk-dev \
    -e PYTHONDONTWRITEBYTECODE=1 \
    -e PIPENV_PIPFILE="/snekbox/Pipfile" \
    -e ENV="/snekbox-local/scripts/.profile" \
    -v "${PWD}":/snekbox-local \
    -w "/snekbox-local" \
    --entrypoint /bin/ash \
    pythondiscord/snekbox-venv:dev \
    "$@"