Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix labels; refine container name detection; support bundle addition #302

Merged
merged 2 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
refined project container name detection
  • Loading branch information
SelfhostedPro committed Feb 22, 2021
commit 2e450d682a6442e6743cd20de70b639f218d4599
40 changes: 31 additions & 9 deletions backend/api/actions/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,36 +302,58 @@ def delete_compose(project_name):
raise HTTPException(exc.status_code, exc.strerror)
return get_compose_projects()


def generate_support_bundle(project_name):
files = find_yml_files(settings.COMPOSE_DIR + project_name)
if project_name in files:
dclient = docker.from_env()
stream = io.BytesIO()
with zipfile.ZipFile(stream, "w") as zf, open(files[project_name], 'r') as fp:
with zipfile.ZipFile(stream, "w") as zf, open(files[project_name], "r") as fp:
compose = yaml.load(fp, Loader=yaml.SafeLoader)
# print(compose)
# print(compose.get("services"))
for _service in compose.get("services"):
if len(compose.get("services").keys()) <2:
print()
if len(compose.get("services").keys()) < 2:
try:
service = dclient.containers.get(_service)
if compose.get("services")[_service].get("container_name"):
service = dclient.containers.get(
compose.get("services")[_service].get("container_name")
)
else:
service = dclient.containers.get(_service)
except docker.errors.NotFound as exc:
raise HTTPException(exc.status_code, detail='container ' + _service + ' not found')
else:
raise HTTPException(
exc.status_code,
detail="container " + _service + " not found",
)
else:
try:
service = dclient.containers.get(project_name+'_'+_service)
if compose.get("services")[_service].get("container_name"):
service = dclient.containers.get(
compose.get("services")[_service].get("container_name")
)
else:
service = dclient.containers.get(
project_name.lower() + "_" + _service + "_1"
)
except docker.errors.NotFound as exc:
raise HTTPException(exc.status_code, detail='container ' + _service + ' not found')
raise HTTPException(
exc.status_code,
detail="container " + _service + " not found",
)
service_log = service.logs()
zf.writestr(f"{_service}.log", service_log)
fp.seek(0)
# It is possible that ".write(...)" has better memory management here.
# It is possible that ".write(...)" has better memory management here.
zf.writestr("docker-compose.yml", fp.read())
stream.seek(0)
return StreamingResponse(
stream,
media_type="application/x-zip-compressed",
headers={
"Content-Disposition": f"attachment;filename={project_name}_bundle.zip"
}
},
)
else:
raise HTTPException(404, f"Project {project_name} not found.")
12 changes: 9 additions & 3 deletions frontend/src/components/compose/ProjectDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,13 @@
</v-card>
<v-card color="foreground" class="mt-2">
<v-card-title> Download Support Bundle </v-card-title>
<v-card-text> Download the logs and docker-compose to get help with your project</v-card-text>
<v-btn :href="`/api/compose/${project.name}/support`" target="_blank">Download</v-btn>
<v-card-text>
Download the logs and docker-compose to get help with your
project</v-card-text
>
<v-btn :href="`/api/compose/${project.name}/support`" target="_blank" class="mb-2 ml-2" color="primary" download
>Download</v-btn
>
</v-card>
<v-dialog v-if="selectedProject" v-model="deleteDialog" max-width="400">
<v-card>
Expand Down Expand Up @@ -560,7 +565,7 @@ export default {
for (var app in this.apps) {
if (
this.apps[app].name == name ||
this.apps[app].name == this.project.name + "_" + name + "_1"
this.apps[app].name == this.project.name.toLowerCase() + "_" + name + "_1"
) {
return this.apps[app].State.Status;
}
Expand All @@ -576,6 +581,7 @@ export default {
mounted() {
const projectName = this.$route.params.projectName;
this.readProject(projectName);

this.readApps();
},
};
Expand Down