blob: 80f4581c2f50f53d9342902444b8dd639b5d5c95 [file] [log] [blame]
Leopold Schabel2983d722019-10-23 12:16:42 +02001#!/bin/bash
2set -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
19podman build -t smalltown-builder .
20
21# Set up SELinux contexts to prevent the container from writing to
22# files that would allow for easy breakouts via tools ran on the host.
23chcon -R system_u:object_r:container_file_t:s0 .
24chcon -R unconfined_u:object_r:user_home_t:s0 \
25 .arcconfig .idea .git
26
Leopold Schabel3ea70702019-10-23 16:40:06 +020027# TODO(leo): mount .cache/bazel on a volume (waiting for podman issue to be fixed)
28# https://github.com/containers/libpod/issues/4318
Leopold Schabel2983d722019-10-23 12:16:42 +020029podman run -it -d \
30 -v $(pwd):/work \
Leopold Schabel52804a12019-10-24 02:17:13 +020031 -v smalltown-gopath:/root/go/pkg \
Leopold Schabel3ea70702019-10-23 16:40:06 +020032 -v smalltown-gobuildcache:/root/.cache/go-build \
33 -v smalltown-bazelcache:/root/.cache/bazel/_bazel_root/cache \
Leopold Schabel2983d722019-10-23 12:16:42 +020034 --tmpfs=/root/.cache/bazel:exec \
35 --device /dev/kvm \
Leopold Schabel7afd3902019-10-23 12:16:57 +020036 --privileged \
Leopold Schabel52804a12019-10-24 02:17:13 +020037 --userns=keep-id \
Leopold Schabel2983d722019-10-23 12:16:42 +020038 --name=smalltown-dev \
39 smalltown-builder