hackspace/README.org

114 lines
3.9 KiB
Org Mode

[[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/][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.
#+BEGIN_SRC sh
git clone https://github.com/maidstone-hackspace/maidstone-hackspace-website.git
#+END_SRC
*** 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.
#+BEGIN_SRC sh
docker-compose -fdev.yml build
#+END_SRC
*** Start your new containers containing a database and django
#+BEGIN_SRC sh
docker-compose -fdev up
#+END_SRC
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=
#+BEGIN_SRC sh
docker-compose -f dev.yml run --rm django python manage.py makemigrations
docker-compose -f dev.yml run --rm django python manage.py migrate
#+END_SRC
*** Create the admin user.
Once created you can login at http://127.0.0.1:8180/trustee
#+BEGIN_SRC sh
docker-compose -f dev.yml run --rm django python manage.py createsuperuser
#+END_SRC
*** Generate dummy data
#+BEGIN_SRC sh
docker-compose -f dev.yml run --rm django python manage.py generate_test_data
#+END_SRC
** 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.
#+BEGIN_SRC sh
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
#+END_SRC
** Django Commands
#+BEGIN_SRC sh
docker-compose -fdev.yml run --rm django python manage.py list_subscriptions
#+END_SRC
*** Render image variations, if you change the images sizes this will be needed
#+BEGIN_SRC sh
docker-compose -fdev.yml run --rm django python manage.py rendervariations 'blog.Post.image' --replace
#+END_SRC
** Api
#+BEGIN_SRC python
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
#+END_SRC
#+RESULTS:
: 200
** Server
Example service setup for website under docker, nginx in a container forwarding traffic to uwsgi.
*** nginx web server
#+BEGIN_SRC bash
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
#+END_SRC
*** letsencrypt cert setup
Setup / create new certs
#+BEGIN_SRC bash
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
#+END_SRC
*** Backups
#+BEGIN_SRC bash
docker exec -t {CONTAINER_NAME} pg_dumpall -c -U postgres > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql
#+END_SRC