Vagrantfile

The syntax of vagrant file is not like others, its format does not like JSON/XML/TOML etc. Instead, it likes a script (ruby).

Vagrant.configure("2) do |config|    # Indicates the configuration version, there are different configuration file version.
    # config.xxx.yyy is the actual config params, xxx is the namespace and yyy is the params

    # The base image of the vagrant
    config.vm.box = "ubuntu/xenial64"

    # Set Ture for checking if box update is available in `vagrant up`, passive download, only show hint
    config.vm.box_check_update = False    

    # Configure the hostname
    config.vm.hostname = "ubuntu-test"

	# For network configuration
	# Port forwarding, 0.0.0.0:8080 -> guest:80
	config.vm.network "forwarded_port", guest: 80, host: 8080
	# Port forwarding, 127.0.0.1:8080 -> guest:80
	config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"	
	# assign private network IP, range: 192.168.0.0 ~ 192.168.255.255
	config.vm.network "private_network", ip: "192.168.33.10"
	# config.vm.network "private_network", type: "dhcp"
	config.vm.network "public_network"		# Network bridge

    # Shared folder between (host,guest)
    config.vm.synced_folder "../data", "/vagrant_data"

    # provider configuration
    # config.vm.provision :shell, path: "bootstrap.sh"
    config.vm.provider "virtualbox" do |vb|
        #vb.gui = true            # enable GUI or not
        vb.cpus = "2"            # Number of CPU
        vb.memory = "1024"        # Memory allocated, MB
    end

    # Used for build the environment before ready to use ^(1)
    # The following session will not be executed unless 
    # --provision is added
    # Use `vagrant provision`
    config.vm.provision "file", source: "~/.gitconfig", destination: ".gitconfig"
    config.vm.provision "shell", inline: <<-SHELL
        apt-get update
        apt-get install -y apache2
    SHELL

(1) What is Provision 伺服器服務開通(Server provisioning)是指:以合適的系統、數據和軟體來準備一個伺服器,並使其可用於網絡操作的一系列動作。開通一個伺服器的典型任務是:從一個可用伺服器的池裡面選擇一個伺服器,載入相應的軟體(作業系統、設備驅動、中間件和應用程式),適當地對系統和軟體進行定製化和配置,從而為這個伺服器創建或改變一個引導映像(boot image),並隨後更改其參數,例如網際協議(IP)地址、網際協議網關,以找到相關的網絡和存儲資源(某些時候被獨立分出為資源開通)來審計該系統。通過審計此系統,確保只有有限的漏洞並遵從開放式漏洞和評價語言(Open Vulnerability and Assessment Language,簡稱OVAL),保證承諾,或安裝補丁。在這些動作後,重啟系統並載入新軟體。這使得系統做好了運營的準備。

i.e. provisioning 是機器「第一次」被建立起來時或要加入服務前必須進行的工作

Last updated

Was this helpful?