Staging - WikipediaLibrary/TWLight GitHub Wiki

We have a staging environment hosted adjacent to the production site at https://twlight-staging.wmflabs.org/.

Staging uses a copy of the production database and in most respects behaves like the Production tool. Deploying changes to the staging environment requires SSH access to the staging server. These steps assume you have a working twlight stack.

To test your changes on the Staging site, to test against live data or in a close-to-production environment, simply (force) push your commits to the staging branch (e.g. git push origin <local_branch_name>:staging --force).

Travis CI will build the staging branch (see branch builds here) and publish it to the branch_staging tag on https://quay.io/repository/wikipedialibrary/twlight. The staging server polls for new images with this tag every few minutes.

If you would like to test your changes in this environment and don't have push permissions for the repository, please let a member of the TWL team know and we can pull your code down.

Fix divergent git history on staging

The chances are good that the git revision history on the staging server will be left in an inconsistent state due to forced pushes. The simplest fix is to reset the local branch and manually deploy the updated docker images.

  • shell in: ssh <staging.fqdn>
  • start a tmux session tmux
    • in case your SSH session is interrupted/broken, shell back in and tmux attach
  • become the twlight user sudo su twlight
  • go the project directory cd /srv/TWLight
  • verify the local and remote staging branches have diverged git status
    • will display a message like Your branch and 'origin/staging' have diverged
  • perform a hard reset of the local branch git reset --hard origin/staging
  • deploy the changes to docker swarm docker stack deploy -c docker-compose.yml -c docker-compose.staging.yml staging

Run migrations on staging

You may now try to run migrations docker exec -it $(docker ps -q -f name=staging_twlight) bin/virtualenv_migrate.sh

The chances are good that the database will break when overwriting staging from a new branch due to incompatible migration graphs. The simplest fix is to restore a backup of production data in order to test your changes against real state.

  • determine the most recent backup in the production directory: ls -tr /data/project/prod/ | tail -n 1
  • copy that file into the staging folder: sudo cp /data/project/prod/<filename> /data/project/staging/
  • become the twlight user sudo su twlight
  • restore the backup docker exec -it $(docker ps -q -f name=staging_twlight) /app/bin/twlight_restore.sh /app/backup/<filename>

The restore script imports the database and files and then runs migrations, so the environment should be working correctly assuming that you don't see any console errors.

⚠️ **GitHub.com Fallback** ⚠️