-
Notifications
You must be signed in to change notification settings - Fork 10
Debian Server Setup
Jason Sherman edited this page Aug 15, 2025
·
12 revisions
- Log into Horizon and create a new instance with image: Debian and flavour:
g3.cores4.ram8.disk20 - Attach the
wikilink-backupanddocker-data-rootvolumes to the instance - Create a web proxy to enable http access to the instance.
- Shell into the instance
- Create a swap file:
fallocate -l 8G /swapfilechmod 600 /swapfilemkswap /swapfileswapon /swapfileecho "/swapfile none swap sw 0 0">>/etc/fstab
- run the cinder configuration scripts to mount the volumes. See (https://wikitech.wikimedia.org/wiki/Help:Adding_Disk_Space_to_Cloud_VPS_instances#Cinder:_Attachable_Block_Storage_for_cloud-vps) for more info
- mount
docker-data-rootto/usr/local/docker-data - mount
wikilink-backupto/usr/local/backup
- mount
- Install docker (https://docs.docker.com/engine/install/debian)
- Create the file
/etc/docker/daemon.jsonwith the following content to configure docker to use the data volume
{
"data-root": "/mnt/docker-data"
}
- Install docker-compose (https://docs.docker.com/compose/install/) version 1.25.5.
1.
sudo curl -SL https://github.com/docker/compose/releases/download/1.25.5/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose- docker-compose versions newer than 1.25.5 have a bug in the
configsubcommand that causes it to requireresources .. cpuselements to be a number instead of a string. Docker swarm requires it to be a string instead of a number. This breaks our deployment. - docker-compose versions newer than 1.27.1 have a bug in the
configsubcommand that causes it to outputdepends_onelements as a dict instead of a list. This breaks our deployment.
- docker-compose versions newer than 1.25.5 have a bug in the
- Become root
sudo su root
- Create a shared user to manage docker services.
adduser wikilink --disabled-password --quiet ||:usermod -aG docker wikilink
- Clone the externallinks repo
cd /srvgit clone https://github.com/WikipediaLibrary/externallinks.git
- Check out appropriate branch.
cd /srv/externallinksgit checkout staging
- Copy template.env to .env, and edit to add real values.
cp template.env .envvim .env
- Set permissions.
chown -R wikilink:wikilink /srv/externallinks
- Become service user.
su wikilink
- Create a swarm.
docker swarm init
- Deploy. Note the config command which allows use of .env in swarm.
cd /srv/externallinksdocker stack deploy -c <(docker-compose config 2>/dev/null) staging
- Setup cron tasks
crontab -e- Enter the following:
# Run django_cron tasks every 5 minutes.
*/5 * * * * docker exec -t $(docker ps -q -f name=staging_externallinks) python manage.py runcrons
# Check for and apply externallinks updates every 5 minutes.
*/5 * * * * /srv/externallinks/bin/swarm_update.sh
# Prune containers and volumes weekly.
0 0 * * 0 docker system prune -a -f; docker volume rm $(docker volume ls -qf dangling=true)
Backups should happen automatically every week in the production environment.
You may exec the backup script to manually backup:
docker exec -it $(docker ps -aq -f name=staging_externallinks | head -n 1) bin/backup.sh
To restore a backup, exec the restore script with the desired backup as the first and only argument:
docker exec -it $(docker ps -aq -f name=staging_externallinks | head -n 1) bin/restore.sh backup/202009181532.tar.gz
-
watch -n 30 docker logs -f $(docker ps -a -q -f name=<staging_migrate> | head -n 1)- watch the docker logs for the container at the top of the given service name at an interval of 30 seconds -
docker ps- lists all running containers -
docker service ls- lists all services -
docker exec -it $(docker ps -aq -f name=staging_externallinks | head -n 1) bash -c "date --rfc-3339=seconds && echo 'select timestamp from links_linkevent order by timestamp desc limit 1;' | python manage.py dbshell"- show current timestamp and the latest event timestamp
- The workflow performs two distinct sets of operations – testing and pushing.
-
Pushis permitted only when the tests pass and the commit is performed on certain branches (staging and master). -
Pushtags two images (externallinks and eventstream) and pushes them to Docker Hub. - We tag the same image twice, once with the branch name and once with the sha of the commit. This allows us to revert back to a previous image since images with branch names as their tags are overwritten on Docker Hub.
- We use GitHub secrets to store our secrets.
DOCKER_USERNAMEandDOCKER_PASSWORDare the credentials of the shared user:wikipedialibrarybot