Added Volume mapping to docker app

This commit is contained in:
Chirag Aggarwal
2019-01-26 18:28:43 +00:00
parent f86e4ad865
commit c5d2a14273
9 changed files with 179 additions and 17 deletions

View File

@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2019-01-23 18:47
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('loginSystem', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Containers',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50, unique=True)),
('cid', models.CharField(default='', max_length=64)),
('image', models.CharField(default='unknown', max_length=50)),
('tag', models.CharField(default='unknown', max_length=50)),
('memory', models.IntegerField(default=0)),
('ports', models.TextField(default='{}')),
('env', models.TextField(default='{}')),
('startOnReboot', models.IntegerField(default=0)),
('admin', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='loginSystem.Administrator')),
],
),
]

View File

@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2019-01-26 16:22
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dockerManager', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='containers',
name='volumes',
field=models.TextField(default='{}'),
),
]

View File

@@ -13,5 +13,6 @@ class Containers(models.Model):
tag = models.CharField(max_length=50, default='unknown')
memory = models.IntegerField(default=0)
ports = models.TextField(default="{}")
volumes = models.TextField(default="{}")
env = models.TextField(default="{}")
startOnReboot = models.IntegerField(default=0)

View File

@@ -119,6 +119,18 @@ app.controller('runContainer', function ($scope, $http) {
$scope.success = true;
$scope.couldNotConnect = true;
$scope.goBackDisable = true;
$scope.volList = {};
$scope.volListNumber = 0;
$scope.addVolField = function() {
$scope.volList[$scope.volListNumber] = {'dest':'', 'src':''};
$scope.volListNumber = $scope.volListNumber + 1;
console.log($scope.volList)
}
$scope.removeVolField = function(){
delete $scope.volList[$scope.volListNumber - 1];
$scope.volListNumber = $scope.volListNumber - 1;
}
$scope.addEnvField = function () {
var countEnv = Object.keys($scope.envList).length;
@@ -157,8 +169,8 @@ app.controller('runContainer', function ($scope, $http) {
memory: memory,
dockerOwner: dockerOwner,
image: image,
envList: $scope.envList
envList: $scope.envList,
volList: $scope.volList
};
$.each($scope.portType, function (port, protocol) {
@@ -698,6 +710,16 @@ app.controller('viewContainer', function ($scope, $http) {
}
}
$scope.addVolField = function() {
$scope.volList[$scope.volListNumber] = {'dest':'', 'src':''};
$scope.volListNumber = $scope.volListNumber + 1;
console.log($scope.volList)
}
$scope.removeVolField = function(){
delete $scope.volList[$scope.volListNumber - 1];
$scope.volListNumber = $scope.volListNumber - 1;
}
$scope.saveSettings = function () {
$('#containerSettingLoading').show();
@@ -709,7 +731,8 @@ app.controller('viewContainer', function ($scope, $http) {
memory: $scope.memory,
startOnReboot: $scope.startOnReboot,
envConfirmation: $scope.envConfirmation,
envList: $scope.envList
envList: $scope.envList,
volList: $scope.volList
};
console.log(data)

View File

@@ -106,12 +106,39 @@
</div>
</div>
</div>
</div>
<div ng-hide="installationDetailsForm" class="col-md-offset-3">
<button type="button" class="btn btn-info" ng-click="addEnvField()">Add more</button>
</div><br>
<div ng-hide="installationDetailsForm" class="form-group text-center">
<label class="control-label">
{% trans "Map Volumes" %}
</label>
</div>
<div ng-repeat="volume in volList track by $index">
<div ng-hide="installationDetailsForm" class="form-group">
<div class="col-sm-3"></div>
<div class="col-sm-2">
<input type="text" class="form-control" ng-model="volList[$index].dest" placeholder="Destination" required>
</div>
<div class="col-sm-4">
<input type="text" class="form-control" ng-model="volList[$index].src" placeholder="Source" required>
</div>
<div ng-show="$last">
<div class="col-sm-1">
<button class="btn btn-primary" type="button" ng-click="removeVolField()"><i class="fa fa-times"></i></button>
</div>
</div>
</div>
</div>
<div ng-hide="installationDetailsForm" class="text-center">
<button type="button" class="btn btn-info" ng-click="addVolField()">{% trans "Add field" %}</button>
</div><br>
<div ng-hide="installationDetailsForm" class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">

View File

@@ -210,12 +210,12 @@
<div class="checkbox">
<label>
<input ng-model="envConfirmation" type="checkbox">
Editing ENV will recreate container <i class="fa fa-warning" title="If you tick this checkbox, your container will be recreated with saved information. Data saved inside container will be deleted (Not avaialble for container created outside of cyberpanel)"></i>
Editing ENV or Volume will recreate container <i class="fa fa-warning" title="If you tick this checkbox, your container will be recreated with saved information. Data saved inside container will be deleted (Not avaialble for container created outside of cyberpanel)"></i>
</label>
</div>
</div>
</div>
<hr>
<span ng-init="envList = {}"></span>
{% for env, value in envList.items %}
@@ -245,6 +245,43 @@
<button type="button" class="btn btn-info" ng-click="addEnvField()">Add more</button>
</div><br>
<span ng-init="volList = {}"></span>
{% for key, value in volList.items %}
<span ng-init="volList[{{ forloop.counter0 }}] = {'dest':'{{value.bind}}' , 'src':'{{key}}'}"></span>
<span ng-init="volListNumber={{ forloop.counter0 }} + 1"></span>
{% endfor %}
<hr>
<div ng-hide="installationDetailsForm" class="form-group text-center">
<label class="control-label">
{% trans "Map Volumes" %}
</label>
</div>
<div ng-repeat="volume in volList track by $index">
<div ng-hide="installationDetailsForm" class="form-group">
<div class="col-sm-3"></div>
<div class="col-sm-2">
<input type="text" class="form-control" ng-model="volList[$index].dest" placeholder="Destination" required>
</div>
<div class="col-sm-4">
<input type="text" class="form-control" ng-model="volList[$index].src" placeholder="Source" required>
</div>
<div ng-show="$last">
<div class="col-sm-1">
<button class="btn btn-primary" type="button" ng-click="removeVolField()"><i class="fa fa-times"></i></button>
</div>
</div>
</div>
</div>
<div ng-hide="installationDetailsForm" class="text-center">
<button type="button" class="btn btn-info" ng-click="addVolField()">{% trans "Add field" %}</button>
</div><br>
</form>
</div>