Skip to content

Commit 394172b

Browse files
authored
[Feature:Developer] Allow customization of VM resources (#11922)
### Why is this Change Important & Necessary? <!-- Include any GitHub issue that is fixed/closed using "Fixes #<number>" or "Closes #<number>" syntax. Alternately write "Partially addresses #<number>" or "Related to #<number>" as appropriate. --> Currently whenever `vagrant up` is run the VM is created with 2G of ram and 2 cpus. ### What is the New Behavior? <!-- Include before & after screenshots/videos if the user interface has changed. --> This adds two new environment variables that can be used to configure the values for the vm. An example of both of them used is `VM_MEMORY=4096 VM_CPUS=4 vagrant up` ### What steps should a reviewer take to reproduce or test the bug or new feature? 1. Run `vagrant up` and observe the memory and cpus allocated to your vm. 2. Run `vagrant halt && vagrant up` with `VM_CPUS` and/or `VM_MEMORY` set and verify the correct value is used. ### Automated Testing & Documentation <!-- Is this feature sufficiently tested by unit tests and end-to-end tests? If this PR does not add/update the necessary automated tests, write a new GitHub issue and link it below. Is this feature sufficiently documented on submitty.org? Link related PRs or new GitHub issue to update documentation. --> documentation added in PR: Submitty/submitty.github.io#695 ### Other information <!-- Is this a breaking change? Does this PR include migrations to update existing installations? Are there security concerns with this PR? -->
1 parent aa1329f commit 394172b

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

Vagrantfile

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
# NO_SUBMISSIONS=1 vagrant up
88
# or
99
# EXTRA=rpi vagrant up
10+
# or
11+
# VM_MEMORY=4096 VM_CPUS=4 vagrant up
1012
#
1113
#
1214
# If you want to override the default image used for the virtual machines, you can set the
@@ -25,6 +27,9 @@
2527
#
2628
# If you don't want any submissions to be automatically generated for the courses created
2729
# by vagrant, you'll want to specify NO_SUBMISSIONS flag.
30+
#
31+
# You can also customize VM resources using environment variables:
32+
# VM_MEMORY=4096 VM_CPUS=4 vagrant up
2833

2934
# Don't buffer output.
3035
$stdout.sync = true
@@ -34,6 +39,10 @@ require 'json'
3439

3540
ON_CI = !ENV.fetch('CI', '').empty?
3641

42+
# VM resource configuration
43+
VM_MEMORY = ENV.fetch('VM_MEMORY', ON_CI ? '1024' : '2048').to_i
44+
VM_CPUS = ENV.fetch('VM_CPUS', ON_CI ? '1' : '2').to_i
45+
3746
def gen_script(machine_name, worker: false, base: false)
3847
no_submissions = !ENV.fetch('NO_SUBMISSIONS', '').empty?
3948
reinstall = ENV.has_key?('VAGRANT_BOX') || base
@@ -197,8 +206,8 @@ Vagrant.configure(2) do |config|
197206

198207
# We limit resources when running on CI to avoid resource exhaustion and it isn't used for grading stuff or
199208
# other things we do in dev.
200-
vb.memory = ON_CI ? 1024 : 2048
201-
vb.cpus = ON_CI ? 1 : 2
209+
vb.memory = VM_MEMORY
210+
vb.cpus = VM_CPUS
202211

203212
# When you put your computer (while running the VM) to sleep, then resume work some time later the VM will be out
204213
# of sync timewise with the host for however long the host was asleep. Of course, the VM by default will
@@ -243,8 +252,8 @@ Vagrant.configure(2) do |config|
243252
end
244253
end
245254

246-
prl.memory = 2048
247-
prl.cpus = 2
255+
prl.memory = VM_MEMORY
256+
prl.cpus = VM_CPUS
248257

249258
mount_folders(override, ["share", "nosuid"])
250259
end
@@ -255,8 +264,8 @@ Vagrant.configure(2) do |config|
255264
override.vm.box = base_boxes[:arm_bento]
256265
end
257266
end
258-
vmware.vmx["memsize"] = "2048"
259-
vmware.vmx["numvcpus"] = "2"
267+
vmware.vmx["memsize"] = VM_MEMORY.to_s
268+
vmware.vmx["numvcpus"] = VM_CPUS.to_s
260269

261270
mount_folders(override, [])
262271
end
@@ -268,8 +277,8 @@ Vagrant.configure(2) do |config|
268277

269278
libvirt.qemu_use_session = true
270279

271-
libvirt.memory = 2048
272-
libvirt.cpus = 2
280+
libvirt.memory = VM_MEMORY
281+
libvirt.cpus = VM_CPUS
273282

274283
libvirt.forward_ssh_port = true
275284

@@ -283,8 +292,8 @@ Vagrant.configure(2) do |config|
283292
end
284293
end
285294

286-
qe.memory = "2G"
287-
qe.smp = 2
295+
qe.memory = "#{VM_MEMORY}M"
296+
qe.smp = VM_CPUS
288297
end
289298

290299
config.vm.provision :shell, :inline => " sudo timedatectl set-timezone America/New_York", run: "once"

0 commit comments

Comments
 (0)