]> git.localhorst.tv Git - blank.git/blob - scripts/docker/exec.bash
move env inside docker container
[blank.git] / scripts / docker / exec.bash
1 #!/bin/bash
2
3 # execute from project root
4 # environment varables:
5 #   IMAGE:    name of the docker image to use
6 #   TARGETS:  targets to pass to `make` inside the container
7 #   PASS_ENV: names of environment variables to import into
8 #             the container during build
9
10 IMAGE="${IMAGE:-archlinux-build}"
11
12 image_name="localhorsttv/${IMAGE}"
13 image_path="scripts/docker/${IMAGE//:/-}"
14
15 build_cmd="cd /repo && make -j\$(nproc) $TARGETS"
16
17 local_conf=""
18
19 if [[ "$TARGETS" == *codecov* ]]; then
20         local_conf="$local_conf $(bash <(curl -s https://codecov.io/env))"
21 fi
22
23 if [ -e "${image_path}/env" ]; then
24         local_conf="$local_conf --env-file ${image_path}/env"
25 fi
26
27 # copy DISPLAY if set
28 if [ "$DISPLAY" != "" ]; then
29         local_conf="$local_conf -e DISPLAY=$DISPLAY"
30 fi
31
32 # copy XDG_RUNTIME_DIR if set
33 if [ "$XDG_RUNTIME_DIR" != "" ]; then
34         local_conf="$local_conf -e XDG_RUNTIME_DIR='$XDG_RUNTIME_DIR'"
35 fi
36
37 docker build -t "${image_name}" --pull=true "${image_path}"
38 docker run -v "$PWD":/repo ${local_conf} "${image_name}" /bin/bash -c "env && ${build_cmd}"