-
Notifications
You must be signed in to change notification settings - Fork 128
Backend
Before the web application can be started, a couple of user files need to be prepared and copied to the right places.
If you are running MPCAutofill for the first time, you need to set up a Google Service Account first. Go to https://console.developers.google.com/ and create a new project. Then, navigate to Service Accounts, create a new one, go to "Manage Keys", add a new key while choosing the JSON format. Finally, copy the downloaded key into the sub-folder MPCAutofill/client_secrets.json.
Also, make sure your Google Drive API is enabled. Otherwise, all drive imports will fail! You can verify this by visiting the following website with your Google project id inserted at the end of the link: https://console.developers.google.com/apis/api/drive.googleapis.com/overview?project=yourprojectid
You also need some Google Drives to be added to MPCAutofill/drives.csv. A template CSV with an example entry can be found in place. The Google Drive ID required in the CSV is the cryptic part of the Google Drive URL, usually at the end. Another example for the drives.csv could look like this:
| name | drive_id | drive_public | description |
|---|---|---|---|
| My Name | 2WmU2qeUouXmPefxYxMDHZnlsIYPe3KlqFy | "My own upside-down japanese proxies" | |
| Otto | q6iJFoJseX-xnHKLiJlRDU2aeaM6Ditvq2X | FALSE | "Otto's future-sight swamp collection" |
The public field is true by default and can be left empty. If a drive is marked non-public, its link won't be displayed on the contribution page or in the search settings popup.
This step is usually optional as the Google Scripts can be shared among installations. But if you find the client (autofill.py) not working, make sure the included Google Scripts are available at the given links. Otherwise, deploy both included scripts and update the links accordingly.
Two alternative installation methods are described in the following. At this point in time, make sure you already have set up your client_secrets.json and your drives.csv as described previously.
The easiest way to get MPCAutofill running as quickly as possible is by using Docker containers. The docker sub-folder includes all necessary scripts to automatically set up and run MPCAutofill with all its dependencies. The only tools you need are Docker and Docker-compose.
In case you are deploying to production, also make sure to put a random secret into docker/django/env.txt, e.g., by running sed -i "s/DJANGO_SECRET_KEY=.*/DJANGO_SECRET_KEY=$(openssl rand -base64 12)/g" docker/django/env.txt.
You can set up Docker and Docker-compose on a clean Ubuntu with the following instructions:
sudo apt update
sudo apt install -y docker.io docker-compose
sudo usermod -aG docker $USER
sudo reboot
Now, you can check out this repository and run the Docker scripts:
sudo apt install -y git
git clone https://github.com/chilli-axe/mpc-autofill.git
cd mpc-autofill
# At this point, configure all necessary files as described previously.
cd docker
docker-compose up
Depending on the size of your configured drives, this can take a while before the website becomes available at http://localhost:8000. Optionally, you can also pass "-d" to run all containers detached. In that case, you can later stop all containers with:
docker-compose down
You can also create an admin account for http://localhost:8000/admin, if you like:
docker-compose exec django python3 manage.py createsuperuser
Docker can also be run on Windows through virtual machines. Download Docker Desktop and follow the installation instructions on https://docs.docker.com/desktop/windows/install/. Make sure that you have virtualization instructions enabled in your BIOS/UEFI. Most other dependencies are handled by the installer.
Once you finished the Docker Desktop installation and restarted your machine, download this repository and extract it somewhere on your machine. Make sure to configure your client_secrets.json and drives.csv as described previously. Then, open the Windows Command Prompt and navigate to the extracted repository folder. Change to the docker sub-folder and run docker-compose up. After a while, MPCAutofill will become available at http://localhost:8000.

