-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
226 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,7 @@ coverage.xml | |
cover/ | ||
|
||
# Translations | ||
*.mo | ||
#*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# 第一阶段 | ||
FROM --platform=$TARGETPLATFORM python:3.9.10-slim as builder | ||
ARG TARGETPLATFORM | ||
ARG BUILDPLATFORM | ||
ARG TARGETARCH | ||
|
||
ENV PIP_CACHE_DIR=/app/.cache \ | ||
LANG=en_GB.UTF-8 \ | ||
DOCKER_HOST=unix:///var/run/docker.sock | ||
#RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list | ||
#RUN sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list | ||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
gcc \ | ||
libc6-dev \ | ||
libsqlite3-dev \ | ||
build-essential \ | ||
libssl-dev \ | ||
libffi-dev \ | ||
python3-dev \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
WORKDIR /app | ||
COPY requirements.txt . | ||
RUN python -m pip install --upgrade pip | ||
#RUN pip install --no-cache-dir -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ && python -m pip install Pillow -i https://mirrors.aliyun.com/pypi/simple/ | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
# 第二阶段 | ||
FROM python:3.9.10-slim | ||
|
||
LABEL maintainer="llody55" | ||
|
||
COPY --from=builder /usr/local/lib/python3.9 /usr/local/lib/python3.9 | ||
|
||
WORKDIR /app | ||
|
||
COPY . /app | ||
|
||
RUN mkdir /app/db | ||
|
||
# 初始化数据库 | ||
RUN python manage.py migrate | ||
RUN echo "from apps.models import CustomUser; CustomUser.objects.create_superuser('[email protected]','llody', '1qaz2wsx')" | python manage.py shell | ||
RUN echo "from apps.models import Registries; registry = Registries(registries_name='dockerhub', registries_url='docker.io', registries_auth=False, registries_remarks='DockerHub'); registry.save()" | python manage.py shell | ||
RUN echo "from apps.models import Registries; registry = Registries(registries_name='llody_proxy', registries_url='docker.llody.cn', registries_auth=False, registries_remarks='CF agent for Docker'); registry.save()" | python manage.py shell | ||
|
||
RUN chmod +x start.sh | ||
|
||
EXPOSE 9002 | ||
EXPOSE 8000 | ||
|
||
CMD ["./start.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Docker Image Pull</title> | ||
<link rel="stylesheet" href="/static/layui/css/layui.css"/> | ||
<script src="/static/layui/layui.js"></script> | ||
<style> | ||
.log-entry { | ||
margin-bottom: 10px; | ||
} | ||
.log-entry p { | ||
margin: 0; | ||
} | ||
.progress-container { | ||
margin-top: 10px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="layui-container"> | ||
<div class="layui-row"> | ||
<div class="layui-col-md12"> | ||
<input type="text" id="image_name" class="layui-input" placeholder="Enter Docker Image Name"> | ||
<button class="layui-btn" id="pull_button">Pull Image</button> | ||
</div> | ||
<div class="layui-col-md12"> | ||
<div id="output"></div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<script> | ||
var protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://'; | ||
var socket = new WebSocket(protocol + window.location.host + '/apps/dockerpull/'); | ||
var output = document.getElementById('output'); | ||
var logEntries = {}; | ||
|
||
document.getElementById('pull_button').onclick = function() { | ||
var imageName = document.getElementById('image_name').value; | ||
output.innerHTML = ''; // 清空之前的日志 | ||
logEntries = {}; // 清空之前的日志条目 | ||
socket.send(JSON.stringify({ | ||
'image_name': imageName | ||
})); | ||
}; | ||
|
||
socket.onmessage = function(e) { | ||
var data = JSON.parse(e.data); | ||
var message = data.message; | ||
|
||
if (message.id) { | ||
if (!logEntries[message.id]) { | ||
// 创建新的日志条目 | ||
var logEntry = document.createElement('div'); | ||
logEntry.classList.add('log-entry'); | ||
logEntry.setAttribute('id', 'log-' + message.id); | ||
|
||
var status = document.createElement('p'); | ||
status.innerHTML = '<strong>ID:</strong> ' + message.id + ' <strong>Status:</strong> ' + message.status; | ||
logEntry.appendChild(status); | ||
|
||
if (message.progressDetail && message.progressDetail.total > 0) { | ||
var progress = (message.progressDetail.current / message.progressDetail.total * 100).toFixed(2); | ||
var progressBarContainer = document.createElement('div'); | ||
progressBarContainer.classList.add('layui-progress', 'progress-container'); | ||
progressBarContainer.setAttribute('lay-showPercent', 'true'); | ||
|
||
var progressBar = document.createElement('div'); | ||
progressBar.classList.add('layui-progress-bar'); | ||
progressBar.setAttribute('lay-percent', progress + '%'); | ||
progressBar.style.width = progress + '%'; | ||
|
||
progressBarContainer.appendChild(progressBar); | ||
logEntry.appendChild(progressBarContainer); | ||
} | ||
|
||
output.appendChild(logEntry); | ||
logEntries[message.id] = logEntry; | ||
layui.element.init(); // 重新初始化进度条 | ||
} else { | ||
// 更新现有的日志条目 | ||
var existingEntry = logEntries[message.id]; | ||
existingEntry.querySelector('p').innerHTML = '<strong>ID:</strong> ' + message.id + ' <strong>Status:</strong> ' + message.status; | ||
if (message.progressDetail && message.progressDetail.total > 0) { | ||
var progress = (message.progressDetail.current / message.progressDetail.total * 100).toFixed(2); | ||
var progressBar = existingEntry.querySelector('.layui-progress-bar'); | ||
if (!progressBar) { | ||
// 如果进度条不存在,创建新的进度条 | ||
var progressBarContainer = document.createElement('div'); | ||
progressBarContainer.classList.add('layui-progress', 'progress-container'); | ||
progressBarContainer.setAttribute('lay-showPercent', 'true'); | ||
|
||
progressBar = document.createElement('div'); | ||
progressBar.classList.add('layui-progress-bar'); | ||
progressBar.setAttribute('lay-percent', progress + '%'); | ||
progressBar.style.width = progress + '%'; | ||
|
||
progressBarContainer.appendChild(progressBar); | ||
existingEntry.appendChild(progressBarContainer); | ||
} else { | ||
progressBar.setAttribute('lay-percent', progress + '%'); | ||
progressBar.style.width = progress + '%'; | ||
} | ||
layui.element.init(); // 重新初始化进度条 | ||
} | ||
} | ||
} else { | ||
// 处理最终结果的情况 | ||
var finalStatus = document.createElement('div'); | ||
finalStatus.classList.add('log-entry'); | ||
finalStatus.innerHTML = '<p><strong>Final Status:</strong> ' + message.status + '</p>'; | ||
if (message.error) { | ||
finalStatus.innerHTML += '<p><strong>Error:</strong> ' + message.error + '</p>'; | ||
finalStatus.classList.add('layui-bg-red'); // 添加红色背景表示错误 | ||
} else { | ||
finalStatus.classList.add('layui-bg-green'); // 添加绿色背景表示成功 | ||
} | ||
output.appendChild(finalStatus); | ||
} | ||
}; | ||
|
||
socket.onclose = function(e) { | ||
console.error('WebSocket closed unexpectedly'); | ||
}; | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# consumers.py | ||
import json | ||
import docker | ||
from channels.generic.websocket import WebsocketConsumer | ||
# 引用验证是否开启TLS认证的公共模块 | ||
from apps.docker_mod import connect_to_docker | ||
|
||
class DockerPullConsumer(WebsocketConsumer): | ||
def connect(self): | ||
self.accept() | ||
|
||
def disconnect(self, close_code): | ||
pass | ||
|
||
def receive(self, text_data): | ||
text_data_json = json.loads(text_data) | ||
image_name = text_data_json['image_name'] | ||
|
||
success, client = connect_to_docker() | ||
if success: | ||
for line in client.api.pull(image_name, stream=True, decode=True): | ||
self.send(text_data=json.dumps({ | ||
'message': line | ||
})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters