Leopold Schabel | 2983d72 | 2019-10-23 12:16:42 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | set -euo pipefail |
| 3 | |
Serge Bazanski | febf0b0 | 2021-01-07 16:34:28 +0100 | [diff] [blame^] | 4 | # TODO(by 2021/02/01): remove this (backward compatibility for dev envs) |
| 5 | ! podman pod stop nexantic |
| 6 | ! podman pod rm nexantic --force |
| 7 | |
Leopold Schabel | 2983d72 | 2019-10-23 12:16:42 +0200 | [diff] [blame] | 8 | # Our local user needs write access to /dev/kvm (best accomplished by |
| 9 | # adding your user to the kvm group). |
| 10 | if ! touch /dev/kvm; then |
| 11 | echo "Cannot write to /dev/kvm - please verify permissions." |
| 12 | exit 1 |
| 13 | fi |
| 14 | |
| 15 | # The KVM module needs to be loaded, since our container is unprivileged |
| 16 | # and won't be able to do it itself. |
| 17 | if ! [[ -d /sys/module/kvm ]]; then |
| 18 | echo "kvm module not loaded - please modprobe kvm" |
| 19 | exit 1 |
| 20 | fi |
| 21 | |
| 22 | # Rebuild base image |
Serge Bazanski | febf0b0 | 2021-01-07 16:34:28 +0100 | [diff] [blame^] | 23 | podman build -t monogon-builder build |
Leopold Schabel | 2983d72 | 2019-10-23 12:16:42 +0200 | [diff] [blame] | 24 | |
| 25 | # Set up SELinux contexts to prevent the container from writing to |
| 26 | # files that would allow for easy breakouts via tools ran on the host. |
Leopold Schabel | 5ed291e | 2019-11-14 19:09:24 +0100 | [diff] [blame] | 27 | chcon -Rh system_u:object_r:container_file_t:s0 . |
| 28 | |
| 29 | # Ignore errors - these might already be masked, like when synchronizing the source. |
| 30 | ! chcon -Rh unconfined_u:object_r:user_home_t:s0 \ |
Leopold Schabel | 2983d72 | 2019-10-23 12:16:42 +0200 | [diff] [blame] | 31 | .arcconfig .idea .git |
| 32 | |
Leopold Schabel | 052af2d | 2019-11-06 02:21:53 +0000 | [diff] [blame] | 33 | # Keep this in sync with ci.sh: |
| 34 | |
Serge Bazanski | febf0b0 | 2021-01-07 16:34:28 +0100 | [diff] [blame^] | 35 | podman pod create --name monogon |
Hendrik Hofstadt | 3e6018f | 2019-10-28 21:29:42 +0100 | [diff] [blame] | 36 | |
Leopold Schabel | 8b9c055 | 2019-11-15 14:07:45 +0100 | [diff] [blame] | 37 | # Mount bazel root to identical paths inside and outside the container. |
| 38 | # This caches build state even if the container is destroyed, and |
| 39 | BAZEL_ROOT=${HOME}/.cache/bazel-nxt |
Leopold Schabel | 8b9c055 | 2019-11-15 14:07:45 +0100 | [diff] [blame] | 40 | mkdir -p ${BAZEL_ROOT} |
| 41 | |
Leopold Schabel | 399fe83 | 2019-11-15 21:15:30 +0100 | [diff] [blame] | 42 | # The Bazel plugin injects a Bazel repository into the sync command line, |
| 43 | # We need to copy the aspect repository and apply a custom patch. |
Leopold Schabel | 8cc81f6 | 2020-01-06 17:04:54 +0100 | [diff] [blame] | 44 | IJ_HOME=$(echo ${HOME}/.IntelliJIdea* | tr ' ' '\n' | sort | tail -n 1) |
| 45 | ASPECT_ORIG=${IJ_HOME}/config/plugins/ijwb/aspect |
Leopold Schabel | 399fe83 | 2019-11-15 21:15:30 +0100 | [diff] [blame] | 46 | |
| 47 | ASPECT_PATH=${BAZEL_ROOT}/ijwb_aspect |
| 48 | rm -rf "$ASPECT_PATH" |
| 49 | cp -r "$ASPECT_ORIG" "$ASPECT_PATH" |
| 50 | patch -d "$ASPECT_PATH" -p1 < scripts/patches/bazel_intellij_aspect_filter.patch |
| 51 | |
Leopold Schabel | 2983d72 | 2019-10-23 12:16:42 +0200 | [diff] [blame] | 52 | podman run -it -d \ |
Leopold Schabel | 8b9c055 | 2019-11-15 14:07:45 +0100 | [diff] [blame] | 53 | -v $(pwd):$(pwd) \ |
| 54 | -w $(pwd) \ |
| 55 | --volume=${BAZEL_ROOT}:${BAZEL_ROOT} \ |
Leopold Schabel | 2983d72 | 2019-10-23 12:16:42 +0200 | [diff] [blame] | 56 | --device /dev/kvm \ |
Leopold Schabel | 7afd390 | 2019-10-23 12:16:57 +0200 | [diff] [blame] | 57 | --privileged \ |
Serge Bazanski | febf0b0 | 2021-01-07 16:34:28 +0100 | [diff] [blame^] | 58 | --pod monogon \ |
| 59 | --name=monogon-dev \ |
Leopold Schabel | 980d003 | 2020-06-03 14:44:49 +0200 | [diff] [blame] | 60 | --net=host \ |
Serge Bazanski | febf0b0 | 2021-01-07 16:34:28 +0100 | [diff] [blame^] | 61 | monogon-builder |