This project has been retired! Find out more.
If you are on macOS then make sure you have Homebrew installed first. Then:
brew tap vapor/homebrew-tap
brew update
brew install vapor
brew install sqlite3
Do a git clone of this repo.
To create the files need
vapor xcode
Open the xcodeproj file in Xcode, check that "Run -> My Mac" is selected as the target and then hit "Play".
Check it is running in your browser at http:://localhost:8080
.
The database will be created automatically when you run the project.
If you want to run the project in Xcode, then you can use a SQLite database. The base Config/fluent.json is already setup to use the sqlite driver by default. Docker will use the driver defined in Config/docker/fluent.json, which is set to MySQL by default.
To seed the tables:
vapor run seed
If you change Package.swift then use vapor update
to download dependencies.
You will need Docker (at least version 17).
This setup uses docker-compose to create 4 containers:
database
- a standard mariadb imageredis
- a standard redis imageweb
- our vapor image that serves the websiteworker
- our vapor image that runs multiple job threadscd docker
docker build -t apptitude/vapor vapor
./build
docker-compose up -d redis database
docker-compose ps
docker-compose logs -ft <container_id>
docker-compose up -d web
docker-compose up -d worker
http://localhost
or your docker VM IP addressdocker-compose run worker run seed --env=docker
./build
will stop, compile and start.docker-compose exec database mysql -u root -p grader
docker-compose exec worker bash
and then use the vapor command vapor run submission X
where X
is your submission id.Compile our custom Vapor image (required before we start using docker run apptitude/vapor
):
docker build -t apptitude/vapor vapor
Login to a Vapor-enabled container (bash prompt, useful for exploring):
docker run -it --volume=$PWD/..:/app --entrypoint /bin/bash apptitude/vapor
Run Vapor commands (e.g. vapor build
):
docker run -it --volume=$PWD/..:/app apptitude/vapor build
In general, you can run any Vapor command (e.g. vapor XXX
):
docker run -it --volume=$PWD/..:/app apptitude/vapor XXX --env=docker
Run a one-off worker:
docker run -it --volume=$PWD/..:/app apptitude/vapor run worker --env=docker
This was tested on AWS, to a Ubuntu Xenial 16.04 (20170414) (ami-8fcc75ec) instance. The security group should have http and ssh open.
ssh
into your newly created instance. (Note: the user to login with for Ubuntu images is ubuntu
.)
Install docker
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install -y --allow-unauthenticated docker-ce
sudo systemctl status docker
sudo usermod -aG docker ${USER}
and check it is working docker
Install docker-compose
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo curl -o /usr/local/bin/docker-compose -L "https://github.com/docker/compose/releases/download/1.15.0/docker-compose-$(uname -s)-$(uname -m)"
sudo chmod +x /usr/local/bin/docker-compose
and check it is working docker-compose -v
Create the /app directory
sudo mkdir /app
sudo chown ubuntu:ubuntu /app
Sync the files (e.g. copy from your local machine to the instance). See ./deploy for an example.
ssh
back into the instance, and build/start the docker services
cd /app/docker
docker build -t apptitude/vapor vapor
docker run -it --volume=$PWD/..:/app apptitude/vapor build
docker-compose up -d
Check everything looks ok on the logs.
docker-compose logs -ft
Make a backup first
ssh grader
cd /app/docker
docker-compose exec database bash
mysqldump -u root -p grader > dump.sql
[Ctrl-D]
Copy backup down to localhost
docker cp `docker-compose ps -q database`:/dump.sql /app/dump.sql
[Ctrl-D]
scp grader:/app/dump.sql ./
Make database changes (from aws) -- if required
ssh grader
cd /app/docker
docker-compose exec database mysql -u root -p grader
[Ctrl-D]
(and do you stuff!)
Resync files (logout to localhost first)
./deploy
Rebuild the worker container (if required)
ssh grader
cd /app/docker
docker-compose up -d --no-deps --build worker
[Ctrl-D]
Use these commands on running containers to modify the resource allocation.
docker update --cpus=".25" <containerid> # Guarantee that a container has at least 25% of 1 cpu core
docker update -c 512 <containerid> # Give 50% share of the CPU to a container (512 out of 1024)
docker update -m 750M <containerid> # Limit memory to 750MB for a container