Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 2 additions & 19 deletions deploy/vagrant/sfdev/Vagrantfile
Comment thread
marksvc marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Vagrant.configure("2") do |config|
# Chromium, running tests, etc. at the same time. Though more, such as 24000, is sometimes needed.
# To set how much RAM the vagrant guest should use, you can set the RAM value in a SFDEV_RAM
# environment variable by running a command such as
# tee --append ~/.pam_environment <<< 'SFDEV_RAM="14000"'
# tee --append ~/.config/environment.d/vagrant.conf <<< "SFDEV_RAM=14000"
# and then logging back into your computer. Or temporarily set the value here.
vb.memory = ENV['SFDEV_RAM'] || "6000"
# Enable 3D acceleration and more video RAM for larger displays.
Expand All @@ -24,34 +24,17 @@ Vagrant.configure("2") do |config|
config.vm.provision "shell", privileged: false, inline: <<~SHELL
set -xueo pipefail

function tryharderto() { i=0; until "$@"; do ((++i <= 3)); echo >&2 "Retrying ${i}"; sleep 2m; done }

# Prepare canary
tee ~/Desktop/warning-not-provisioned.txt >/dev/null <<END
The presence of this file means that the vagrant virtual machine did not
finish provisioning correctly.
The best way to get to a working machine state is to backup any data that
you want to keep from this virtual machine, and then destroy and re-create
this vagrant virtual machine by running these commands from your host:
vagrant destroy
vagrant up
END

# Set git user and email from host.
GIT_USER="#{`git config --get user.name`.strip}"
GIT_EMAIL="#{`git config --get user.email`.strip}"
[[ -z $GIT_USER ]] || git config --global user.name "${GIT_USER}"
[[ -z $GIT_EMAIL ]] || git config --global user.email "${GIT_EMAIL}"

# Update code repo
cd ~/code/web-xforge
git fetch

cd ~/code/web-xforge/
sudo npm install --global npm@11.11.0
Comment thread
marksvc marked this conversation as resolved.

# Remove canary
rm ~/Desktop/warning-not-provisioned.txt
rm -f ~/Desktop/WARNING-NOT-PROVISIONED.txt
echo "Provisioning finished successfully."
SHELL
end
124 changes: 124 additions & 0 deletions deploy/vagrant/sfdev/base/development.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/bin/bash
# Vagrant sfdev optional development tools provision script.
set -xueo pipefail

# Duplicate output to a log file
exec &> >(tee "$(mktemp --tmpdir "provision-$(date +"%F-%H%M%S")-XXXXXXXXXX.log")")

# Helper method to avoid failing from a network hiccup during provision
function tryharderto() {
i=0
until "$@"; do
((++i <= 3))
echo >&2 "Retrying ${i}"
sleep 2m
done
}

sudo snap install yq
sudo snap install --beta tortoisehg

# GitKraken
sudo snap install --classic gitkraken

# Visual Studio Code https://code.visualstudio.com/docs/setup/linux
cd "$(mktemp -d)"
curl --silent --location --fail --show-error \
https://packages.microsoft.com/keys/microsoft.asc |
gpg --dearmor >microsoft.gpg
sudo install --owner root --group root --mode 644 \
microsoft.gpg /etc/apt/trusted.gpg.d/
sudo tee /etc/apt/sources.list.d/vscode.list >/dev/null <<< \
"deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"
tryharderto sudo apt-get update
tryharderto sudo apt-get --assume-yes install code
code --install-extension EditorConfig.EditorConfig
code --install-extension eamodio.gitlens
code --install-extension ms-dotnettools.csharp
code --install-extension GitHub.copilot
code --install-extension mongodb.mongodb-vscode
code --install-extension formulahendry.dotnet-test-explorer
code --install-extension ms-dotnettools.csdevkit
code --install-extension streetsidesoftware.code-spell-checker
code --install-extension csharpier.csharpier-vscode
code --install-extension dbaeumer.vscode-eslint
code --install-extension GitHub.copilot-chat
code --install-extension ms-dotnettools.vscodeintellicode-csharp
code --install-extension ms-vsliveshare.vsliveshare
code --install-extension esbenp.prettier-vscode
code --install-extension hbenl.vscode-test-explorer
Comment thread
marksvc marked this conversation as resolved.

