blob: f98c296fcd98dde07739b7b997dad373d97990c9 [file] [log] [blame]
Leopold Schabel2983d722019-10-23 12:16:42 +02001#!/bin/bash
2set -euo pipefail
3
Serge Bazanskifebf0b02021-01-07 16:34:28 +01004# 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 Schabel2983d722019-10-23 12:16:42 +02008# Our local user needs write access to /dev/kvm (best accomplished by
9# adding your user to the kvm group).
10if ! touch /dev/kvm; then
11 echo "Cannot write to /dev/kvm - please verify permissions."
12 exit 1
13fi
14
15# The KVM module needs to be loaded, since our container is unprivileged
16# and won't be able to do it itself.
17if ! [[ -d /sys/module/kvm ]]; then
18 echo "kvm module not loaded - please modprobe kvm"
19 exit 1
20fi
21
22# Rebuild base image
Serge Bazanskifebf0b02021-01-07 16:34:28 +010023podman build -t monogon-builder build
Leopold Schabel2983d722019-10-23 12:16:42 +020024
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 Schabel5ed291e2019-11-14 19:09:24 +010027chcon -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 Schabel2983d722019-10-23 12:16:42 +020031 .arcconfig .idea .git
32
Leopold Schabel052af2d2019-11-06 02:21:53 +000033# Keep this in sync with ci.sh:
34
Serge Bazanskifebf0b02021-01-07 16:34:28 +010035podman pod create --name monogon
Hendrik Hofstadt3e6018f2019-10-28 21:29:42 +010036
Leopold Schabel8b9c0552019-11-15 14:07:45 +010037# Mount bazel root to identical paths inside and outside the container.
38# This caches build state even if the container is destroyed, and
39BAZEL_ROOT=${HOME}/.cache/bazel-nxt
Leopold Schabel8b9c0552019-11-15 14:07:45 +010040mkdir -p ${BAZEL_ROOT}
41
Leopold Schabel399fe832019-11-15 21:15:30 +010042# 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 Schabel8cc81f62020-01-06 17:04:54 +010044IJ_HOME=$(echo ${HOME}/.IntelliJIdea* | tr ' ' '\n' | sort | tail -n 1)
45ASPECT_ORIG=${IJ_HOME}/config/plugins/ijwb/aspect
Leopold Schabel399fe832019-11-15 21:15:30 +010046
47ASPECT_PATH=${BAZEL_ROOT}/ijwb_aspect
48rm -rf "$ASPECT_PATH"
49cp -r "$ASPECT_ORIG" "$ASPECT_PATH"
50patch -d "$ASPECT_PATH" -p1 < scripts/patches/bazel_intellij_aspect_filter.patch
51
Leopold Schabel2983d722019-10-23 12:16:42 +020052podman run -it -d \
Leopold Schabel8b9c0552019-11-15 14:07:45 +010053 -v $(pwd):$(pwd) \
54 -w $(pwd) \
55 --volume=${BAZEL_ROOT}:${BAZEL_ROOT} \
Leopold Schabel2983d722019-10-23 12:16:42 +020056 --device /dev/kvm \
Leopold Schabel7afd3902019-10-23 12:16:57 +020057 --privileged \
Serge Bazanskifebf0b02021-01-07 16:34:28 +010058 --pod monogon \
59 --name=monogon-dev \
Leopold Schabel980d0032020-06-03 14:44:49 +020060 --net=host \
Serge Bazanskifebf0b02021-01-07 16:34:28 +010061 monogon-builder