Remove unmaintained Vagrant configuration

This commit is contained in:
Alex Cabal 2021-02-10 16:00:03 -06:00
parent d32c56bb05
commit 8f30ee2530
4 changed files with 5 additions and 183 deletions

View file

@ -180,50 +180,3 @@ Before submitting design contributions, please discuss them with the Standard Eb
else else
print('Bar!'); print('Bar!');
```` ````
# Vagrant
You can also set up a development server running Ubuntu 18.04 with nginx and php-fpm by using the included Vagrantfile in the project root. To do so, first install Vagrant and VirtualBox.
Both are available as packages in several major distributions, including Arch, Debian, Fedora, Gentoo, Ubuntu, and NixOS among others. Note that [the official docs advise against installing from distribution repositories](https://www.vagrantup.com/intro/getting-started/install.html) due to potentially old versions or incorrect dependencies.
If you want to download the official binaries because Vagrant is not available in your distros repository, because the version in the repository is too old or broken, or because you do not use Linux, you can download Vagrant [here](https://www.vagrantup.com/downloads.html)
and VirtualBox from [here.](https://www.virtualbox.org/wiki/Downloads)
After you have installed both, you can start and manage a VM running a server like this:
- `vagrant box add ubuntu/bionic64` downloads an [official Ubuntu 18.04 image](https://app.vagrantup.com/ubuntu/boxes/bionic64) (also known as a box in Vagrant terminology) for use as a base image in Vagrant VMs. This box is stored in `$HOME/.vagrant.d/boxes`.
- `vagrant run` will launch a VirtualBox VM running the server. (Note: newer versions of Vagrant, such as the one found on Arch, use `up` instead of `run`.)
* On its first invocation, or when the VM has been deleted, `vagrant up` will create a new VirtualBox VM in your standard Virtualbox machine directory (usually `$HOME/VirtualBox VMs`) using the previously added box as a base and configure it using the `Vagrantfile` and `scripts/provision.sh`. This means that the first time doing `vagrant run` will take significantly longer than following invocations because those simply start up the already created VM associated with VirtualBox.
* Note that `vagrant run` will automatically download the box specified in the Vagrantfile (in this case `ubuntu/bionic64`), so you can skip `vagrant box add ubuntu/bionic64` if you want.
- The project root is mounted in the VM as `/standardebooks.org/`, so any changes you make in the repository will be reflected in the webroot inside VM. However, you may have to restart the server for it to pick up the changes. You can restart the entire VM by doing `vagrant reload` or you can use `vagrant ssh -c "sudo systemctl restart php7.2-fpm; sudo systemctl restart nginx;"` to restart php-fpm and nginx.
- You can run commands inside the VM with `vagrant ssh -c COMMAND` or launch an interactive SSH session with `vagrant ssh`.
- When you are done, you can shut down the VM by doing `vagrant halt`. To start it again, do `vagrant run`.
- To delete the project-local VirtualBox VM, run `vagrant destroy`. To get a fresh VM, for example, you can do `vagrant destroy` followed by `vagrant up`. Note that this does not delete any added boxes/base images added with `vagrant box add`.
## Some further notes
- The Vagrant script will install [se](https://standardebooks.org/tools) by default. If you dont want that (it pulls in quite a few dependencies), remove the `se-tools` argument in Vagrantfile.
- `se`, if installed in the VM, and /standardebooks.org/scripts are in the VMs path. This means you can easily use them with `vagrant ssh -c` like this: `vagrant ssh -c "sync-ebooks -vv /standardebooks.org/ebooks; deploy-ebook-to-www -v --group www-data /standardebooks.org/ebooks/*"`, which would populate the test server with all available SE ebooks.
- It is safe to re-run the provision script if you did not change the nginx or php configuration files (change the files in the provision script and re-provision instead), so you can use `vagrant up --provision` or `vagrant reload --provision to update the VM, including se-tools and epubcheck, without having to delete it.
- The server runs on `127.0.0.1:8080` if you want to use a different port, change the `host: 8080` statement in the Vagrantfile to the desired port.
- You can list all locally installed boxes by doing `vagrant box list`.
- To completely delete a box, you can run `vagrant box remove ubuntu/bionic64`.
- To update the box, run `vagrant box update --box ubuntu/bionic64`. Note that this will not change the project-local VM. You will have to create a new VM based on the updated box by doing a `vagrant destroy` followed by a `vagrant up`. To remove old unused versions of boxes, run `vagrant box prune`.
- Check out scripts/provision.sh to see how the server is configured, the script is Vagrant-agnostic, so it should be helpful even if you dont want to use Vagrant.
- For further information, check out the [official Vagrant guide.](https://www.vagrantup.com/intro/index.html)

9
Vagrantfile vendored
View file

@ -1,9 +0,0 @@
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/bionic64"
config.vm.provision :shell, path: "scripts/vagrant/provision",
args: ["se-tools"]
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.synced_folder ".", "/standardebooks.org",
owner: "www-data", group: "www-data",
mount_options: ["dmode=775,fmode=777"]
end

View file

@ -1,13 +1,13 @@
# sync-ebooks # sync-ebooks
To use, call this script with the directory where your ebooks go as its last argument. For example `sync-ebooks /standardebooks.org/ebooks` or if you want to clone them into this repository `sync-ebooks ebooks`. If you want progress output, use -v, and if you want detailed git progress output use -vv. GitHub allows you to make 60 unauthenticated API requests per hour. If you use unauthenticated API requests for other things, this might not be enough, so to resolve that issue, you can create a new OAuth token at https://github.com/settings/tokens/new and pass it via the --token option. You don't need to give the token any permissions. To use, call this script with the directory where your ebooks go as its last argument. For example `sync-ebooks /standardebooks.org/ebooks`, or if you want to clone them into this repository, `sync-ebooks ebooks`. If you want progress output, use `-v`, and if you want detailed Git progress output use `-vv`. GitHub allows you to make 60 unauthenticated API requests per hour. If you use unauthenticated API requests for other things, this might not be enough, so to resolve that issue, you can create a new OAuth token at `https://github.com/settings/tokens/new` and pass it via the `--token` option. You dont need to give the token any permissions.
# deploy-ebook-to-www # deploy-ebook-to-www
To use, call this script with the directories of the books you want to deploy as its arguments. For example, to deploy all ebooks after using sync-ebooks, run `deploy-ebook-to-www /standardebooks.org/ebooks/*`. To deploy only The Time Machine by H.G Wells, you would run `deploy-ebook-to-www /standardebooks.org/ebooks/h-g-wells_the-time-machine`. To output progress information, use -v or --verbose. To use, call this script with the directories of the books you want to deploy as its arguments. For example, to deploy all ebooks after using sync-ebooks, run `deploy-ebook-to-www /standardebooks.org/ebooks/*`. To deploy only The Time Machine by H. G. Wells, you would run `deploy-ebook-to-www /standardebooks.org/ebooks/h-g-wells_the-time-machine`. To output progress information, use `-v` or `--verbose`.
The default web root is /standardebooks.org. If it is located elsewhere, specify it with the --webroot option. For instance, `deploy-ebook-to-www --webroot /var/www/html /path/to/ebook`. Note that there will be php errors if the git repositories are not in the ebook directory immediately in the web root. Either keep them there or create a symlink. The default web root is `/standardebooks.org`. If it is located elsewhere, specify it with the `--webroot` option. For instance, `deploy-ebook-to-www --webroot /var/www/html /path/to/ebook`. Note that there will be php errors if the Git repositories are not in the ebook directory immediately in the web root. Either keep them there or create a symlink.
The default group is se. to use a different one, specify it with the --group option. For instance, to use this script inside the included Vagrant VM, which uses the www-data group, use `deploy-ebook-to-www --group www-data /path/to/ebook`. The default group is `se`. to use a different one, specify it with the `--group` option.
The default URL is `https://standardebooks.org`. To change it, use the --weburl option. For example, `deploy-ebook-to-www --weburl "http://localhost:8080". This option will cause deploy-ebook-to-www to use the specified URL in the generated opds and rss files. Care should be taken however; the URL `https://standardebooks.org` is hardcoded in a few places, even when `SITE_URL` is changed to a custom URL, so for testing, it may be more convenient to simply use /etc/hosts or a similar mechanism to resolve `standardebooks.org` to `127.0.0.1`. The default URL is `https://standardebooks.org`. To change it, use the `--weburl` option. For example, `deploy-ebook-to-www --weburl "http://localhost:8080"`. This option will cause `deploy-ebook-to-www` to use the specified URL in the generated OPDS and RSS files. Care should be taken however; the URL `https://standardebooks.org` is hard-coded in a few places, even when `SITE_URL` is changed to a custom URL, so for testing, it may be more convenient to simply use `/etc/hosts` or a similar mechanism to resolve `standardebooks.org` to `127.0.0.1`.

View file

@ -1,122 +0,0 @@
#!/usr/bin/env bash
apt-get update -y
apt-get install -y nginx php-fpm php-apcu php-intl php-mbstring php-xml php-zip composer\
zip unzip git
if [ "$1" = "se-tools" ]
then
cat << "EOF" | su - vagrant -c /bin/bash
#!/bin/bash
set -e
set -o pipefail
# Install some pre-flight dependencies.
sudo apt-get install -y python3-pip libxml2-utils librsvg2-bin libimage-exiftool-perl imagemagick jarwrapper default-jre inkscape calibre curl\
firefox
# Install required fonts.
mkdir -p ~/.local/share/fonts/
curl -s -o ~/.local/share/fonts/LeagueSpartan-Bold.otf "https://raw.githubusercontent.com/theleagueof/league-spartan/master/LeagueSpartan-Bold.otf"
curl -s -o ~/.local/share/fonts/OFLGoudyStM.otf "https://raw.githubusercontent.com/theleagueof/sorts-mill-goudy/master/OFLGoudyStM.otf"
curl -s -o ~/.local/share/fonts/OFLGoudyStM-Italic.otf "https://raw.githubusercontent.com/theleagueof/sorts-mill-goudy/master/OFLGoudyStM-Italic.otf"
# Refresh the local font cache.
sudo fc-cache -f
rm -rf ~/.local/share/epubcheck
epubcheck_download_url=$(curl https://api.github.com/repos/w3c/epubcheck/releases/latest \
| grep -E --only-matching "\"browser_download_url\":\s*\"(.*?)\"" \
| sed "s/\"browser_download_url\":\s*//g" | sed "s/\"//g")
if [ ! -f ~/.epubcheck_version ] || ! grep -q "${epubcheck_download_url}" ~/.epubcheck_version; then
# Download and install the required version of epubcheck.
wget --quiet -O /tmp/epubcheck.zip "${epubcheck_download_url}"
unzip -o -d $HOME/.local/share/ /tmp/epubcheck.zip
mv -f $HOME/.local/share/epubcheck-* $HOME/.local/share/epubcheck
sudo chmod +x $HOME/.local/share/epubcheck/epubcheck.jar
sudo ln -fs $HOME/.local/share/epubcheck/epubcheck.jar /usr/local/bin/epubcheck
printf "%s" "${epubcheck_download_url}" > ~/.epubcheck_version
fi
# Install the toolset.
pip3 install --upgrade standardebooks
# Install tab completion.
sudo ln -fs $HOME/.local/lib/python3.*/site-packages/se/completions/bash/se /usr/share/bash-completion/completions/se
echo "se has been installed to '~/.local/bin'. It should be in your path."
EOF
fi
cat << "EOF" > /etc/php/7.2/fpm/conf.d/99-standardebooks.ini
include_path = .:/standardebooks.org/lib
short_open_tag = On
extension = apcu
extension = intl
#display_errors = On
#display_startup_errors = On
EOF
sed -i "s/short_open_tag = Off/short_open_tag = On/g" /etc/php/7.2/cli/php.ini
cat << "EOF" > /etc/nginx/sites-available/default
server {
listen 80 default_server;
listen [::]:80 default_server;
root /standardebooks.org/web/www;
index index.php index.html index.htm index.xml index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ @extensionless-php;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
location @extensionless-php {
rewrite ^(.*)$ $1.php last;
}
rewrite ^/ebooks/([^\./]+?)/$ /ebooks/author.php?url-path=$1;
rewrite ^/ebooks/([^\.]+?)/?$ /ebooks/ebook.php?url-path=$1;
rewrite ^/tags/([^\./]+?)/?$ /ebooks/index.php?tag=$1;
rewrite ^/collections/([^\./]+?)/?$ /ebooks/index.php?collection=$1;
rewrite ^/images/covers/([^\./]+?)-[0-9a-f]+-cover([^\./]+).jpg$ /images/covers/$1-cover$2.jpg;
rewrite ^/images/covers/([^\./]+?)-[0-9a-f]+-hero([^\./]+).jpg$ /images/covers/$1-hero$2.jpg;
rewrite ^/rss/new-releases/?$ /rss/new-releases.xml;
}
EOF
cat << "EOF" | su - vagrant -c /bin/bash
#!/bin/bash
set -e
set -o pipefail
if ! grep "^export PATH=$PATH:~/.local/bin$" ~/.bashrc; then
printf '\nexport PATH=$PATH:~/.local/bin' >> ~/.bashrc
fi
ln -fs /standardebooks.org/scripts/sync-ebooks ~/.local/bin/sync-ebooks
ln -fs /standardebooks.org/web/scripts/deploy-ebook-to-www ~/.local/bin/deploy-ebook-to-www
EOF
chown -R www-data:www-data /var/www
su - www-data -s /bin/sh -c "cd /standardebooks.org/; composer install"
usermod -a -G www-data vagrant
systemctl enable php7.2-fpm
systemctl enable nginx
systemctl restart php7.2-fpm
systemctl restart nginx