Go to file
James Leighton e13e413915 fix twitter link 2018-09-12 19:56:11 +01:00
compose Reduce workers by one 2018-05-02 14:25:14 +01:00
config update libraries 2018-09-11 14:07:07 +01:00
docs Moved all files up one folder 2017-01-04 18:11:25 +00:00
logs Add in place holder files 2018-01-26 13:20:21 +00:00
mhackspace fix twitter link 2018-09-12 19:56:11 +01:00
requirements update libraries 2018-09-11 14:07:07 +01:00
utility Moved all files up one folder 2017-01-04 18:11:25 +00:00
.drone.yml Updated deploy steps 2018-01-25 21:45:13 +00:00
.gitignore Ldap server integration 2018-05-02 13:57:08 +01:00
.travis.yml Added support for Circle CI tests (#16) 2017-01-26 09:03:03 +00:00
CONTRIBUTORS.txt Moved all files up one folder 2017-01-04 18:11:25 +00:00
COPYING Moved all files up one folder 2017-01-04 18:11:25 +00:00
LICENSE Moved all files up one folder 2017-01-04 18:11:25 +00:00
README.org Django 2 2018-09-08 10:15:22 +01:00
circle.yml Updated circle config to be Python 3 2017-01-26 13:30:14 +00:00
docker-compose.yml celery integration 2017-08-15 07:26:06 +01:00
env.example Twitter reminder support 2018-05-08 21:49:13 +01:00
live.yml Ldap server integration 2018-05-02 13:57:08 +01:00
local.yml Ldap server integration 2018-05-02 13:57:08 +01:00
manage.py Moved all files up one folder 2017-01-04 18:11:25 +00:00
pytest.ini Moved all files up one folder 2017-01-04 18:11:25 +00:00
requirements.txt Added support for Circle CI tests (#16) 2017-01-26 09:03:03 +00:00
setup.cfg Moved all files up one folder 2017-01-04 18:11:25 +00:00
stage.yml Ldap server integration 2018-05-02 13:57:08 +01:00
wsgi_bjoern.py Simplify config fix wiki styles. 2018-02-03 19:21:12 +00:00

README.org

https://cdn.rawgit.com/maidstone-hackspace/administration/2ede7cb1/images/hackspace-banner.png

Maidstone Hackspace website

https://pyup.io/repos/github/maidstone-hackspace/maidstone-hackspace-website/shield.svg

Repository for the maidstone hackspace website, feel free to fork this site for your own Hackspace.

Requirements

Before getting started make sure you have git, docker and docker-compose installed on your machine. The simplest way to setup this site is to use docker-compose so please install that from this site https://docs.docker.com/engine/installation/ and make sure the quick start guide works https://docs.docker.com/machine/get-started/ then you can use the commands below to test and make changes.

Setup

Steps to get the site running for the first time

First clone the project

To get started checkout the project to your machine, with the command below.

git clone https://github.com/maidstone-hackspace/maidstone-hackspace-website.git

Build your containers to install the sites requirements

Once checked out build your containers locally you only need to do this when first start or if requirements change.

docker-compose -fdev.yml build

Start your new containers containing a database and django

docker-compose -fdev up

Test django is serving pages http://127.0.0.1:8180

Run migrations to setup the database

To run django commands just prefix them with docker-compose -f dev.yml run django

docker-compose -f dev.yml run --rm django python manage.py makemigrations
docker-compose -f dev.yml run --rm django python manage.py migrate

Create the admin user.

Once created you can login at http://127.0.0.1:8180/trustee

docker-compose -f dev.yml run --rm django python manage.py createsuperuser

Generate dummy data

docker-compose -f dev.yml run --rm django python manage.py generate_test_data

Migrations / Managing default data

If you want to export some data you entered into the admin area you can use dumpdata and loaddata to export and import.

docker-compose -fdev.yml run --rm django python manage.py dumpdata feeds > mhackspace/feeds/fixtures/defaults.json
docker-compose -fdev.yml run --rm django python manage.py loaddata mhackspace/feeds/fixtures/defaults.json

Django Commands

docker-compose -fdev.yml run --rm django python manage.py list_subscriptions

Render image variations, if you change the images sizes this will be needed

docker-compose -fdev.yml run --rm django python manage.py rendervariations 'blog.Post.image' --replace

Api

import requests 

url = 'http://127.0.0.1:8180/api/v1/rfidAuth/'
data = {
  'rfid': '4996',
  'device': '7bff6053-77ef-4250-ac11-8a119fd05a0e'
}

# client = RequestsClient()
response = requests.post(
    'http://127.0.0.1:8180/api/v1/rfidAuth/',
    data={'rfid': '238e', 'device': 'e8f27231-8093-4477-8906-e5ae1b12dbd6'})
#requests.get(url)
return response.status_code
200

Server

Example service setup for website under docker, nginx in a container forwarding traffic to uwsgi.

nginx web server

docker volume create --name=sockets
docker run --name=nginx -d \
    -v /etc/nginx/sites-enabled/:/etc/nginx/sites-enabled/ \
    -v /etc/letsencrypt/:/etc/letsencrypt/ \
    -v /var/www/:/var/www/ \
    -v sockets:/data/sockets -p 80:80 -p 443:443 olymk2/nginx

letsencrypt cert setup

Setup / create new certs

letsencrypt certonly --renew --webroot -w /var/www/.well-known -d stage.maidstone-hackspace.org.uk
letsencrypt certonly --webroot -w /var/www/.well-known -d stage.maidstone-hackspace.org.uk

Automation of renewal process create a file called /etc/cron.monthly/letsencrypt-renew.sh and make it executable with chmod +x, then place your above commands in the file like in the example below.

#!/bin/bash
letsencrypt certonly --webroot --renew-by-default --agree-tos -w /var/www/.well-known -d stage.maidstone-hackspace.org.uk

Postgres tips

Connect to the database inside container to run sql commands.

docker-compose -fstage.yml run --rm postgres psql -U postgres

Backups

Create a backup file with today's date

    docker exec -t {CONTAINER_NAME} pg_dump -Fp -c -U postgresuser > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql
    docker exec {CONTAINER_NAME} bash -lc 'pg_dump --format custom vmdb_production' > dump_`date +%d-%m-%Y"_"%H_%M_%S`.pgdata

Import previously made backup

docker exec -i -u {USER} {CONTAINER_NAME}  pg_restore --verbose --no-acl --no-owner --clean --role=postgres -Upostgres --dbname={DATABASE_USER} < dump_31-01-2018_13_09_24.pgdata
  docker exec -i -u {USER} {CONTAINER_NAME} pg_restore -C --clean -d {DATABASE_USER} < dump_31-01-2018_13_09_24.pgdata
  cat dump_27-01-2018_14_26_09.sql | docker exec -i {CONTAINER_ID} psql -U postgres

letsencrypt config

  letsencrypt certonly --renew --webroot -w /var/www/.well-known -d maidstone-hackspace.org.uk -d maidstone-hackspace.org.uk -d www.maidstone-hackspace.org.uk

CMD ["nginx", "-g", "daemon off;"] sudo chmod -R a+rX static/

(let ((default-directory "/docker:hackdev_django_1:/app"))
  (python-shell-make-comint "python manage.py shell" "Python" 'show))

Test

(setq python-shell-interpreter "/docker:hackdev_django_1:/usr/local/bin/python")
(setq python-environment-directory "/docker:hackdev_django_1:/")
/docker:hackdev_django_1:/