Use container IDs.
continuous-integration/drone/push Build is failing Details

master
Thomas Bellembois 2 years ago
parent 4d47300d50
commit b5b20fa446

@ -0,0 +1,5 @@
Build with docker:
```
docker run --rm -it --volume $(pwd):/app sandrokeil/typescript tsc /app/src/index.ts
mv src/index.js build/src/index.js
```

@ -1,3 +1,11 @@
// const proxyUrl = "http://localhost:8080";
// const proxyPath = "/";
const proxyUrl = "";
const proxyPath = "/dockerrunner/";
// console.log(proxyUrl);
function getContainers() { function getContainers() {
const httpRequest = new XMLHttpRequest(); const httpRequest = new XMLHttpRequest();
@ -15,14 +23,14 @@ function getContainers() {
} }
} }
}; };
httpRequest.open('GET', '/dockerrunner/containers/json'); httpRequest.open('GET', proxyUrl + proxyPath + 'containers/json');
httpRequest.send(); httpRequest.send();
return ''; return '';
} }
function getContainerLog(this: HTMLElement, ev: Event) { function getContainerLog(this: HTMLElement, ev: Event) {
const containerName = this.getAttribute('id'); const containerId = this.getAttribute('id');
const httpRequest = new XMLHttpRequest(); const httpRequest = new XMLHttpRequest();
if (!httpRequest) { if (!httpRequest) {
@ -41,7 +49,7 @@ function getContainerLog(this: HTMLElement, ev: Event) {
}; };
httpRequest.open( httpRequest.open(
'GET', 'GET',
'/dockerrunner/containers/' + containerName + '/logs' proxyUrl + proxyPath + 'containers/' + containerId + '/logs'
); );
httpRequest.send(); httpRequest.send();
@ -49,7 +57,7 @@ function getContainerLog(this: HTMLElement, ev: Event) {
} }
function removeContainer(this: HTMLElement, ev: Event) { function removeContainer(this: HTMLElement, ev: Event) {
const containerName = this.getAttribute('id'); const containerId = this.getAttribute('id');
const httpRequest = new XMLHttpRequest(); const httpRequest = new XMLHttpRequest();
if (!httpRequest) { if (!httpRequest) {
@ -60,13 +68,13 @@ function removeContainer(this: HTMLElement, ev: Event) {
httpRequest.onreadystatechange = () => { httpRequest.onreadystatechange = () => {
if (httpRequest.readyState === XMLHttpRequest.DONE) { if (httpRequest.readyState === XMLHttpRequest.DONE) {
if (httpRequest.status === 204) { if (httpRequest.status === 204) {
removeContainerSuccess(containerName!); removeContainerSuccess(containerId!);
} else { } else {
removeContainerError(containerName!); removeContainerError(containerId!);
} }
} }
}; };
httpRequest.open('DELETE', '/dockerrunner/containers/' + containerName); httpRequest.open('DELETE', proxyUrl + proxyPath + 'containers/' + containerId);
httpRequest.send(); httpRequest.send();
return ''; return '';
@ -88,7 +96,7 @@ function getContainersSuccess(response: string) {
for (let index = 0; index < containers.length; index++) { for (let index = 0; index < containers.length; index++) {
const container = containers[index]; const container = containers[index];
// const containerId = container.Id; const containerId = container.Id;
const containerImage = container.Image; const containerImage = container.Image;
const containerName = container.Labels['codefirst-containername']; const containerName = container.Labels['codefirst-containername'];
const containerEndpoint = container.Labels['codefirst-container-endpoint']; const containerEndpoint = container.Labels['codefirst-container-endpoint'];
@ -97,7 +105,7 @@ function getContainersSuccess(response: string) {
// Main div. // Main div.
const containerDiv = document.createElement('div'); const containerDiv = document.createElement('div');
containerDiv.setAttribute('class', 'row'); containerDiv.setAttribute('class', 'row');
containerDiv.setAttribute('id', `container${containerName}`); containerDiv.setAttribute('id', containerId);
// Container informations. // Container informations.
const containerInfo = document.createElement('div'); const containerInfo = document.createElement('div');
@ -138,12 +146,12 @@ function getContainersSuccess(response: string) {
// Build action buttons. // Build action buttons.
const containerLogs = document.createElement('button'); const containerLogs = document.createElement('button');
containerLogs.setAttribute('id', containerName); containerLogs.setAttribute('id', containerId);
containerLogs.innerHTML = 'logs'; containerLogs.innerHTML = 'logs';
containerLogs.addEventListener('click', getContainerLog); containerLogs.addEventListener('click', getContainerLog);
const containerdDelete = document.createElement('button'); const containerdDelete = document.createElement('button');
containerdDelete.setAttribute('id', containerName); containerdDelete.setAttribute('id', containerId);
containerdDelete.innerHTML = 'remove'; containerdDelete.innerHTML = 'remove';
containerdDelete.addEventListener('click', removeContainer); containerdDelete.addEventListener('click', removeContainer);

Loading…
Cancel
Save