Docker-compose fails with "docker.errors.DockerException: Error while fetching server API version: (2, 'CreateFile', 'The system cannot find the file specified.')"! Your docker daemon isn't running. Just start Docker Desktop, wait for a couple of seconds, and try again.
The website just gives me "502 Bad Gateway"! The Django instance isn't ready yet, probably still scanning cards. Have a look at the docker output. Use docker-compose logs django if you started them detached.
I changed some files but it looks like Docker didn't adopt those changes! All files (including drives.csv) are part of docker images and not updated automatically. If you just changed some code, docker-compose build should be sufficient to update the images. Affected containers will be rebuild on the next docker-compose up. However, if you changed, e.g., your drives.csv, the old state might still persist in the databases (stored in "volumes"). In this case, you can either manually trigger an update with docker-compose exec django python3 manage.py import_sources followed by docker-compose exec django python3 manage.py update_database, or, in doubt, just start all over again in a clean docker environment by executing the docker_clean_all script.
The website seems to work fine but I can't generate orders! Do you have cardbacks in your Google Drive? Add a folder named "Cardbacks" to your Drive and put some cardbacks there!
If you aim to contribute to MPCAutofill or are familiar with running Django locally, you can also install MPCAutofill manually.
- Python 3.9+,
- The Python packages specified in
requirements.txtin$working_directory/MPCAutofill, - Elasticsearch 7.10.x - install natively on your machine or run in Docker,
- npm,
- A Google account.
All steps with the prefix [PROD] are only needed if you are deploying this web app in a production environment. For running the application locally or for development, you can skip these steps.
- Clone this repo somewhere on your server/local computer. This will be referred to as the
$working_directory. - If you are using an IDE to run the Django commands and are NOT using Windows: go to the
$working_directory/.rundirectory and for each XML file delete the optionSDK_HOME - Add the file
$working_directory/MPCAutofill/MPCAutofill/.envto edit any environment variables used in$working_directory/MPCAutofill/MPCAutofill/settings.py. IN ORDER TO RUN THE APP LOCALLY, YOU MUST ADDDJANGO_DEBUG=onTO THE$working_directory/MPCAutofill/MPCAutofill/.envFILE -
[PROD] In the
$working_directory, create a folder calledstaticrootfor static assets - [PROD] Deploy the Django project (I'm using DigitalOcean for Ubuntu) with a webserver (I'm using Apache) and serve static files with another webserver if you want (I was previously using nginx but now I just serve static files with Apache as well)
- Install Elasticsearch based on your OS, or with Docker (Installation Guide)
- It might make the most sense to unzip the Elasticsearch directory into your
$working_directory - Optionally, add the executables to your PATH for easy terminal access (add
location-of-package/elasticsearch-<VERSION_NUM>/binto your PATH)
- It might make the most sense to unzip the Elasticsearch directory into your
- Run Elasticsearch
- Use the executable indicated in your OS's Installation Guide, optionally running it as a daemon.
- Test that Elasticsearch is running by querying the local instance. For example:
wget -qO- http://localhost:9200/
- Set up your Google Drive credentials using a Google Drive service account. For each step, only follow the instructions for the given section, then return and complete the next step. The linked tutorial is slightly out of date, but it is the most complete tutorial around.
- Step 1 - NOTE: The project name, product name, and Application type don't matter for just running the tool locally.
- Step 2 - NOTE: The JSON file you download at the end of this step is named something slightly different from what the application expects. Make sure to rename it.
- Rename the saved JSON file to
client_secrets.jsonand move it to:$working_directory/MPCAutofill
- Update the
$working_directory/MPCAutofill/drives.csvspreadsheet with links to public Google Drives with MPC ready images- Do not edit the first row of the spreadsheet
- Heading Reference (
name= Name of Drive Owner,drive_id= 33 character Gdrive identifier,drive_public= TRUE,description= Description of what's in that drive) - Drive ID is everything after
https://drive.google.com/drive/u/0/folders/in the Gdrive link
- Install the main dependencies using a python virtual environment (this entire step is often automatically handled by your IDE)
- To initialize the environment, create the virtual environment library using
python3 -m venv $working_directory/venvFor Windows the command will bepy -m venv $working_directory\venv - Activate the environment using your OS specific command in the table found in this section of the docs: Scroll to the table
- In
$working_directorywith the virtual environment active, run the commandpip3 install -r requirements.txtto install all requirements listed in$working_directory/requirements.txt
- To initialize the environment, create the virtual environment library using
- Install the frontend dependencies and compile it with webpack
- Install npm: https://docs.npmjs.com/downloading-and-installing-node-js-and-npm.
- In
$working_directory/MPCAutofill, run the commandnpm installto install the dependencies. - In
$working_directory/MPCAutofill, run the commandnpm run buildto compile the frontend with webpack.
- In
$working_directory/MPCAutofill, run the commandpython manage.py migrateto ensure the database tables reflect any Django model changes. - In
$working_directory/MPCAutofill, run the commandpython manage.py update_dfcsto synchronise the double-faced cards table with Scryfall. - In
$working_directory/MPCAutofill, run the commandpython manage.py import_sourcesto sync sources in$working_directory/MPCAutofill/drives.csvto the database (optionally specifying a particular drive to sync with-d <drivename>) - (Elasticsearch must be running for this script to work)
In
$working_directory/MPCAutofill, run the commandpython manage.py update_databaseto populate the database with cards from the sources loaded withimport_sources -
[PROD] Deploy two Google Script according to the code specified in
autofill.pyand adjust the URLs in that script to point to your GS endpoints - (At this point elasticsearch should be running and you should be inside the virtual environment)
In
$working_directory/MPCAutofill, run the commandpython manage.py runserverto start the local Django server. - Open your web browser and go to http://127.0.0.1:8000/
Made with