sudo tee --append /etc/sysctl.d/90-vscode.conf >/dev/null <<END
# Let VS Code, dotnet, etc watch lots of files.
fs.inotify.max_user_watches=10000000
fs.inotify.max_user_instances=10000000
END
# mono devel for OmniSharp
tryharderto sudo apt-get --assume-yes install mono-complete

# Install workspace-recommended extensions
perl -n -e 'print unless /^ *\/\//' ~/code/web-xforge/.vscode/extensions.json |
jq --raw-output '.recommendations[]' |
while read extension; do
code --install-extension "${extension}"
done

# Paratext
sudo snap install paratext --beta
sudo snap install paratextlite
sudo snap install paratext-10-studio

# Launchers
TOOLSDIR="${HOME}/Desktop"
mkdir --parents "${TOOLSDIR}"
cp -a --dereference \
/usr/share/applications/code.desktop \
/snap/gitkraken/current/meta/gui/gitkraken.desktop \
/snap/paratext/current/meta/gui/paratext.desktop \
/usr/share/applications/byobu.desktop \
/snap/chromium/current/meta/gui/chromium.desktop \
"${TOOLSDIR}"
chmod +x "${TOOLSDIR}"/*.desktop
perl -pi -e 's#\${SNAP}#/snap/chromium/current#' "${TOOLSDIR}"/chromium.desktop
perl -pi -e 's#\${SNAP}#/snap/paratext/current#' "${TOOLSDIR}"/paratext.desktop

# Fix icon
perl -pi -e '/Icon/ and s#.*#Icon=/snap/gitkraken/current/usr/share/gitkraken/gitkraken.png#' \
"${TOOLSDIR}"/gitkraken.desktop

# Docker

# https://docs.docker.com/desktop/install/linux-install/
sudo usermod --append --groups kvm ${USER}

# https://docs.docker.com/engine/install/ubuntu/#set-up-the-repository
cd $(mktemp -d)
curl --silent --location --fail --show-error \
--output docker.asc https://download.docker.com/linux/ubuntu/gpg
sudo install --owner root --group root --mode 644 docker.asc /etc/apt/keyrings/
sudo tee /etc/apt/sources.list.d/docker.sources >/dev/null <<-END
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(lsb_release --short --codename)
Components: stable
Architectures: amd64
Signed-By: /etc/apt/keyrings/docker.asc
END
tryharderto sudo apt-get update
tryharderto sudo apt-get --assume-yes install \
docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# This is not a great security solution. https://askubuntu.com/q/477551
sudo usermod --append --groups docker ${USER}

# Make dir ahead of time before root does and owns it.
mkdir --parents ~/.vsdbg

# /Docker

# Apply any updates
tryharderto sudo apt-get update
tryharderto sudo apt-get --assume-yes upgrade
tryharderto sudo apt-get --assume-yes dist-upgrade

echo "$0: $(date -Is): Script finished successfully."
73 changes: 37 additions & 36 deletions deploy/vagrant/sfdev/base/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,37 @@ using it.
The actual RAM available in the product will depend on a Vagrantfile setting
later on.
- In Settings for the guest, give 2-4 processors.
- Boot installation .iso. Install OS. Don't install unneeded
"third-party software" in Ubuntu.
- Boot Kubuntu installation .iso. Install OS. Minimal install. Don't install
unneeded "third-party software" in Ubuntu. No swap.
- Use computer name `sfdev`, username `vagrant` and password `vagrant`.
Choose Log in automatically.
Select to log in automatically.
- Choosing a North American location can make the locale situation less
complicated when later getting to Ansible.

## Setup machine

- Set resolution to a big enough but conservative initial value of 1440x900,
that will fit inside someone's 1080p desktop.

- Launch Software Updater, apply updates, and reboot into any new kernel. If
that gives any trouble, fall back to: boot to recovery mode, enable
networking, and run `apt update && apt upgrade --assume-yes`.
- Update with `sudo apt update && sudo apt upgrade` and reboot into any new
kernel.

- Install guest additions.

- On your host machine, you may need to run the following if you have
VirtualBox installed from Ubuntu rather than from Oracle.

sudo apt install virtualbox-guest-additions-iso

- In the guest machine window, choose Devices > Insert Guest Additions CD
image. In the guest machine, run
image. In the guest machine, mount it if needed, and run

```
sudo apt update &&
sudo apt install --assume-yes build-essential &&
sudo /media/vagrant/VBox*/VBoxLinuxAdditions.run
```

- Right-click the CD icon on the panel or desktop and Eject the
VirtualBox Additions disc.
- Eject the VirtualBox Additions disc.

- In the guest machine window, choose Devices > Shared clipboard >
Bidirectional.
Expand All @@ -58,19 +57,17 @@ using it.

nano ~/provision.sh && bash ~/provision.sh

- Reboot.
- Insert development provision script. (And later test it, not part of final product.)

- Launch Extension Manager. Open settings for Dash to Panel. On the Position
tab move the "Date menu" down to after the "System menu". Turn off visibility
for "Show Applications button".
nano ~/provision-dev.sh

- Arrange desktop icons. Consider making rows:
- Reboot.

- Home, GitKraken, machine-instructions
- Terminator, Paratext, Geany, Chromium
- Byobu, Code, Gitk, Git Cola.
- Turn off screen blanking more.

- Clean up byobu status bar (F1), turning off everything.
- Launch KWalletManager and make a kdewallet called 'kdewallet'.

- Arrange desktop icons if helpful.

- Optionally edit basebox version file at `~/machine-info.txt`.
"Installed from" can state the installation media used to create the machine.
Expand All @@ -86,26 +83,34 @@ using it.
sudo apt-get update &&
sudo apt-get --assume-yes autoremove &&
sudo apt-get --assume-yes clean &&
sudo apt-get distclean &&
Comment thread
marksvc marked this conversation as resolved.
sudo du -sh /var/lib/apt/lists &&
sudo rm -v /etc/ssh/ssh_host_* &&
sudo truncate --size 0 /etc/machine-id &&
ls -l /etc/machine-id &&
df -h / &&
cat /dev/zero > ~/zeros; sync; ls -lh ~/zeros; rm -v ~/zeros
```

