Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions buildServer/api/consumers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import json
from channels.generic.websocket import AsyncWebsocketConsumer

class RunConsumer(AsyncWebsocketConsumer):
async def connect(self):
self.group_name = 'run_updates'
await self.channel_layer.group_add(self.group_name, self.channel_name)
await self.accept()

async def disconnect(self, close_code):
await self.channel_layer.group_discard(self.group_name, self.channel_name)

async def run_data(self, event):
# Send data to WebSocket
await self.send(text_data=json.dumps(event['data']))
6 changes: 6 additions & 0 deletions buildServer/api/routing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.urls import re_path
from . import consumers

websocket_urlpatterns = [
re_path(r'ws/data/$', consumers.RunConsumer.as_asgi()),
]
2 changes: 1 addition & 1 deletion buildServer/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
path('login/', views.login_user, name="login"),
path('logout/', views.logout_user, name="logout"),
path('fetch_giturl/', views.fetch_giturl, name='fetch_giturl'),
path('deploy/', views.run, name='deploy'),
path('deploy/', views.run, name='deploy')
]
23 changes: 21 additions & 2 deletions buildServer/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
from .forms import SignupForm
from .models import User
from django.views.decorators.csrf import csrf_exempt
from channels.layers import get_channel_layer
from asgiref.sync import async_to_sync

from channels.layers import get_channel_layer
from asgiref.sync import async_to_sync



Expand Down Expand Up @@ -110,13 +115,27 @@ def run(request):
volumes={"/var/run/docker.sock": {"bind": "/var/run/docker.sock", "mode": "rw"}},
privileged=True,
)

channel_layer = get_channel_layer()
async_to_sync(channel_layer.group_send)(
'run_updates',
{
'type': 'run_data', # Matches consumer method
'data': "Sending LOGS..."
}
)
# Stream logs

logs = container.logs(stream=True)
logs_output = ""
for log in logs:
decoded_log = log.decode("utf-8")
logs_output += decoded_log
async_to_sync(channel_layer.group_send)(
'run_updates',
{
'type': 'run_data',
'data': decoded_log
}
)

container.stop()
container.remove()
Expand Down
11 changes: 8 additions & 3 deletions buildServer/buildServer/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
For more information on this file, see
https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application
from channels.routing import ProtocolTypeRouter, URLRouter
from api import routing

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'buildServer.settings')

application = get_asgi_application()
application = ProtocolTypeRouter({
"http": get_asgi_application(),
"websocket": URLRouter(
routing.websocket_urlpatterns
),
})
8 changes: 8 additions & 0 deletions buildServer/buildServer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions',
'channels',
'api',
]

Expand Down Expand Up @@ -78,6 +79,13 @@
]

WSGI_APPLICATION = 'buildServer.wsgi.application'
ASGI_APPLICATION = 'buildServer.asgi.application'

CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels.layers.InMemoryChannelLayer', # For development
},
}


# Database
Expand Down
3 changes: 1 addition & 2 deletions proxy_server/test
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ events {

http {
map $subdomain $upstream {
611883b794f67e5f82fd7e28ba580f483ac6bdb1bc3b9fde8d683acf61b5331f http://172.25.96.1:4000;
7dc4c894da2f612a6b0b688710bffafde3fb28e2003d151385744f50d2263822 http://172.25.96.1:4001;
ad029320d7a6ba413c8b2ec22e62aa8f3628f6d4eae5156250a9da7e345834da http://172.25.96.1:4000;
default "";
}

Expand Down