Skip to content

Commit 75bf4f4

Browse files
committed
added ability to specify environment vars on container creation
1 parent 9238d62 commit 75bf4f4

File tree

6 files changed

+27
-6
lines changed

6 files changed

+27
-6
lines changed

Diff for: containers/forms.py

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Meta:
4545
class CreateContainerForm(forms.Form):
4646
image = forms.ChoiceField()
4747
command = forms.CharField(required=False)
48+
environment = forms.CharField(required=False, help_text='key=value space separated pairs')
4849
ports = forms.CharField(required=False, help_text='space separated')
4950
hosts = forms.MultipleChoiceField()
5051

Diff for: containers/models.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@ def get_images(self, show_all=False):
7070
cache.set(key, images, HOST_CACHE_TTL)
7171
return images
7272

73-
def create_container(self, image=None, command=None, ports=[]):
73+
def create_container(self, image=None, command=None, ports=[],
74+
environment=[]):
7475
c = self._get_client()
75-
cnt = c.create_container(image, command, detach=True, ports=ports)
76+
cnt = c.create_container(image, command, detach=True, ports=ports,
77+
environment=environment)
7678
c.start(cnt.get('Id'))
7779
self._invalidate_container_cache()
7880

Diff for: containers/views.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,20 @@ def add_host(request):
3333
@login_required
3434
def create_container(request):
3535
form = CreateContainerForm(request.POST)
36-
# TODO: create / start container
3736
image = form.data.get('image')
37+
environment = form.data.get('environment')
3838
command = form.data.get('command')
3939
if command.strip() == '':
4040
command = None
41+
if environment.strip() == '':
42+
environment = None
43+
else:
44+
environment = environment.split()
4145
ports = form.data.get('ports', '').split()
4246
hosts = form.data.getlist('hosts')
4347
for i in hosts:
4448
host = Host.objects.get(id=i)
45-
host.create_container(image, command, ports)
49+
host.create_container(image, command, ports, environment=environment)
4650
messages.add_message(request, messages.INFO, _('Created') + ' {0}'.format(
4751
image))
4852
return redirect('dashboard.views.index')

Diff for: shipyard/settings.py

+9
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,12 @@
215215
from local_settings import *
216216
except ImportError:
217217
pass
218+
219+
# create default admin user if not present
220+
from django.contrib.auth.models import User
221+
u, created = User.objects.get_or_create(username='admin')
222+
if created:
223+
u.set_password('shipyard')
224+
u.is_staff = True
225+
u.is_superuser = True
226+
u.save()

Diff for: shipyard/templatetags/shipyard.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,12 @@ def container_port_links(value, host):
3535
if value:
3636
host = Host.objects.get(name=host)
3737
all_forwards = value.split(',')
38-
print(all_forwards)
3938
for x in all_forwards:
4039
k,v = x.split('->')
4140
ports[k] = v
4241
for k,v in ports.items():
4342
link = '<a href="http://{0}:{1}" target="_blank">{1}->{2}</a>'.format(
44-
host.hostname, k,v)
43+
host.hostname, k.strip(), v.strip())
4544
links.append(link)
4645
ret = ', '.join(links)
4746
return ret

Diff for: wsgi.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from shipyard import wsgi
2+
#import newrelic.agent
3+
application = wsgi.application
4+
5+
#newrelic.agent.initialize('newrelic.ini')
6+
#app = newrelic.agent.wsgi_application()(app)

0 commit comments

Comments
 (0)