2
0
mirror of https://github.com/frappe/bench.git synced 2024-11-13 16:56:33 +00:00

chore: Drop vm project

VM project has been unmaintained and out of date for a long long time
now. The auto-build and publish pipeline has been dead for years and has
been de-listed too from erpnext.org. Nows a better time than ever to get
rid of this unmaintained piece of the project.
This commit is contained in:
Gavin D'souza 2022-06-14 15:36:20 +05:30
parent a1a0d5dae4
commit 0f64446c17
15 changed files with 0 additions and 570 deletions

View File

@ -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.

73
vm/Vagrantfile vendored
View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,4 +0,0 @@
#!/bin/bash -eux
# Install base requirements.
apt-get install -y curl git wget vim python-dev gcc

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,101 +0,0 @@
{
"builders": [{
"vm_name": "ERPNext-Develop-{{isotime \"20060102150405\"}}",
"output_directory": "Developer Builds",
"type": "virtualbox-iso",
"boot_command": [
"<enter><wait><f6><esc><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"/install/vmlinuz<wait>",
" auto<wait>",
" console-setup/ask_detect=false<wait>",
" console-setup/layoutcode=us<wait>",
" console-setup/modelcode=pc105<wait>",
" debconf/frontend=noninteractive<wait>",
" debian-installer=en_US<wait>",
" fb=false<wait>",
" initrd=/install/initrd.gz<wait>",
" kbd-chooser/method=us<wait>",
" keyboard-configuration/layout=USA<wait>",
" keyboard-configuration/variant=USA<wait>",
" locale=en_US<wait>",
" netcfg/get_domain=vm<wait>",
" netcfg/get_hostname=ubuntu<wait>",
" grub-installer/bootdev=/dev/sda<wait>",
" noapic<wait>",
" preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg",
" -- <wait>",
"<enter><wait>"
],
"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"
}]
}

View File

@ -1,95 +0,0 @@
{
"builders": [{
"vm_name": "ERPNext-Production-{{isotime \"20060102150405\"}}",
"output_directory": "Production Builds",
"type": "virtualbox-iso",
"boot_command": [
"<enter><wait><f6><esc><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
"/install/vmlinuz<wait>",
" auto<wait>",
" console-setup/ask_detect=false<wait>",
" console-setup/layoutcode=us<wait>",
" console-setup/modelcode=pc105<wait>",
" debconf/frontend=noninteractive<wait>",
" debian-installer=en_US<wait>",
" fb=false<wait>",
" initrd=/install/initrd.gz<wait>",
" kbd-chooser/method=us<wait>",
" keyboard-configuration/layout=USA<wait>",
" keyboard-configuration/variant=USA<wait>",
" locale=en_US<wait>",
" netcfg/get_domain=vm<wait>",
" netcfg/get_hostname=ubuntu<wait>",
" grub-installer/bootdev=/dev/sda<wait>",
" noapic<wait>",
" preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg",
" -- <wait>",
"<enter><wait>"
],
"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"]
}]
}