Page MenuHomePhabricator

Update the Wikilink production server to use Docker Swarm
Closed, ResolvedPublic

Description

The Wikilink tool is currently deployed via Docker Compose. We would like to move to Docker Swarm as the means by which the tool is deployed.

We set up the Staging environment for the Wikilink tool with Docker Swarm earlier in the year, but didn't migrate this to the Production server. The steps for deploying via Docker Swarm are documented at https://github.com/WikipediaLibrary/externallinks/wiki/Staging, along with information about how this integrates with GitHub Actions.

Upgrading the Production server to use Docker Swarm is the next step. This will have the additional benefit of helping with T250084, and help us automate deployments.

Steps:

  • stop eventstream and nginx containers on production (eventstream was dead already)
  • backup current production database, pull a copy down to my local machine
  • shutdown current production instance
  • delete any instances besides current production and staging instances
  • create a new production instance
  • go through the server setup steps
  • upload backup to new server
  • restore the backup
  • update proxy in horizon

Acceptance criteria

  • Production server is live, deployed with Docker Swarm

Event Timeline

Samwalton9-WMF renamed this task from Investigate Docker Swarm for Wikilink production server to Update the Wikilink production server to use Docker Swarm.Aug 6 2020, 9:48 AM
Samwalton9-WMF triaged this task as High priority.
Samwalton9-WMF updated the task description. (Show Details)

Since we're changing environment information, it might make sense to bundle this change with T258144.

@Scardenasmolinar This is priority when you're ready to pick up a new ticket. Thanks!

I created another instance and launched Docker Swarm on https://wikilink-prod.wmflabs.org/. What would be the next best steps? Should we copy the data from the old production database into this new deployment and then change the DNS of the new deployment to https://wikilink.wmflabs.org/? Also, I am using the staging area event stream, since I am not sure how to build the master event stream, so any help on this would be great.

Should we copy the data from the old production database into this new deployment and then change the DNS of the new deployment to https://wikilink.wmflabs.org/?

That seems sensible!

I am using the staging area event stream, since I am not sure how to build the master event stream, so any help on this would be great.

Could you elaborate on this problem? I'm not sure I understand.

Could you elaborate on this problem? I'm not sure I understand.

Sure. In GitHub Actions, every time a push is made to staging or master, the Docker images are pushed to DockerHub, although I can't find the image for the event stream master image. I'm going to need to do some testing to see why that is and when I get that working, I can change the configuration in the docker-compose.production.yml file. If anyone knows how to upload the master branch's event stream image, feel free to chime in!

We were just discussing backups to make this change. At the moment they're being generated via a weekly crontab which fires mysql_backup.sh - a file that I only created on Production and didn't put in the repository. Re-scoped T254327 to address this in the future..

Sorry for being slow to the party here: It looks like the GitHub actions haven't been setup to build the event stream images. Aaron started out trying to automate this in travis, so it's possible those older images are from those attempts. I'd be happy to finish out that workflow to actually build and push all of the images related to the project.

I'd be happy to finish out that workflow to actually build and push all of the images related to the project.

That would be great, thanks! I am not sure how to do this, since I am new to GitHub Actions and don't have a lot of Travis experience.

I realize that I need to factor out the wait for db code from the gunicorn entry point so that it can be used for the eventstream command as well

Wrinkle:

github actions throws away local state between jobs, including locally built docker images. There is a data persistence feature that we're now using to upload/download those images, but it adds a fair amount of built time
https://github.com/WikipediaLibrary/externallinks/commit/5906f200db3852ed9387c15bc72aa63e0323963d
we should probably streamline that to a single test and push job that uses shell conditionals to guard the docker hub publish steps, as it should run at least 2 minutes faster per commit and be a more efficient use of donated resources.

I realized that I forgot to gzip those images which would explain the log upload/download time. I updated the github action to take care of that.
I also updated the readme with a gh action badge instead of travis and turned off the travis integrations for externallinks so we don't have 2 cicd systems running on the same pushes.

We've made big progress on this. The github actions are working as expected, and admin error emails are in place. I still need to:

  • do a little cleanup on the logging config to make it stop writing directly to logfiles on the host
  • add automated backups
  • add auto image pull and deploy

Those blockers are merged in, so now we're just wrapping the django upgrade, which is the first thing we'll deploy to the production swarm.

Django upgrade is done. This looks ready to deploy to a new production system.
My plan:

  • Backup current production database, pull a copy down to my local machine.
  • shutdown current production instance
  • delete any instances besides current production and staging instances
  • create a new production instance
  • go through the server setup steps
  • upload backup to new server
  • restore the backup.

If something goes really sideways (which seems unlikely), we can just switch back to the current production system.
If I end up needing to do any extra steps, I'll add them to the project wiki in github.

That sounds great! Maybe in this new production environment, we should start the eventstream container with 2 replicas to make sure that if one fails, then the other will pick up where the other left off.

Now that we're not holding the container open with the old manual logging configuration, it *should* die out on error, in which case the service *should* auto heal by detecting the exit and starting a new container immediately.
If that doesn't work that way, then I've got some swarm config bugs to squash.

I could test this on staging first by restoring a backup there and watching what happens. I actually haven't validated any of the eventstream behavior in my changes so far, I just fixed the issues I saw.

Okay identified and resolved a few issues:
https://github.com/WikipediaLibrary/externallinks/pull/48

But did verify that the eventstream container is up and running now that it is configured to do something.
With an empty database, it just exits successfully and then gets fired back up by swarm since we told it we always need to have 1 up.
This is all expected behavior, so I think we're good on that front.

Okay, I added checkboxes for deployment steps into the description. I'll check them off as I progress on this deployment.

Okay, deployment complete, with only one hiccup:
docker-compose version 1.27.4, build 40524192 has a bug in the config subcommand that causes it to output depends_on elements as a dict instead of a list. This breaks our deployment. docker-compose version 1.27.1, build 509cfb99 (the latest version we previously deployed) works fine. I added a note about this to the debian server setup in the project wiki

Hooray!

docker-compose version 1.27.1, build 509cfb99 (the latest version we previously deployed) works fine

Just to clarify, does that mean we're using this older version, or working around the bug in the new version?

We're using the older version for now.