diff --git a/docker-compose.yml b/docker-compose.yml index 91d7169..15e0f2d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,9 +4,9 @@ services: build: context: . dockerfile: scripts/db/Dockerfile - image: mariadb environment: - - MYSQL_ROOT_PASSWORD=toor + - POSTGRES_PASSWORD=toor + - POSTGRES_USER=root web: build: context: . diff --git a/misc/create_dummydata.py b/misc/create_dummydata.py index f4aa513..f1c16df 100644 --- a/misc/create_dummydata.py +++ b/misc/create_dummydata.py @@ -1,4 +1,4 @@ -import sys +import sys import os import time import random @@ -10,12 +10,13 @@ from django.conf import settings django.setup() #django related stuff should be imported below this from members.models import Member, MemberRequest +from infoscreen.models import Rotation, ExternalImageInfoItem, InfoInstance from misc.namegenerator import generate_names MEMBERAMOUNT = 30 MEMBERREQUESTAMOUNT = 3 -print ("""THIS SCRIPT WILL GENERATE DUMMY VALUES TO DATABASE -AND SHOULD __NEVER__ BE RUN ON PRODUCTION. +print ("""THIS SCRIPT WILL GENERATE DUMMY VALUES TO DATABASE +AND SHOULD __NEVER__ BE RUN ON PRODUCTION. IF YOU ARE ON PRODUCTION ABORT (ctrl-c) IMMEDIATELY!!!! CONTINUING IN 10 SECONDS""") time.sleep(10) @@ -36,6 +37,13 @@ for i in range(MEMBERAMOUNT): AYY=ayy, jas=jas) - -for m in list(Member.objects.all())[:5]: - MemberRequest.objects.create(member=m) +i_item = ExternalImageInfoItem.objects.create( + name="Heavy", + url="https://i.imgur.com/XXSSqDG.gif" +) +rot = Rotation.objects.create(name="Demo") +inst = InfoInstance.objects.create( + rotation=rot, + item=i_item, + duration=20.0 +) diff --git a/requirements.txt b/requirements.txt index aa10343..6b4f74d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,6 @@ decorator==4.0.9 Django==1.9 ipython==4.2.0 ipython-genutils==0.1.0 -mysqlclient==1.3.7 pexpect==4.1.0 pickleshare==0.7.2 ptyprocess==0.5.1 @@ -18,3 +17,4 @@ djangorestframework==3.5.3 coverage==4.3.4 django-nose==1.4.4 uWSGI==2.0.14 +psycopg2==2.7.1 diff --git a/scripts/autoinstall.sh b/scripts/autoinstall.sh index b1d6f09..1b99999 100755 --- a/scripts/autoinstall.sh +++ b/scripts/autoinstall.sh @@ -28,30 +28,24 @@ fi echo "Building db container..." docker-compose -p "$PROJECT" build db || { echo "Failed to build db!"; exit 1; } - -echo "Starting db container..." -docker-compose -p "$PROJECT" up -d db || { echo "Failed to start db container!"; exit 1; } - -echo "Waiting 10 seconds..." -sleep 10 - -echo "Importing database settings..." -docker-compose -p "$PROJECT" exec -T db sh /db/install.sh || { echo "Failed to import database settings!"; exit 1; } - -echo "Shutting down db container..." -docker-compose down db +docker-compose -p "$PROJECT" up -d db echo "Copying settings..." -cp sikweb/settings-docker-sample.py sikweb/settings.py || { echo "Failed to copy settings!"; exit 1; } +cp -n sikweb/settings-docker-sample.py sikweb/settings.py || { echo "Failed to copy settings!"; exit 1; } echo "Building web container..." docker-compose -p "$PROJECT" build web +sleep 10 echo "Running manage.py commands..." docker-compose -p "$PROJECT" run web python manage.py migrate --noinput || { echo "Failed to apply migrations!"; exit 1; } docker-compose -p "$PROJECT" run web python manage.py createdefaultadmin || { echo "Failed to create default admin user."; } +echo "generating dummydata" +docker-compose -p "$PROJECT" run web python /code/misc/create_dummydata.py || { echo "Failed to create default admin user."; } + +echo "Starting web container..." +docker-compose -p "$PROJECT" up -d web || { echo "Failed to start containers!"; exit 1; } + -echo "Starting all containers..." -docker-compose -p "$PROJECT" up -d || { echo "Failed to start containers!"; exit 1; } echo "Done." diff --git a/scripts/db/Dockerfile b/scripts/db/Dockerfile index d1bcd2e..4bd2dee 100644 --- a/scripts/db/Dockerfile +++ b/scripts/db/Dockerfile @@ -1,5 +1,2 @@ -FROM mariadb:latest -RUN mkdir -p /db -WORKDIR /db -ADD scripts/db/init.sql /db/ -ADD scripts/db/install.sh /db/ +FROM postgres:9.6 +COPY scripts/db/init.sql /docker-entrypoint-initdb.d/init.sql diff --git a/scripts/db/init.sql b/scripts/db/init.sql index 968096b..acd8ab4 100644 --- a/scripts/db/init.sql +++ b/scripts/db/init.sql @@ -1,7 +1,8 @@ -DROP USER IF EXISTS 'sik'; -FLUSH PRIVILEGES; -CREATE USER 'sik'@'%' IDENTIFIED BY 'password123'; -CREATE DATABASE IF NOT EXISTS sik DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci; -GRANT ALL PRIVILEGES ON `sik\_%` . * TO 'sik'@'%' IDENTIFIED BY 'password123'; -GRANT ALL PRIVILEGES ON sik.* TO 'sik'@'%'; - +DROP ROLE IF EXISTS sik; +CREATE USER sik WITH PASSWORD 'password123'; +ALTER ROLE sik SET client_encoding TO 'utf8'; +ALTER ROLE sik SET default_transaction_isolation TO 'read committed'; +ALTER ROLE sik SET timezone TO 'UTC'; +CREATE DATABASE sik + ENCODING 'UTF8' + OWNER sik; diff --git a/scripts/db/install.sh b/scripts/db/install.sh deleted file mode 100755 index 53419b4..0000000 --- a/scripts/db/install.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -set -e -mysql -u root -ptoor < /db/init.sql diff --git a/sikweb/settings-docker-sample.py b/sikweb/settings-docker-sample.py index 654de10..16d06cd 100644 --- a/sikweb/settings-docker-sample.py +++ b/sikweb/settings-docker-sample.py @@ -97,12 +97,12 @@ WSGI_APPLICATION = 'sikweb.wsgi.application' DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.mysql', + 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'sik', 'USER': 'sik', 'PASSWORD': 'password123', 'HOST': 'db', - 'PORT': '3306', + 'PORT': '5432', 'TEST': { 'NAME': 'sik_test', },