Skip to content

Commit

Permalink
Fix Plone 5 vagrant stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ksuess committed Oct 10, 2024
1 parent f775ddf commit 30e8086
Show file tree
Hide file tree
Showing 9 changed files with 355 additions and 6 deletions.
Binary file modified docs/_static/plone_training_config.zip
Binary file not shown.
11 changes: 7 additions & 4 deletions docs/mastering-plone-5/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ Mastering Plone is intended as a week-long training for people who are new to Pl
At conferences a shortened 2-day version of the advanced training with a slightly modified order is held.

```{toctree}
:caption: Mastering Plone 5
:maxdepth: 2
:numbered: true
---
caption: Mastering Plone 5 Development
name: toc-mastering5
maxdepth: 3
numbered: 2
---
about_mastering
intro
what_is_plone
installation
instructions_plone5
instructions_plone5/index
case
features
anatomy
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ You can choose to skip this step if you encounter any problems with it.
vagrant plugin install vagrant-vbguest
```

Now download {download}`plone_training_config.zip <../_static/plone_training_config.zip>` and copy its contents into your training directory.
Now download {download}`plone_training_config.zip <../../_static/plone_training_config.zip>` and copy its contents into your training directory.

```shell
wget https://github.com/plone/training/raw/master/_static/plone_training_config.zip
wget https://github.com/plone/training/raw/refs/heads/main/docs/_static/plone_training_config.zip
unzip plone_training_config.zip
```

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/bionic64"

config.vm.hostname = "training.plone.org"
config.vm.network :forwarded_port, guest: 8080, host: 8080

# Allow the creation of symbolic links in the shared folder.
# This is needed for some builds with cmmi and for omelette to work.
# 'v-root' is the default-name for the primary volume.
config.vm.provider :virtualbox do |vb|
vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vb.memory = "1536"
end

# A workaround for missing symbolic links on windows:
# config.vm.synced_folder "eggs/", "/home/vagrant/buildout-cache/eggs/"

# Read initial package index information + upgrade
config.vm.provision :shell, inline: <<-SHELL
apt-get update
apt-get -y upgrade
SHELL

# We need to install puppet on the guest before we can use it
config.vm.provision :shell, inline: <<-SHELL
apt-get install -y puppet
SHELL

# ensure we have the packages we need
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "manifests"
puppet.manifest_file = "packages.pp"
end

# Create a Putty-style keyfile for Windows users
config.vm.provision :shell do |shell|
shell.path = "manifests/host_setup.sh"
shell.args = RUBY_PLATFORM
end

# install plone
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "manifests"
puppet.manifest_file = "plone.pp"
end


end
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/sh

AS_VAGRANT="sudo -u vagrant"
SHARED_DIR="/vagrant"

# RUBY_PLATFORM=$1
echo $1 | if grep -q mingw; then
# Host environment is mingw, aka Windows.
# Let's set up support for using Putty

echo Host environment appears to be Windows.
echo Setting up support for using Putty for ssh.

if [ ! -f .ssh/id_rsa ]; then
echo Creating an ssh key, authorizing it, and putting a
echo Putty-compatible key file in shared directory.
cd .ssh
# generate openssh-style key pair
/usr/bin/ssh-keygen -q -t rsa -N "" -f id_rsa
# append public key to authorized_keys
cat id_rsa.pub >> authorized_keys
# create a putty-compatible key file
/usr/bin/puttygen id_rsa -O private -o id_rsa.ppk
# copy putty keyfile into shared directory
cp id_rsa.ppk ${SHARED_DIR}/insecure_putty_key.ppk
chmod 400 ${SHARED_DIR}/insecure_putty_key.ppk
cd ~
fi

