@@ -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
5555 done
5656fi
5757
58- if [ " ${CONTAINER_TYPE} " != " docker" -a " ${CONTAINER_TYPE} " != " singularity" ]; then
58+ if [ " ${CONTAINER_TYPE} " != " docker" -a " ${CONTAINER_TYPE} " != " singularity" -a " ${CONTAINER_TYPE} " != " devcontainer " ]; then
5959 echo " BAD CONTAINER TYPE: ${CONTAINER_TYPE} "
6060fi
6161
6262if [ ! -f ${ROOT} /.container-type ]; then
6363 echo ${CONTAINER_TYPE} > ${ROOT} /.container-type
6464fi
6565
66- print_env () {
67- if [ " ${CONTAINER_TYPE} " == " docker" ]; then
68- echo " Using Docker environment"
69- else
70- echo " Using Singularity environment"
71- fi
72- }
66+ echo " Using ${CONTAINER_TYPE} environment"
7367
7468if [ -v GITHUB_ACTIONS ]; then
75- echo " ACTIONS "
69+ echo " Running in a GitHub Action "
7670 CONTAINER_PATH=${ROOT} /.singularity/image.sif
7771 HOME_PATH=${GITHUB_WORKSPACE}
7872 HOME_OPT=" --home ${ROOT} /.home"
7973 SINGULARITY_CACHE=--disable-cache
74+
75+ # needed to get singularity working on Ubuntu 24.04
76+ # see https://github.com/lima-vm/lima/issues/2319
77+ sudo /bin/bash -c " echo \" kernel.apparmor_restrict_unprivileged_userns = 0\" >/etc/sysctl.d/99-userns.conf"
78+ sudo sysctl --system
8079elif [ " ${CONTAINER_TYPE} " == " docker" ]; then
81- print_env
8280 if ! docker images riscvintl/udb:${CONTAINER_TAG} | grep -q udb ; then
8381 # TODO: pull the image if it can be found
8482 echo " Building Docker image..."
@@ -90,8 +88,7 @@ elif [ "${CONTAINER_TYPE}" == "docker" ]; then
9088 DOCKER_BASE=" docker run -v $( ROOT) :$( ROOT) -w $( ROOT) riscvintl/udb:${CONTAINER_TAG} "
9189 fi
9290 RUN=" ${DOCKER_BASE} "
93- else
94- print_env
91+ elif [ " ${CONTAINER_TYPE} " == " singularity" ]; then
9592 CONTAINER_PATH=${ROOT} /.singularity/image-$CONTAINER_TAG .sif
9693 HOME_PATH=${HOME}
9794 HOME_OPT=" --bind ${ROOT} /.home:${HOME_PATH} "
@@ -103,6 +100,11 @@ else
103100 fi
104101 singularity pull ${SINGULARITY_CACHE} ${CONTAINER_PATH} oras://docker.io/riscvintl/spec-generator:$CONTAINER_TAG
105102 fi
103+ elif [ " ${CONTAINER_TYPE} " == " devcontainer" ]; then
104+ HOME_PATH=${HOME}
105+ else
106+ echo " Bad container type: ${CONTAINER_TYPE} " 1>&2
107+ exit 1
106108fi
107109
108110if [ -f $ROOT /.git ]; then
@@ -111,12 +113,15 @@ if [ -f $ROOT/.git ]; then
111113 HOME_OPT=" ${HOME_OPT} --bind ${GIT_PATH} :${GIT_PATH} "
112114fi
113115
114- if [ -v DEVCONTAINER_ENV ]; then
116+ if [ " ${CONTAINER_TYPE} " == " devcontainer " ]; then
115117 RUN=" "
116118elif [ " ${CONTAINER_TYPE} " == " docker" ]; then
117119 RUN=" ${DOCKER_BASE} "
118- else
120+ elif [ " ${CONTAINER_TYPE} " == " singularity " ] ; then
119121 RUN=" singularity run ${HOME_OPT} ${CONTAINER_PATH} "
122+ else
123+ echo " Bad container type: ${CONTAINER_TYPE} " 1>&2
124+ exit 1
120125fi
121126
122127if [ ! -d $ROOT /.home ]; then
@@ -164,7 +169,7 @@ if [ ! -d ${ROOT}/node_modules ]; then
164169 ${RUN} npm i
165170fi
166171
167- if [ -v DEVCONTAINER_ENV ]; then
172+ if [ " ${CONTAINER_TYPE} " == " devcontainer " ]; then
168173 BUNDLE=" bundle"
169174 RUBY=" bundle exec ruby"
170175 RAKE=" bundle exec rake"
@@ -184,7 +189,7 @@ elif [ "${CONTAINER_TYPE}" == "docker" ]; then
184189 PYTHON=" ${DOCKER_BASE} ${ROOT} /.home/.venv/bin/python3"
185190 PIP=" ${DOCKER_BASE} ${ROOT} /.home/.venv/bin/pip"
186191 BASH=" ${DOCKER_BASE} bash"
187- else
192+ elif [ " ${CONTAINER_TYPE} " == " singularity " ] ; then
188193 BUNDLE=" singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle"
189194 RUBY=" singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle exec ruby"
190195 RAKE=" singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle exec rake"
194199 PYTHON=" singularity run ${HOME_OPT} ${CONTAINER_PATH} ${ROOT} /.home/.venv/bin/python3"
195200 PIP=" singularity run ${HOME_OPT} ${CONTAINER_PATH} ${ROOT} /.home/.venv/bin/pip"
196201 BASH=" singularity run ${HOME_OPT} ${CONTAINER_PATH} bash"
202+ else
203+ echo " Bad container type: ${CONTAINER_TYPE} " 1>&2
204+ exit 1
197205fi
198206
199207if [ ! -f $ROOT /.git/hooks/pre-commit ]; then
0 commit comments