blob: 2c60e5dfac05e8128a1006590c594d680420c9dd [file] [log] [blame]
Leopold Schabeldca59d92021-04-01 19:02:53 +02001#!/usr/bin/env bash
Leopold Schabel2983d722019-10-23 12:16:42 +02002set -euo pipefail
3
4# Our local user needs write access to /dev/kvm (best accomplished by
5# adding your user to the kvm group).
6if ! touch /dev/kvm; then
7 echo "Cannot write to /dev/kvm - please verify permissions."
8 exit 1
9fi
10
11# The KVM module needs to be loaded, since our container is unprivileged
12# and won't be able to do it itself.
13if ! [[ -d /sys/module/kvm ]]; then
14 echo "kvm module not loaded - please modprobe kvm"
15 exit 1
16fi
17
18# Rebuild base image
Serge Bazanskifebf0b02021-01-07 16:34:28 +010019podman build -t monogon-builder build
Leopold Schabel2983d722019-10-23 12:16:42 +020020
Leopold Schabel052af2d2019-11-06 02:21:53 +000021# Keep this in sync with ci.sh:
22
Serge Bazanskifebf0b02021-01-07 16:34:28 +010023podman pod create --name monogon
Hendrik Hofstadt3e6018f2019-10-28 21:29:42 +010024
Leopold Schabel8b9c0552019-11-15 14:07:45 +010025# Mount bazel root to identical paths inside and outside the container.
26# This caches build state even if the container is destroyed, and
27BAZEL_ROOT=${HOME}/.cache/bazel-nxt
Leopold Schabel8b9c0552019-11-15 14:07:45 +010028mkdir -p ${BAZEL_ROOT}
29
Leopold Schabel399fe832019-11-15 21:15:30 +010030# The Bazel plugin injects a Bazel repository into the sync command line,
31# We need to copy the aspect repository and apply a custom patch.
Leopold Schabel58ec09e2021-04-01 18:34:19 +020032
33# TODO(leo): the IntelliJ path changed to ~/.config on new setups, we should look for that as well
34
Leopold Schabel8cc81f62020-01-06 17:04:54 +010035IJ_HOME=$(echo ${HOME}/.IntelliJIdea* | tr ' ' '\n' | sort | tail -n 1)
36ASPECT_ORIG=${IJ_HOME}/config/plugins/ijwb/aspect
Leopold Schabel399fe832019-11-15 21:15:30 +010037ASPECT_PATH=${BAZEL_ROOT}/ijwb_aspect
Leopold Schabel58ec09e2021-04-01 18:34:19 +020038
39if [[ -d "$IJ_HOME" ]]; then
40 echo "IntelliJ found, copying aspect file to Bazel root"
41 rm -rf "$ASPECT_PATH"
42 cp -r "$ASPECT_ORIG" "$ASPECT_PATH"
43 patch -d "$ASPECT_PATH" -p1 < scripts/patches/bazel_intellij_aspect_filter.patch
44fi
Leopold Schabel399fe832019-11-15 21:15:30 +010045
Leopold Schabel2983d722019-10-23 12:16:42 +020046podman run -it -d \
Leopold Schabel58ec09e2021-04-01 18:34:19 +020047 -v $(pwd):$(pwd):z \
Leopold Schabel8b9c0552019-11-15 14:07:45 +010048 -w $(pwd) \
49 --volume=${BAZEL_ROOT}:${BAZEL_ROOT} \
Leopold Schabel2983d722019-10-23 12:16:42 +020050 --device /dev/kvm \
Leopold Schabel7afd3902019-10-23 12:16:57 +020051 --privileged \
Serge Bazanskifebf0b02021-01-07 16:34:28 +010052 --pod monogon \
53 --name=monogon-dev \
Leopold Schabel980d0032020-06-03 14:44:49 +020054 --net=host \
Serge Bazanskifebf0b02021-01-07 16:34:28 +010055 monogon-builder