for script in ${SHARED_DIR}/manifests/windows_host_scripts/*
do
target=`basename $script`
if [ ! -f ${SHARED_DIR}/$target ]; then
echo Copying `basename $script` ...
$AS_VAGRANT cp $script ${SHARED_DIR}
fi
done
else
# Host environment is probably something *nix
for script in ${SHARED_DIR}/manifests/host_scripts/*
do
target=`basename $script`
if [ ! -f ${SHARED_DIR}/$target ]; then
echo Copying `basename $script` ...
$AS_VAGRANT cp $script ${SHARED_DIR}
chmod 755 ${SHARED_DIR}/*.sh
fi
done
fi

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class packages {

package { "build-essential": ensure => present, }
package { "curl": ensure => present, }
package { "elinks": ensure => present, }
package { "gettext": ensure => present, }
package { "git": ensure => present, }
package { "libedit-dev": ensure => present, }
package { "libjpeg-dev": ensure => present, }
package { "libpcre3-dev": ensure => present, }
package { "libssl-dev": ensure => present, }
package { "libxml2-dev": ensure => present, }
package { "libxslt-dev": ensure => present, }
package { "libyaml-dev": ensure => present, }
package { "libz-dev": ensure => present, }
package { "nodejs": ensure => present, }
package { "npm": ensure => present, }
package { "python3.7-dev": ensure => present, }
package { "python3.7-tk": ensure => present, }
package { "python3.7-venv": ensure => present, }
package { "subversion": ensure => present, }
package { "unzip": ensure => present, }
package { "vim": ensure => present, }
package { "wget": ensure => present, }

# Optional packages to enable indexing of office/pdf docs
# package { "wv": ensure => present, }
# package { "poppler-utils": ensure => present, }

# used for creating a PuTTy-compatible key file
package { "putty-tools": ensure => present, }

}

include packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
class plone {

$plone_version = "5.2"
$buildout_branch = "plone52"

file { ['/home/vagrant/tmp',
'/home/vagrant/.buildout',
'/home/vagrant/buildout-cache',
'/home/vagrant/buildout-cache/eggs',
'/home/vagrant/buildout-cache/downloads',
'/home/vagrant/buildout-cache/extends',
]:
ensure => directory,
owner => 'vagrant',
group => 'vagrant',
mode => '0755',
}

file { '/home/vagrant/.buildout/default.cfg':
ensure => present,
content => inline_template('[buildout]
eggs-directory = /home/vagrant/buildout-cache/eggs
download-cache = /home/vagrant/buildout-cache/downloads
extends-cache = /home/vagrant/buildout-cache/extends'),
owner => 'vagrant',
group => 'vagrant',
mode => '0664',
}

Exec {
path => [
'/usr/local/bin',
'/opt/local/bin',
'/usr/bin',
'/usr/sbin',
'/bin',
'/sbin'],
logoutput => true,
}

# Create virtualenv
exec {'python3.7 -m venv py37':
alias => "virtualenv",
creates => '/home/vagrant/py37',
user => 'vagrant',
cwd => '/home/vagrant',
before => Exec["install_buildout_setuptools"],
timeout => 300,
}

# Install zc.buildout, setuptools
exec {"/home/vagrant/py37/bin/pip install -r http://dist.plone.org/release/${plone_version}/requirements.txt":
alias => "install_buildout_setuptools",
creates => '/home/vagrant/py37/bin/buildout',
user => 'vagrant',
cwd => '/home/vagrant',
before => Exec["checkout_training"],
timeout => 0,
}

# Unpack the buildout-cache to /home/vagrant/buildout-cache/
exec {"tar xjf /home/vagrant/buildout-cache.tar.bz2":
alias => "unpack_buildout_cache",
creates => "/home/vagrant/buildout-cache/eggs/Products.CMFPlone-${plone_version}-py3.7.egg/",
user => 'vagrant',
cwd => '/home/vagrant',
before => Exec["checkout_training"],
timeout => 0,
onlyif => "test -f /home/vagrant/buildout-cache.tar.bz2" # managed to dowload the tarball
}

# get training buildout
exec {'git clone https://github.com/collective/training_buildout.git buildout':
alias => "checkout_training",
creates => '/vagrant/buildout',
user => 'vagrant',
cwd => '/vagrant',
before => Exec["branch_training"],
timeout => 0,
}

# select branch of training buildout
exec {'git checkout ${buildout_branch}':
alias => "branch_training",
user => 'vagrant',
cwd => '/vagrant/buildout',
before => Exec["buildout_training"],
timeout => 0,
}

# run training buildout
exec {'/home/vagrant/py37/bin/buildout -c vagrant_provisioning.cfg':
alias => "buildout_training",
creates => '/vagrant/buildout/bin/instance',
user => 'vagrant',
cwd => '/vagrant/buildout',
# before => Exec["buildout_final"],
timeout => 0,
}

}

include plone
103 changes: 103 additions & 0 deletions docs/mastering-plone-5/instructions_plone5/what_vagrant_does.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
myst:
html_meta:
"description": ""
"property=og:description": ""
"property=og:title": ""
"keywords": ""
---

# What Vagrant is and does

```{note}
These steps are automatically done by Vagrant and Puppet for you. They are only interesting if you want to know what goes on under the hood for preparing your virtual training environment.
```

Vagrant is an automation tool for developers to script the configuration and starting/stopping of virtual machines using applications like VirtualBox or Vmware Fusion/Workstation. The beauty of Vagrant is that it is largely platform independent for Linux, Windows and Apple, so with one 'Vagrantfile' per project you describe a base installation virtual image and all kinds of virtual machine settings you would otherwise have to click and type together in Virtual machine application.

What Vagrant for example does is install a port forward so that `http://localhost:8080` on your physical computer is automatically forwarded to the port Plone will be listening on in the guest virtual machine. After Vagrant has done its thing to set up your virtual machine we are not finished though. Although Vagrant has the option to prebuild specific images it would be a lot of work and waste of bandwidth to redownload a machine images (300-600Mb) each time we would like to change small things in our virtual training environment.

Puppet is a configuration management tool (others you might have heard of are Chef, Ansible and SaltStack) and helps system admnistrators to automatically manage servers (real and virtual). We won't get into Puppet in detail, but it builds on top of our base Vagrant image to further set up our environment.

Vagrant detects when you set up a new machine and runs Puppet or other Provisioners by default only once, although it also can be used to keep machines up to date, which is a bit harder. See the {file}`Vagrantfile` and [Vagrant Documentation](https://developer.hashicorp.com/vagrant/docs), especially the *Provisioning* chapter.

This is basically what Puppet does if we were to configure our system by hand:

First we update Ubuntu and install some packages.

```shell
$ sudo aptitude update --quiet --assume-yes
$ sudo aptitude upgrade --quiet --assume-yes
$ sudo apt-get install build-essential
$ sudo apt-get install curl
$ sudo apt-get install elinks
$ sudo apt-get install gettext
$ sudo apt-get install git
$ sudo apt-get install libedit-dev
$ sudo apt-get install libjpeg-dev
$ sudo apt-get install libpcre3-dev
$ sudo apt-get install libssl-dev
$ sudo apt-get install libxml2-dev
$ sudo apt-get install libxslt-dev
$ sudo apt-get install libyaml-dev
$ sudo apt-get install libz-dev
$ sudo apt-get install nodejs
$ sudo apt-get install npm
$ sudo apt-get install python3.7-dev
$ sudo apt-get install python3.7-tk
$ sudo apt-get install python3.7-venv
$ sudo apt-get install subversion
$ sudo apt-get install unzip
$ sudo apt-get install vim
$ sudo apt-get install wget
$ sudo apt-get install wv
$ sudo apt-get install poppler-utils
$ sudo apt-get install putty-tools
```

Then we create a virtual python environment using virtualenv. This is always a good practice since that way we get a clean isolated copy of our system python, so that we do not break the system python by installing eggs that might collide with other eggs. Python is nowadays used a lot by your operating system as well for all kinds of system tools and scripting.

```shell
$ python3.7 -m venv /home/vagrant/py37
```

Install zc.buildout, setuptools and other dependencies for the current version into the new virtualenv.

```shell
$ /home/vagrant/py37/bin/pip install -r http://dist.plone.org/release/5.2/requirements.txt
```

Now we download and unpack a buildout-cache that holds all the python packages that make up Plone. This is an optimisation: We could skip this step and have buildout download all packages individually from the [python packaging index PyPi](https://pypi.org) but that takes much longer on a first install.

```shell
$ wget http://dist.plone.org/release/5.2/buildout-cache.tar.bz2
$ tar xjf buildout-cache.tar.bz2
```

Then we check out our tutorial buildout from <https://github.com/collective/training_buildout> and build it.

```shell
$ cd /vagrant
$ git clone https://github.com/collective/training_buildout.git buildout
$ cd buildout
```

Then we run buildout:

```shell
$ /home/vagrant/py37/bin/buildout -c vagrant_provisioning.cfg
```

This will download many additional eggs that are not yet part of the buildout-cache and configure Plone to be ready to run.

At this point Vagrant and Puppet have finished their job to set up your virtual training environment on your local machine.

You can now connect to the machine and start Plone.

```shell
$ vagrant ssh
$ cd /vagrant/buildout
$ ./bin/instance fg
```

Now we have a fresh Buildout-based Zope application server, ready to add a Plone site. Go to <http://localhost:8080> and create a Plone site.

0 comments on commit 30e8086

Please sign in to comment.