diff --git a/vm/Readme.md b/vm/Readme.md deleted file mode 100644 index 316b3c33..00000000 --- a/vm/Readme.md +++ /dev/null @@ -1,37 +0,0 @@ -## ERPNext VM Builder - - -### Steps to build a VM Image - -* `python build.py` builds a new Production VM, a Dev VM and a Dev Vagrant Box - - -### Requirements - -* Bench should be installed -* Ansible should be installed - - -### How it works - -Apart from the above the rest is handled by bench: - -* Install prerequisites if not already installed - - virtualbox - - packer -* Cleanup - - Clean the required directories -* Build the VM using packer - - Packer downloads the mentioned Ubuntu iso, boots a virtual machine and preceeds the preseed.cfg file into it in order to setup a clean Ubuntu OS - - Then packer uses ssh to enter the virtual machine to execute the required commands - - `scripts/debian_family/install_ansible.sh` sets up ansible on the vm. - - Depending on the VM being built, the `vm-develop.json` or the `vm-production.json` is used - - `scripts/set_message.sh` sets welcome message (with update instructions) in the vm. - - `scripts/cleanup.sh` writes zeros to all the free space in the disk, it shrinks the disk image -* Set the correct permissions for the built Vagrant and Virtual Appliance Images -* Cleanup - - Delete the generated files from the required directories -* Restart nginx - - -Running the `build.py` script builds the VMs and puts them in `~/Public`. It also creates the md5 hashes for the same, and puts them in the same folder. diff --git a/vm/Vagrantfile b/vm/Vagrantfile deleted file mode 100644 index 19fe518f..00000000 --- a/vm/Vagrantfile +++ /dev/null @@ -1,73 +0,0 @@ -# -*- mode: ruby -*- -# vi: set ft=ruby : - -# All Vagrant configuration is done below. The "2" in Vagrant.configure -# configures the configuration version (we support older styles for -# backwards compatibility). Please don't change it unless you know what -# you're doing. -Vagrant.configure(2) do |config| - # The most common configuration options are documented and commented below. - # For a complete reference, please see the online documentation at - # https://docs.vagrantup.com. - - # Every Vagrant development environment requires a box. You can search for - # boxes at https://atlas.hashicorp.com/search. - config.vm.box = "erpnext" - config.ssh.username = "frappe" - config.ssh.password = "frappe" - - # Disable automatic box update checking. If you disable this, then - # boxes will only be checked for updates when the user runs - # `vagrant box outdated`. This is not recommended. - # config.vm.box_check_update = false - - # Create a forwarded port mapping which allows access to a specific port - # within the machine from a port on the host machine. In the example below, - # accessing "localhost:8080" will access port 80 on the guest machine. - # config.vm.network "forwarded_port", guest: 80, host: 8080 - - # Create a private network, which allows host-only access to the machine - # using a specific IP. - # config.vm.network "private_network", ip: "192.168.33.10" - - # Create a public network, which generally matched to bridged network. - # Bridged networks make the machine appear as another physical device on - # your network. - # config.vm.network "public_network" - - # Share an additional folder to the guest VM. The first argument is - # the path on the host to the actual folder. The second argument is - # the path on the guest to mount the folder. And the optional third - # argument is a set of non-required options. - # config.vm.synced_folder "../data", "/vagrant_data" - - # Provider-specific configuration so you can fine-tune various - # backing providers for Vagrant. These expose provider-specific options. - # Example for VirtualBox: - # - # config.vm.provider "virtualbox" do |vb| - # # Display the VirtualBox GUI when booting the machine - # vb.gui = true - # - # # Customize the amount of memory on the VM: - # vb.memory = "1024" - # end - # - # View the documentation for the provider you are using for more - # information on available options. - - # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies - # such as FTP and Heroku are also available. See the documentation at - # https://docs.vagrantup.com/v2/push/atlas.html for more information. - # config.push.define "atlas" do |push| - # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" - # end - - # Enable provisioning with a shell script. Additional provisioners such as - # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the - # documentation for more information about their specific syntax and use. - # config.vm.provision "shell", inline: <<-SHELL - # sudo apt-get update - # sudo apt-get install -y apache2 - # SHELL -end diff --git a/vm/build.py b/vm/build.py deleted file mode 100644 index 0fc0d6d0..00000000 --- a/vm/build.py +++ /dev/null @@ -1,128 +0,0 @@ -""" -Builds a vm and puts it in ~/public with a latest.json that has its filename and md5sum -""" - -# imports - standard imports -import os -import json -import stat -import errno -from shutil import rmtree -from distutils import spawn -from subprocess import check_output - -NEW_FILES = [] -BUILDS = ['Production', 'Developer'] -PUBLIC_DIR = os.path.join(os.path.expanduser('~'), 'Public') -SYMLINKS = ['ERPNext-Production.ova', 'ERPNext-Dev.ova', 'ERPNext-Vagrant.box', - 'ERPNext-Production.ova.md5', 'ERPNext-Dev.ova.md5', 'ERPNext-Vagrant.box.md5'] - -def main(): - install_virtualbox() - install_packer() - cleanup() - build_vm() - generate_md5_hashes() - generate_symlinks() - delete_old_vms() - move_current_vms() - cleanup() - -def install_virtualbox(): - if not spawn.find_executable("virtualbox"): - check_output(['bench', 'install', 'virtualbox']) - -def install_packer(): - if not spawn.find_executable("packer") and not os.path.exists(os.path.join('/', 'opt', 'packer')): - check_output(['bench', 'install', 'packer']) - -def silent_remove(name, is_dir=False): - ''' - Method to safely remove a file or directory, - without throwing error if file doesn't exist - - By default takes in file as input, for directory: - is_dir = True - ''' - try: - if is_dir: - rmtree(name) - else: - os.remove(name) - except OSError as e: - if e.errno != errno.ENOENT: # errno.ENOENT = no such file or directory - raise # re-raise exception if a different error occurred - -def cleanup(): - silent_remove("Production Builds", is_dir=True) - silent_remove("Developer Builds", is_dir=True) - silent_remove("packer_virtualbox-iso_virtualbox-iso_md5.checksum") - -def build_vm(): - check_output(["packer", "build", "vm-production.json"]) - check_output(["packer", "build", "vm-develop.json"]) - -def md5(build, file): - return check_output("md5sum '{} Builds/{}'".format(build, file), shell=True).split()[0] - -def move_to_public(build, file): - NEW_FILES.append(file) - src = os.path.join('{} Builds/{}'.format(build, file)) - dest = os.path.join(PUBLIC_DIR, file) - os.rename(src, dest) - # Make Public folder readable by others - st = os.stat(dest) - os.chmod(dest, st.st_mode | stat.S_IROTH) - -def generate_md5_hashes(): - for build in BUILDS: - for file in os.listdir('{} Builds'.format(build)): - if file.endswith(".ova") or file.endswith(".box"): - with open('{} Builds/{}.md5'.format(build, file), 'w') as f: - f.write(md5(build, file)) - move_to_public(build, file) - move_to_public(build, '{}.md5'.format(file)) - -def generate_symlinks(): - for file in NEW_FILES: - if 'md5' in file: - if 'Vagrant' in file: - silent_remove(os.path.join(PUBLIC_DIR, 'ERPNext-Vagrant.box.md5')) - os.symlink(os.path.join(PUBLIC_DIR, file), - os.path.join(PUBLIC_DIR, 'ERPNext-Vagrant.box.md5')) - elif 'Production' in file: - silent_remove(os.path.join(PUBLIC_DIR, 'ERPNext-Production.ova.md5')) - os.symlink(os.path.join(PUBLIC_DIR, file), - os.path.join(PUBLIC_DIR, 'ERPNext-Production.ova.md5')) - else: # Develop - silent_remove(os.path.join(PUBLIC_DIR, 'ERPNext-Dev.ova.md5')) - os.symlink(os.path.join(PUBLIC_DIR, file), - os.path.join(PUBLIC_DIR, 'ERPNext-Dev.ova.md5')) - else: # ova/box files - if 'Vagrant' in file: - silent_remove(os.path.join(PUBLIC_DIR, 'ERPNext-Vagrant.box')) - os.symlink(os.path.join(PUBLIC_DIR, file), - os.path.join(PUBLIC_DIR, 'ERPNext-Vagrant.box')) - elif 'Production' in file: - silent_remove(os.path.join(PUBLIC_DIR, 'ERPNext-Production.ova')) - os.symlink(os.path.join(PUBLIC_DIR, file), - os.path.join(PUBLIC_DIR, 'ERPNext-Production.ova')) - else: # Develop - silent_remove(os.path.join(PUBLIC_DIR, 'ERPNext-Dev.ova')) - os.symlink(os.path.join(PUBLIC_DIR, file), - os.path.join(PUBLIC_DIR, 'ERPNext-Dev.ova')) - -def delete_old_vms(): - silent_remove(os.path.join(PUBLIC_DIR, 'BACKUPS'), is_dir=True) - -def move_current_vms(): - os.mkdir(os.path.join(PUBLIC_DIR, 'BACKUPS')) - for file in os.listdir(PUBLIC_DIR): - if file in NEW_FILES or file in SYMLINKS or file == 'BACKUPS': - continue - src = os.path.join(PUBLIC_DIR, '{}'.format(file)) - dest = os.path.join(PUBLIC_DIR, 'BACKUPS/{}'.format(file)) - os.rename(src, dest) - -if __name__ == "__main__": - main() diff --git a/vm/http/preseed.cfg b/vm/http/preseed.cfg deleted file mode 100644 index 87c4622e..00000000 --- a/vm/http/preseed.cfg +++ /dev/null @@ -1,41 +0,0 @@ -choose-mirror-bin mirror/http/proxy string -choose-mirror-bin mirror/http/proxy string -d-i base-installer/kernel/override-image string linux-server -d-i clock-setup/utc boolean true -d-i clock-setup/utc-auto boolean true -d-i finish-install/reboot_in_progress note -d-i grub-installer/only_debian boolean true -d-i grub-installer/with_other_os boolean true -d-i partman-auto/disk string /dev/sda -d-i partman-auto-lvm/guided_size string max -d-i partman-auto/choose_recipe select atomic -d-i partman-auto/method string lvm -d-i partman-lvm/confirm boolean true -d-i partman-lvm/confirm boolean true -d-i partman-lvm/confirm_nooverwrite boolean true -d-i partman-lvm/device_remove_lvm boolean true -d-i partman/choose_partition select finish -d-i partman/confirm boolean true -d-i partman/confirm_nooverwrite boolean true -d-i partman/confirm_write_new_label boolean true -d-i pkgsel/include string openssh-server cryptsetup build-essential libssl-dev libreadline-dev zlib1g-dev linux-source dkms nfs-common -d-i pkgsel/install-language-support boolean false -d-i pkgsel/update-policy select none -d-i pkgsel/upgrade select full-upgrade -d-i time/zone string UTC -tasksel tasksel/first multiselect standard, ubuntu-server - -d-i console-setup/ask_detect boolean false -d-i keyboard-configuration/layoutcode string us -d-i keyboard-configuration/modelcode string pc105 -d-i debian-installer/locale string en_US - -# Create frappe user account. -d-i passwd/user-fullname string frappe -d-i passwd/username string frappe -d-i passwd/user-password password frappe -d-i passwd/user-password-again password frappe -d-i user-setup/allow-password-weak boolean true -d-i user-setup/encrypt-home boolean false -d-i passwd/user-default-groups frappe sudo -d-i passwd/user-uid string 900 diff --git a/vm/scripts/debian_family/cleanup.sh b/vm/scripts/debian_family/cleanup.sh deleted file mode 100644 index d70c7a09..00000000 --- a/vm/scripts/debian_family/cleanup.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -eux - -# Apt cleanup -apt-get autoremove -apt-get clean -apt-get update - -# Zero out the rest of the free space using dd, then delete the written file. -dd if=/dev/zero of=/EMPTY bs=1M -rm -f /EMPTY - -# Add `sync` so Packer doesn't quit too early, before the large file is deleted. -sync \ No newline at end of file diff --git a/vm/scripts/debian_family/install_ansible.sh b/vm/scripts/debian_family/install_ansible.sh deleted file mode 100644 index c173dd94..00000000 --- a/vm/scripts/debian_family/install_ansible.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -eux - -# Install Ansible repository. -apt -y update && apt-get -y upgrade -apt -y install software-properties-common -apt-add-repository ppa:ansible/ansible - -# Install Ansible. -apt -y update -apt -y install ansible diff --git a/vm/scripts/debian_family/install_erpnext_develop.sh b/vm/scripts/debian_family/install_erpnext_develop.sh deleted file mode 100644 index 19b1b705..00000000 --- a/vm/scripts/debian_family/install_erpnext_develop.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -eux - -# Install ERPNext -wget https://raw.githubusercontent.com/frappe/bench/develop/install.py -python install.py --develop --user frappe --mysql-root-password frappe --admin-password admin \ No newline at end of file diff --git a/vm/scripts/debian_family/install_erpnext_production.sh b/vm/scripts/debian_family/install_erpnext_production.sh deleted file mode 100644 index b8493f1e..00000000 --- a/vm/scripts/debian_family/install_erpnext_production.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -eux - -# Install ERPNext -wget https://raw.githubusercontent.com/frappe/bench/develop/install.py -python install.py --production --user frappe --mysql-root-password frappe --admin-password admin \ No newline at end of file diff --git a/vm/scripts/debian_family/install_prerequisites.sh b/vm/scripts/debian_family/install_prerequisites.sh deleted file mode 100644 index 0aed12fd..00000000 --- a/vm/scripts/debian_family/install_prerequisites.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -eux - -# Install base requirements. -apt-get install -y curl git wget vim python-dev gcc diff --git a/vm/scripts/debian_family/setup.sh b/vm/scripts/debian_family/setup.sh deleted file mode 100644 index 743300e1..00000000 --- a/vm/scripts/debian_family/setup.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -eux - -# Add frappe user to sudoers. -echo "frappe ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers -sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers - -# Disable daily apt unattended updates. -echo 'APT::Periodic::Enable "0";' >> /etc/apt/apt.conf.d/10periodic diff --git a/vm/scripts/restart_supervisor.sh b/vm/scripts/restart_supervisor.sh deleted file mode 100644 index 0afad870..00000000 --- a/vm/scripts/restart_supervisor.sh +++ /dev/null @@ -1,14 +0,0 @@ -#! /bin/bash - - -# Write out current crontab -crontab -l > current_cron - -# Echo new cron into cron file -echo "@reboot sleep 20 && systemctl restart supervisor" >> current_cron - -# Install new cron file -crontab current_cron - -# Delete the temporary cron file -rm current_cron \ No newline at end of file diff --git a/vm/scripts/set_message_develop.sh b/vm/scripts/set_message_develop.sh deleted file mode 100644 index a1e94353..00000000 --- a/vm/scripts/set_message_develop.sh +++ /dev/null @@ -1,18 +0,0 @@ -#! /bin/bash - -message=" - ERPNext Evaluation VM (built on `date +\"%B %d, %Y\"`) - - Please access ERPNext by going to http://localhost:8000 on the host system. - The username is \"Administrator\" and password is \"admin\" - - Do consider donating at https://frappe.io/buy - - To update, login as - username: frappe - password: frappe - cd frappe-bench - bench update -" -echo "$message" | sudo tee -a /etc/issue -echo "$message" | sudo tee -a /etc/motd diff --git a/vm/scripts/set_message_production.sh b/vm/scripts/set_message_production.sh deleted file mode 100644 index 2fddcb77..00000000 --- a/vm/scripts/set_message_production.sh +++ /dev/null @@ -1,18 +0,0 @@ -#! /bin/bash - -message=" - ERPNext VM (built on `date +\"%B %d, %Y\"`) - - Please access ERPNext by going to http://localhost:8080 on the host system. - The username is \"Administrator\" and password is \"admin\" - - Consider buying professional support from us at https://erpnext.com/support - - To update, login as - username: frappe - password: frappe - cd frappe-bench - bench update -" -echo "$message" | sudo tee -a /etc/issue -echo "$message" | sudo tee -a /etc/motd diff --git a/vm/vm-develop.json b/vm/vm-develop.json deleted file mode 100644 index 1a70c44a..00000000 --- a/vm/vm-develop.json +++ /dev/null @@ -1,101 +0,0 @@ -{ - "builders": [{ - "vm_name": "ERPNext-Develop-{{isotime \"20060102150405\"}}", - "output_directory": "Developer Builds", - "type": "virtualbox-iso", - "boot_command": [ - "", - "", - "", - "", - "/install/vmlinuz", - " auto", - " console-setup/ask_detect=false", - " console-setup/layoutcode=us", - " console-setup/modelcode=pc105", - " debconf/frontend=noninteractive", - " debian-installer=en_US", - " fb=false", - " initrd=/install/initrd.gz", - " kbd-chooser/method=us", - " keyboard-configuration/layout=USA", - " keyboard-configuration/variant=USA", - " locale=en_US", - " netcfg/get_domain=vm", - " netcfg/get_hostname=ubuntu", - " grub-installer/bootdev=/dev/sda", - " noapic", - " preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg", - " -- ", - "" - ], - "boot_wait": "10s", - "format": "ova", - "guest_os_type": "Ubuntu_64", - "headless": true, - "iso_url": "http://releases.ubuntu.com/16.04/ubuntu-16.04.6-server-amd64.iso", - "iso_checksum": "ac8a79a86a905ebdc3ef3f5dd16b7360", - "iso_checksum_type": "md5", - "ssh_username": "frappe", - "ssh_password": "frappe", - "ssh_port": 22, - "ssh_wait_timeout": "10000s", - "http_directory": "http", - "guest_additions_mode": "disable", - "virtualbox_version_file": ".vbox_version", - "guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso", - "export_opts": [ - "--vsys", "0", - "--product", "ERPNext", - "--producturl", "https://erpnext.com", - "--vendor", "Frappe Techonologies", - "--vendorurl", "https://frappe.io", - "--description", "ERPNext Evaluation VM" - ], - "shutdown_command": "echo 'frappe'|sudo -S shutdown -P now", - "vboxmanage": [ - [ "modifyvm", "{{.Name}}", "--memory", "1024" ], - [ "modifyvm", "{{.Name}}", "--cpus", "1" ], - [ "modifyvm", "{{.Name}}", "--audio", "none" ], - [ "modifyvm", "{{.Name}}", "--natpf1", "vm_ssh,tcp,,3022,,22" ], - [ "modifyvm", "{{.Name}}", "--natpf1", "vm_http,tcp,,8080,,80" ], - [ "modifyvm", "{{.Name}}", "--natpf1", "vm_http2,tcp,,8000,,8000" ] - ] - }], - "provisioners": [{ - "type": "shell", - "execute_command": "echo 'frappe' | {{.Vars}} sudo -S -E bash '{{.Path}}'", - "script": "scripts/debian_family/install_ansible.sh" - }, { - "type": "shell", - "execute_command": "echo 'frappe' | {{.Vars}} sudo -S -E bash '{{.Path}}'", - "script": "scripts/debian_family/setup.sh" - },{ - "type": "shell", - "execute_command": "echo 'frappe' | {{.Vars}} sudo -S -E bash '{{.Path}}'", - "script": "scripts/debian_family/install_prerequisites.sh" - }, { - "type": "shell", - "script": "scripts/debian_family/install_erpnext_develop.sh" - }, { - "type": "shell", - "execute_command": "echo 'frappe' | {{.Vars}} sudo -S -E bash '{{.Path}}'", - "script": "scripts/debian_family/cleanup.sh" - }, { - "type": "shell", - "script": "scripts/set_message_develop.sh" - }, { - "type": "shell", - "execute_command": "echo 'frappe' | {{.Vars}} sudo -S -E bash '{{.Path}}'", - "script": "scripts/restart_supervisor.sh" - }], - "post-processors": [{ - "type": "checksum", - "checksum_types": ["md5"] - }, { - "type": "vagrant", - "keep_input_artifact": true, - "output": "Developer Builds/ERPNext-Vagrant-Develop-{{isotime \"20060102150405\"}}.box", - "vagrantfile_template": "Vagrantfile" - }] -} diff --git a/vm/vm-production.json b/vm/vm-production.json deleted file mode 100644 index c2883d54..00000000 --- a/vm/vm-production.json +++ /dev/null @@ -1,95 +0,0 @@ -{ - "builders": [{ - "vm_name": "ERPNext-Production-{{isotime \"20060102150405\"}}", - "output_directory": "Production Builds", - "type": "virtualbox-iso", - "boot_command": [ - "", - "", - "", - "", - "/install/vmlinuz", - " auto", - " console-setup/ask_detect=false", - " console-setup/layoutcode=us", - " console-setup/modelcode=pc105", - " debconf/frontend=noninteractive", - " debian-installer=en_US", - " fb=false", - " initrd=/install/initrd.gz", - " kbd-chooser/method=us", - " keyboard-configuration/layout=USA", - " keyboard-configuration/variant=USA", - " locale=en_US", - " netcfg/get_domain=vm", - " netcfg/get_hostname=ubuntu", - " grub-installer/bootdev=/dev/sda", - " noapic", - " preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg", - " -- ", - "" - ], - "boot_wait": "10s", - "format": "ova", - "guest_os_type": "Ubuntu_64", - "headless": true, - "iso_url": "http://releases.ubuntu.com/16.04/ubuntu-16.04.6-server-amd64.iso", - "iso_checksum": "ac8a79a86a905ebdc3ef3f5dd16b7360", - "iso_checksum_type": "md5", - "ssh_username": "frappe", - "ssh_password": "frappe", - "ssh_port": 22, - "ssh_wait_timeout": "10000s", - "http_directory": "http", - "guest_additions_mode": "disable", - "virtualbox_version_file": ".vbox_version", - "guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso", - "export_opts": [ - "--vsys", "0", - "--product", "ERPNext", - "--producturl", "https://erpnext.com", - "--vendor", "Frappe Techonologies", - "--vendorurl", "https://frappe.io", - "--description", "ERPNext Evaluation VM" - ], - "shutdown_command": "echo 'frappe'|sudo -S shutdown -P now", - "vboxmanage": [ - [ "modifyvm", "{{.Name}}", "--memory", "1024" ], - [ "modifyvm", "{{.Name}}", "--cpus", "1" ], - [ "modifyvm", "{{.Name}}", "--audio", "none" ], - [ "modifyvm", "{{.Name}}", "--natpf1", "vm_ssh,tcp,,3022,,22" ], - [ "modifyvm", "{{.Name}}", "--natpf1", "vm_http,tcp,,8080,,80" ] - ] - }], - "provisioners": [{ - "type": "shell", - "execute_command": "echo 'frappe' | {{.Vars}} sudo -S -E bash '{{.Path}}'", - "script": "scripts/debian_family/install_ansible.sh" - }, { - "type": "shell", - "execute_command": "echo 'frappe' | {{.Vars}} sudo -S -E bash '{{.Path}}'", - "script": "scripts/debian_family/setup.sh" - },{ - "type": "shell", - "execute_command": "echo 'frappe' | {{.Vars}} sudo -S -E bash '{{.Path}}'", - "script": "scripts/debian_family/install_prerequisites.sh" - }, { - "type": "shell", - "script": "scripts/debian_family/install_erpnext_production.sh" - }, { - "type": "shell", - "execute_command": "echo 'frappe' | {{.Vars}} sudo -S -E bash '{{.Path}}'", - "script": "scripts/debian_family/cleanup.sh" - }, { - "type": "shell", - "script": "scripts/set_message_production.sh" - }, { - "type": "shell", - "execute_command": "echo 'frappe' | {{.Vars}} sudo -S -E bash '{{.Path}}'", - "script": "scripts/restart_supervisor.sh" - }], - "post-processors": [{ - "type": "checksum", - "checksum_types": ["md5"] - }] -}