Browse Source

fixed docker

Roberto Berto 4 years ago
parent
commit
3e91bd43df

+ 7 - 4
Dockerfile

@@ -5,13 +5,16 @@ WORKDIR /code
 COPY requirements.txt /code/
 RUN pip install -r requirements.txt
 COPY vycontrol/ /code/
-
+COPY vycontrol/vycontrol/settings_example/ /code/vycontrol/settings_available/
 
 WORKDIR /code
-RUN python3 manage.py migrate
+RUN python3 manage.py makemigrations config --settings=vycontrol.settings_available.production 
+RUN python3 manage.py makemigrations accounts --settings=vycontrol.settings_available.production 
+RUN python3 manage.py makemigrations --settings=vycontrol.settings_available.production 
+RUN python3 manage.py migrate --settings=vycontrol.settings_available.production 
+RUN python3 manage.py createcachetable --settings=vycontrol.settings_available.production 
 
-# Server
 EXPOSE 8000
 STOPSIGNAL SIGINT
 ENTRYPOINT ["python", "manage.py"]
-CMD ["runserver", "0.0.0.0:8000"]
+CMD ["runserver", "--settings=vycontrol.settings_available.production", "0.0.0.0:8000"]

+ 36 - 11
README.md

@@ -29,27 +29,49 @@ VyControl can be a web gui for multiple VyOS installation in a datacenter. Each
 # Install instructions 
 
 * download [VyOS](https://www.vyos.io/) Rolling Release, since VyControl needs the latest VyOS API.
-* for your security edit SECRET_KEY in inside Django settings/production.py and change to something random, maybe using 
+* configure VyOS-API according VyOS documentation
+
+## Docker
+latest VyControl is being autobuilt at dockerhub https://hub.docker.com/r/robertoberto/vycontrol
+
+
+your configuration will be mounted on Docker to /etc/vycontrol/production.py
+```
+mkdir /etc/vycontrol
+cd /etc/vycontrol
+wget https://raw.githubusercontent.com/vycontrol/vycontrol/master/vycontrol/vycontrol/settings/production.py
+````
+
+now edit production.py:
+* ALLOWED_HOSTS currently 127.0.0.1 is ok for tests
+* for tests you don't need to edit EMAIL settings, but forget password will not work
+* sqlite is ok for tests, but you can change to MySQL/PostgreSQL. 
+* SECRET_KEY edit to anything random, you can use openssl for example:
+
 ```
 openssl rand -hex 32
 ```
 
-
-## by dockerhub
-latest VyControl is being autobuilt at dockerhub https://hub.docker.com/r/robertoberto/vycontrol
+now download latest docker image:
 ```
 docker pull robertoberto/vycontrol
+```
+
+
+run docker:
+```
 docker run -p 8000:8000 -t robertoberto/vycontrol
-access http://127.0.0.1:8000
 ```
 
-## by docker composer
+now you can access http://127.0.0.1:8000
 
-Right now we are using db.sqlite3, but I used composer so we can change to mySQL if needed.
+
+## by docker composer
+Right now we are using db.sqlite3, you can edit composer and to change to mySQL/PostgreSQL if needed.
 
 ```
 docker-compose build
-docker-compose  up
+docker-compose up
 ```
 
 ## manual install instructions
@@ -63,13 +85,16 @@ pip3 install -r requirements.txt
 
 ### setup initial database
 ```
+source env/bin/activate
 cd vycontrol
-python3 manage.py --settings=vycontrol.settings.production migrate
+python3 manage.py migrate --settings=vycontrol.settings_available.production
 ```
 
 ### run webserver
 ```
-python3 manage.py  --settings=vycontrol.settings.production runserver
+source env/bin/activate
+cd vycontrol
+python3 manage.py runserver --settings=vycontrol.settings_available.production 0.0.0.0:8000
 ```
 
 ## access webpage
@@ -78,7 +103,7 @@ http://127.0.0.1:8000/
 
 ## setup vyos new instance
 * click on *Add new instance*
-* configure vyos services like explained here https://docs.vyos.io/en/latest/appendix/http-api.html
+* configure vyos services like explained here https://docs.vyos.io/
 * click on *List Instances*
 * click on *Test Connection*
 

+ 2 - 0
docker-compose.yml

@@ -2,6 +2,8 @@ version: "2.2"
 services:
   django:
     container_name: vycontrol
+    volumes:
+      - /etc/vycontrol/settings_available:/code/vycontrol/settings_available
     build:
       context: .
       dockerfile: Dockerfile

+ 3 - 2
vycontrol/accounts/views.py

@@ -39,8 +39,9 @@ def index(request):
         if 'username' in request.POST and 'password' in request.POST:
             user = User.objects.create_superuser(username=request.POST['username'], email='', password=request.POST['password'])
             user.save()
-            return redirect('instances')
- 
+            return redirect('config:instances')
+
+    context = {}
     return render(request, 'accounts/start.html', context)
 
 

+ 0 - 25
vycontrol/config/migrations/0001_initial.py

@@ -1,25 +0,0 @@
-# Generated by Django 2.0.3 on 2020-04-26 04:50
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
-    initial = True
-
-    dependencies = [
-    ]
-
-    operations = [
-        migrations.CreateModel(
-            name='Instance',
-            fields=[
-                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
-                ('alias', models.CharField(max_length=30)),
-                ('hostname', models.CharField(max_length=120)),
-                ('port', models.IntegerField(max_length=5)),
-                ('key', models.CharField(max_length=100)),
-                ('https', models.BinaryField()),
-            ],
-        ),
-    ]

+ 0 - 18
vycontrol/config/migrations/0002_auto_20200426_0450.py

@@ -1,18 +0,0 @@
-# Generated by Django 2.0.3 on 2020-04-26 04:50
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('config', '0001_initial'),
-    ]
-
-    operations = [
-        migrations.AlterField(
-            model_name='instance',
-            name='port',
-            field=models.IntegerField(),
-        ),
-    ]

+ 0 - 18
vycontrol/config/migrations/0003_auto_20200426_1259.py

@@ -1,18 +0,0 @@
-# Generated by Django 2.0.3 on 2020-04-26 12:59
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('config', '0002_auto_20200426_0450'),
-    ]
-
-    operations = [
-        migrations.AlterField(
-            model_name='instance',
-            name='https',
-            field=models.BooleanField(),
-        ),
-    ]

+ 0 - 22
vycontrol/config/migrations/0004_auto_20200427_1159.py

@@ -1,22 +0,0 @@
-# Generated by Django 2.0.3 on 2020-04-27 11:59
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('config', '0003_auto_20200426_1259'),
-    ]
-
-    operations = [
-        migrations.RemoveField(
-            model_name='instance',
-            name='id',
-        ),
-        migrations.AlterField(
-            model_name='instance',
-            name='hostname',
-            field=models.CharField(max_length=120, primary_key=True, serialize=False),
-        ),
-    ]

+ 0 - 19
vycontrol/config/migrations/0005_instancedefault.py

@@ -1,19 +0,0 @@
-# Generated by Django 2.0.3 on 2020-04-27 19:06
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('config', '0004_auto_20200427_1159'),
-    ]
-
-    operations = [
-        migrations.CreateModel(
-            name='InstanceDefault',
-            fields=[
-                ('hostname', models.CharField(max_length=120, primary_key=True, serialize=False)),
-            ],
-        ),
-    ]

+ 0 - 21
vycontrol/config/migrations/0006_auto_20200427_2202.py

@@ -1,21 +0,0 @@
-# Generated by Django 2.0.3 on 2020-04-27 22:02
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('config', '0005_instancedefault'),
-    ]
-
-    operations = [
-        migrations.DeleteModel(
-            name='InstanceDefault',
-        ),
-        migrations.AddField(
-            model_name='instance',
-            name='main',
-            field=models.BooleanField(default=False),
-        ),
-    ]

+ 0 - 20
vycontrol/config/migrations/0007_instance_group.py

@@ -1,20 +0,0 @@
-# Generated by Django 3.1.7 on 2021-04-05 06:55
-
-from django.db import migrations, models
-import django.db.models.deletion
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('auth', '__first__'),
-        ('config', '0006_auto_20200427_2202'),
-    ]
-
-    operations = [
-        migrations.AddField(
-            model_name='instance',
-            name='group',
-            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='auth.group'),
-        ),
-    ]

+ 0 - 0
vycontrol/config/migrations/__init__.py


+ 1 - 2
vycontrol/devstart.sh

@@ -1,2 +1 @@
-#https://simpleisbetterthancomplex.com/tips/2017/07/03/django-tip-20-working-with-multiple-settings-modules.html
-python manage.py runserver --settings=vycontrol.settings.development
+python manage.py runserver --settings=vycontrol.settings_available.development

+ 0 - 0
vycontrol/dnsresolver/migrations/__init__.py


+ 0 - 0
vycontrol/firewall/migrations/__init__.py


+ 0 - 0
vycontrol/interface/migrations/__init__.py


+ 1 - 1
vycontrol/manage.py

@@ -5,7 +5,7 @@ import sys
 
 
 def main():
-    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'vycontrol.settings.production')
+    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'vycontrol.settings_available.production')
     try:
         from django.core.management import execute_from_command_line
     except ImportError as exc:

+ 0 - 0
vycontrol/ntp/migrations/__init__.py


+ 0 - 0
vycontrol/static/migrations/__init__.py


+ 2 - 1
vycontrol/vycontrol/settings/base.py → vycontrol/vycontrol/settings.py

@@ -14,7 +14,8 @@ import os
 from pathlib import Path
 
 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
-BASE_DIR = str(Path(__file__).resolve().parents[2])
+#BASE_DIR = str(Path(__file__).resolve().parents[2])
+BASE_DIR = str(Path(__file__).resolve().parents[1])
 
 # Quick-start development settings - unsuitable for production
 # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

+ 0 - 0
vycontrol/vycontrol/settings/__init__.py


+ 0 - 25
vycontrol/vycontrol/settings/production.py

@@ -1,25 +0,0 @@
-from .base import *
-
-DEBUG = False
-
-ALLOWED_HOSTS = ['vycontrol.domain.com', ]
-
-CACHES = {
-    'default': {
-        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
-        'LOCATION': '127.0.0.1:11211',
-    }
-}
-
-EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
-EMAIL_HOST = 'email-smtp.us-east-1.amazonaws.com'
-EMAIL_PORT = 587
-EMAIL_HOST_USER = 'user'
-EMAIL_HOST_PASSWORD = 'password'
-EMAIL_USE_TLS = True
-DEFAULT_FROM_EMAIL = '"VyControl" <contact@vycontrol.com>'
-
-
-# SECURITY WARNING: keep the secret key used in production secret!
-SECRET_KEY = '*wv2=o(o5$i2qim7yxras_7jf%n!*1rrzehv3o2f-ebsr@ba%4'
-

+ 0 - 0
vycontrol/accounts/migrations/__init__.py → vycontrol/vycontrol/settings_example/__init__.py


+ 40 - 0
vycontrol/vycontrol/settings_example/production.py

@@ -0,0 +1,40 @@
+from vycontrol.settings import *
+import os
+
+DEBUG = True
+
+ALLOWED_HOSTS = ['127.0.0.1', ]
+
+CACHES = {
+#    'default': {
+#        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
+#        'LOCATION': '127.0.0.1:11211',
+#    }
+    'default': {
+        'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
+        'LOCATION': 'my_cache_table',
+    }
+}
+
+#EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
+#EMAIL_BACKEND = 'django_smtp_ssl.SSLEmailBackend'
+EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
+EMAIL_HOST = 'email-smtp.us-east-1.amazonaws.com'
+EMAIL_PORT = 587
+EMAIL_HOST_USER = 'user'
+EMAIL_HOST_PASSWORD = 'password'
+EMAIL_USE_TLS = True
+DEFAULT_FROM_EMAIL = '"VyControl" <contact@vycontrol.com>'
+
+DATABASES = {
+    'default': {
+        'ENGINE': 'django.db.backends.sqlite3',
+        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
+    }
+}
+
+# SECURITY WARNING: keep the secret key used in production secret!
+SECRET_KEY = 'change me warning'
+
+# show footer link to VyControl
+VYCONTROL_CREDITS = True