@@ -22,17 +22,17 @@ CONTAINER_TAG=`cat ${ROOT}/bin/.container-tag`
2222# An apptainer/singularity container. All commands on the host (using ./do or ./bin/*) are run in the context of an Apptainer/Singularity image.
2323#
2424#
25- # ALL THREE CONTAINERS ARE IDENTICAL. Which one you use is a preference of your setup and installed
25+ # ALL THREE CONTAINERS ARE (in theory) IDENTICAL. Which one you use is a preference of your setup and installed
2626# software.
2727
2828
2929# get the container type
3030#
3131# use, in priority order:
32- # 1. devcontainer, if DEVCONTAINER_ENV is set in the enviornment
32+ # 1. devcontainer, if DEVCONTAINER_ENV is set in the environment
3333# 2. the type stored in .container-type
34- # 3. Docker, if DOCKER is set in the enviornment
35- # 4. Singularity, if SINGULARITY is set in the enviornment
34+ # 3. Docker, if DOCKER is set in the environment
35+ # 4. Singularity, if SINGULARITY is set in the environment
3636# 5. The choice made by the user, which will be cached in .container-type
3737if [ -v DEVCONTAINER_ENV ]; then
3838CONTAINER_TYPE=devcontainer
5656fi
5757
5858if [ " ${CONTAINER_TYPE} " != " docker" -a " ${CONTAINER_TYPE} " != " singularity" -a " ${CONTAINER_TYPE} " != " devcontainer" ]; then
59- echo " BAD CONTAINER TYPE: ${CONTAINER_TYPE} "
59+ echo " BAD CONTAINER TYPE: ${CONTAINER_TYPE} " 1>&2
6060 exit 1
6161fi
6262
@@ -72,19 +72,25 @@ print_env() {
7272 elif [ " ${CONTAINER_TYPE} " == " devcontainer" ]; then
7373 echo " Using devcontainer environment"
7474 else
75- echo " Unknown container type of ${CONTAINER_TYPE} "
75+ echo " Unknown container type of ${CONTAINER_TYPE} " 1>&2
7676 exit 1
7777 fi
7878}
7979
80+ print_env
81+
8082if [ -v GITHUB_ACTIONS ]; then
81- echo " ACTIONS "
83+ echo " Running in a GitHub Action "
8284 CONTAINER_PATH=${ROOT} /.singularity/image.sif
8385 HOME_PATH=${GITHUB_WORKSPACE}
8486 HOME_OPT=" --home ${ROOT} /.home"
8587 SINGULARITY_CACHE=--disable-cache
88+
89+ # needed to get singularity working on Ubuntu 24.04
90+ # see https://github.com/lima-vm/lima/issues/2319
91+ sudo /bin/bash -c " echo \" kernel.apparmor_restrict_unprivileged_userns = 0\" >/etc/sysctl.d/99-userns.conf"
92+ sudo sysctl --system
8693elif [ " ${CONTAINER_TYPE} " == " docker" ]; then
87- print_env
8894 if ! docker images riscvintl/udb:${CONTAINER_TAG} | grep -q udb ; then
8995 # TODO: pull the image if it can be found
9096 echo " Building Docker image..."
@@ -97,7 +103,6 @@ elif [ "${CONTAINER_TYPE}" == "docker" ]; then
97103 fi
98104 RUN=" ${DOCKER_BASE} "
99105elif [ " ${CONTAINER_TYPE} " == " singularity" ]; then
100- print_env
101106 CONTAINER_PATH=${ROOT} /.singularity/image-$CONTAINER_TAG .sif
102107 HOME_PATH=${HOME}
103108 HOME_OPT=" --bind ${ROOT} /.home:${HOME_PATH} "
@@ -110,9 +115,9 @@ elif [ "${CONTAINER_TYPE}" == "singularity" ]; then
110115 singularity pull ${SINGULARITY_CACHE} ${CONTAINER_PATH} oras://docker.io/riscvintl/spec-generator:$CONTAINER_TAG
111116 fi
112117elif [ " ${CONTAINER_TYPE} " == " devcontainer" ]; then
113- print_env
118+ HOME_PATH= ${HOME}
114119else
115- echo " Unknown container type of ${CONTAINER_TYPE} "
120+ echo " Bad container type: ${CONTAINER_TYPE} " 1>&2
116121 exit 1
117122fi
118123
@@ -122,12 +127,15 @@ if [ -f $ROOT/.git ]; then
122127 HOME_OPT=" ${HOME_OPT} --bind ${GIT_PATH} :${GIT_PATH} "
123128fi
124129
125- if [ -v DEVCONTAINER_ENV ]; then
130+ if [ " ${CONTAINER_TYPE} " == " devcontainer " ]; then
126131 RUN=" "
127132elif [ " ${CONTAINER_TYPE} " == " docker" ]; then
128133 RUN=" ${DOCKER_BASE} "
129- else
134+ elif [ " ${CONTAINER_TYPE} " == " singularity " ] ; then
130135 RUN=" singularity run ${HOME_OPT} ${CONTAINER_PATH} "
136+ else
137+ echo " Bad container type: ${CONTAINER_TYPE} " 1>&2
138+ exit 1
131139fi
132140
133141if [ ! -d $ROOT /.home ]; then
@@ -175,7 +183,7 @@ if [ ! -d ${ROOT}/node_modules ]; then
175183 ${RUN} npm i
176184fi
177185
178- if [ -v DEVCONTAINER_ENV ]; then
186+ if [ " ${CONTAINER_TYPE} " == " devcontainer " ]; then
179187 BUNDLE=" bundle"
180188 RUBY=" bundle exec ruby"
181189 RAKE=" bundle exec rake"
@@ -195,7 +203,7 @@ elif [ "${CONTAINER_TYPE}" == "docker" ]; then
195203 PYTHON=" ${DOCKER_BASE} ${ROOT} /.home/.venv/bin/python3"
196204 PIP=" ${DOCKER_BASE} ${ROOT} /.home/.venv/bin/pip"
197205 BASH=" ${DOCKER_BASE} bash"
198- else
206+ elif [ " ${CONTAINER_TYPE} " == " singularity " ] ; then
199207 BUNDLE=" singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle"
200208 RUBY=" singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle exec ruby"
201209 RAKE=" singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle exec rake"
205213 PYTHON=" singularity run ${HOME_OPT} ${CONTAINER_PATH} ${ROOT} /.home/.venv/bin/python3"
206214 PIP=" singularity run ${HOME_OPT} ${CONTAINER_PATH} ${ROOT} /.home/.venv/bin/pip"
207215 BASH=" singularity run ${HOME_OPT} ${CONTAINER_PATH} bash"
216+ else
217+ echo " Bad container type: ${CONTAINER_TYPE} " 1>&2
218+ exit 1
208219fi
209220
210221if [ ! -f $ROOT /.git/hooks/pre-commit ]; then
0 commit comments