Skip to content

API development instances

andrea rota edited this page Apr 18, 2023 · 4 revisions

During active development, we may use a dev API instance running on an Azure VM instance.

We used to name these VMs as marxanXY where XY was a number (fully made up, except when we spun up a 64-cores VM for load testing and we called it marxan64) during the first phase of development - we can stick to the same convention.

We create the VM via a CLI command such as the one below.

The specific CLI options in the example below have been verified with the azure-cli=2.47.0-1~bullseye version of the azure-cli APT package for Debian: handling of CLI options related to OS images has changed recently and older versions of the azure-cli tool may require tweaks to the suggested CLI command.

az vm create \
  -n marxanXY \
  -g <resource_group> \
  --image Ubuntu2204 \
  --admin-username azureuser \
  --public-ip-address-dns-name marxanXY \
  --size Standard_D8d_v5 \
  --generate-ssh-keys \
  --location <location> \
  --data-disk-sizes-gb 1000 \
  --data-disk-delete-option Delete \
  --tags Project=Marxan Environment=DEV OwnedBy=Vizzuality

Please remember to check about resource allocation/costs, resource group and subscription to use, tags, etc. with the owners of the Azure tenant under which the VM is being created.

The test API instance's source is in /opt/marxan/Projects/marxan-cloud/marxan-cloud and we run it via docker compose (make start-api from the project root) .

Caddy is used as reverse proxy in front of the API service.

To access from command-line:

ssh azureuser@marxanXY.<azurelocation>.cloudapp.azure.com

# We keep a tmux session open with the docker-compose client that is used to run this project
# List tmux sessions - if they aren't named you may need to attach to one and check if it's the right one
tmux ls

# Attach to a tmux session
tmux attach-session -t <session name/id> -d

# Detach session with Ctrl + b, then d.

In order to deploy, use git pull to pull the latest changes.

VM setup notes

  • basic packages:

apt install git tmux make zsh btrfs-progs jq

  • a large disk is mounted as /opt/marxan

From /etc/fstab:

PARTUUID="<partition UUID>" /opt/marxan     auto    defaults,nofail 0       2

/etc/caddy/Caddyfile is very simple; this will also automatically provision a Let's Encrypt TLS certificate:

marxanXY.<azurelocation>.cloudapp.azure.com {
  reverse_proxy localhost:3030
}

Stop Docker, then mv /var/lib/docker /opt/marxan/var-lib-docker && ln -s /opt/marxan/var-lib-docker /var/lib/docker, then restart Docker

  • Clone the Marxan repository:

mkdir -p /opt/marxan/Projects/marxan-cloud && cd /opt/marxan/Projects/marxan-cloud && git clone https://github.com/Vizzuality/marxan-cloud

  • Start the Marxan services

cd /opt/marxan/Projects/marxan-cloud/marxan-cloud && make start-api

  • Restore full data from latest dump:

make restore-dumps