- Power off.
- Clear clipboard history.

- Shutdown.

## Generate and publish product

- Export VM .box file and prepare to test the result. This may take 30 minutes.
The `--base` argument is the name of the base machine in virtualbox manager.
Edit the value VERSION in the first line below before running.
First edit SOURCE_NAME to match the name of the base machine in VirtualBox Manager,
and VERSION.

```
export BOX="sfdev" && export VERSION="1.2.0" &&
date && vagrant package --base ${BOX}-base --output ${BOX}-${VERSION}.box &&
date && ls -lh ${BOX}-${VERSION}.box &&
sha256sum ${BOX}-${VERSION}.box | tee --append "${BOX}".json &&
date && mkdir test && tee test/Vagrantfile <<END &&
VERSION="1.3.0" && SOURCE_NAME="sfdev-base-kub2404" &&
BOX="sfdev" && OUTPUT_NAME="${BOX}-${VERSION}.box" &&
date -Is && vagrant package --base "${SOURCE_NAME}" --output "${OUTPUT_NAME}" &&
date -Is && ls -lh "${OUTPUT_NAME}" &&
sha512sum "${OUTPUT_NAME}" | tee --append "${OUTPUT_NAME}".sha512 &&
date -Is && mkdir test && tee test/Vagrantfile <<END &&
Vagrant.configure("2") do |config|
config.vm.box = "../${BOX}-${VERSION}.box"
config.vm.box = "../${OUTPUT_NAME}"
config.vm.provider "virtualbox" do |vb|
vb.gui = true
vb.cpus = 2
Expand All @@ -114,15 +119,11 @@ export BOX="sfdev" && export VERSION="1.2.0" &&
end
END
cd test &&
vagrant up; date
vagrant up; date -Is
```

- Test the result. Such as by adding secrets,
[launching](https://github.com/sillsdev/web-xforge/wiki/Debugging) backend,
frontend, and browser, and in VSCode attaching via
"Attach to frontend",
"Attach to backend dotnet application", and
"Attach to backend realtime server".
- Test the result. Such as by adding secrets and running
`cd ~/code/web-xforge/src/SIL.XForge.Scripture && dotnet run`.

- Clean up box test machine. In the `test` directory, run the following.
The `vagrant box remove` command removes the internally stored copy of the
Expand All @@ -132,7 +133,7 @@ END
```
vagrant halt &&
vagrant destroy &&
vagrant box remove "../${BOX}-${VERSION}.box" &&
vagrant box remove "../${OUTPUT_NAME}" &&
cd .. &&
rm test -rf
```
Expand Down
Loading
Loading