Skip to content

Commit

Permalink
Isolate node_modules inside development container/VM (e-valuation#1899)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardebeling authored and FSadrieh committed Jun 12, 2023
1 parent 61e97f7 commit 69d41ae
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ The easiest setup using [Vagrant](https://www.vagrantup.com) is shown here.
git config --global core.autocrlf input
```

* Symlink Privileges: Our setup script for the VM creates symlinks in the repository folder. This requires either [explicitly allowing your user account to create symlinks](https://superuser.com/a/105381) or simply running the commands in step 3 as administrator. Thus, we suggest doing step 3 in a Git Bash that was started using "Run as administrator". Generally, this is only required for the first time executing `vagrant up`.

3. Run the following commands on the command line to clone the repository, create the Vagrant VM and run the Django development server.
To use Docker, replace `vagrant up` with `vagrant up --provider docker && vagrant provision`.
```bash
Expand Down
3 changes: 3 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Vagrant.configure("2") do |config|
# Docker container really are supposed to be used differently. Hacky way to make it into a "VM".
d.cmd = ["tail", "-f", "/dev/null"]

# Required so we can use mount inside the VM -- see e.g. https://github.com/moby/moby/issues/16429
d.create_args = ["--cap-add=SYS_ADMIN", "--security-opt=apparmor:unconfined"]

# Workaround for no SSH server as long as https://github.com/hashicorp/vagrant/issues/8145 is still open
override.trigger.before :provision do |trigger|
trigger.ruby do |env, machine| system("vagrant docker-exec -it -- /evap/deployment/provision_vagrant_vm.sh") end
Expand Down
8 changes: 8 additions & 0 deletions deployment/provision_vagrant_vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ MOUNTPOINT="/evap"
USER="evap"
REPO_FOLDER="/opt/evap"
ENV_FOLDER="/home/$USER/venv"
NODE_MODULES_FOLDER="/home/$USER/node_modules"
EVAP_PYTHON=python3.8

# force apt to not ask, just do defaults.
Expand Down Expand Up @@ -101,8 +102,15 @@ wget https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh --no-verbos
# setup evap
cd "$MOUNTPOINT"
sudo -H -u $USER git submodule update --init

sudo -H -u $USER mkdir node_modules
sudo -H -u $USER mkdir ${NODE_MODULES_FOLDER}
sudo mount --bind ${NODE_MODULES_FOLDER} ${MOUNTPOINT}/node_modules
echo "sudo mount --bind ${NODE_MODULES_FOLDER} ${MOUNTPOINT}/node_modules" >> /home/$USER/.bashrc

sudo -H -u $USER bash -c "source /home/$USER/.nvm/nvm.sh; nvm install --no-progress node; npm ci"
echo "nvm use node" >> /home/$USER/.bashrc

sudo -H -u $USER $ENV_FOLDER/bin/python manage.py migrate --noinput
sudo -H -u $USER $ENV_FOLDER/bin/python manage.py collectstatic --noinput
sudo -H -u $USER $ENV_FOLDER/bin/python manage.py compilemessages --locale de
Expand Down

0 comments on commit 69d41ae

Please sign in to comment.