From 115105a2a08c3e2bc50ab82016b1c66b58c66622 Mon Sep 17 00:00:00 2001 From: wildloop Date: Mon, 12 Nov 2018 20:00:05 +0100 Subject: [PATCH] Init with the docker registry hosted on the same domain as UI --- .gitignore | 37 +++++++++++++++++++++++++++++++++++-- dist/index.html | 2 +- dist/scripts/init.js | 27 +++++++++++++++++++++++++++ src/index.html | 1 + src/scripts/init.js | 27 +++++++++++++++++++++++++++ 5 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 dist/scripts/init.js create mode 100644 src/scripts/init.js diff --git a/.gitignore b/.gitignore index 476bcfa..cd894f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,37 @@ -.project -node_modules +# dependencies +/node_modules package-lock.json + +# IDEs and editors +/.idea +*.iml +.project +.classpath +.c9/ +*.launch +.settings/ +*.sublime-workspace + +# IDE - VSCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +# misc +/.sass-cache +/connect.lock +/coverage +/libpeerconnection.log +npm-debug.log +yarn-error.log +testem.log +/typings + +# System Files +.DS_Store +Thumbs.db +.vscode/ + registry-data diff --git a/dist/index.html b/dist/index.html index 5caf748..2333361 100644 --- a/dist/index.html +++ b/dist/index.html @@ -13,4 +13,4 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . --->Docker Registry UI \ No newline at end of file +-->Docker Registry UI \ No newline at end of file diff --git a/dist/scripts/init.js b/dist/scripts/init.js new file mode 100644 index 0000000..90b8ebb --- /dev/null +++ b/dist/scripts/init.js @@ -0,0 +1,27 @@ +const REGISTRY_SERVER_KEY = 'registryServer'; +let registryServersStr = localStorage.getItem(REGISTRY_SERVER_KEY); +let registryServers = []; +if (registryServersStr !== null){ + let rs = JSON.parse(registryServersStr); + if (rs instanceof Array) { + registryServers = rs; + } +} + +const apiHost = location.protocol+'//'+location.host; +if (!registryServers.includes(apiHost)) { + let xhr = new XMLHttpRequest(); + xhr.open('GET', apiHost+"/v2/", true); + xhr.onload = function (e) { + if (xhr.readyState === 4) { + if (xhr.status === 200) { + const version = xhr.getResponseHeader('Docker-Distribution-Api-Version'); + if (version.startsWith('registry/2.')) { + registryServers.unshift(apiHost); + localStorage.setItem(REGISTRY_SERVER_KEY, JSON.stringify(registryServers)); + } + } + } + }; + xhr.send(); +} diff --git a/src/index.html b/src/index.html index edd9850..30ff624 100644 --- a/src/index.html +++ b/src/index.html @@ -32,6 +32,7 @@ + diff --git a/src/scripts/init.js b/src/scripts/init.js new file mode 100644 index 0000000..90b8ebb --- /dev/null +++ b/src/scripts/init.js @@ -0,0 +1,27 @@ +const REGISTRY_SERVER_KEY = 'registryServer'; +let registryServersStr = localStorage.getItem(REGISTRY_SERVER_KEY); +let registryServers = []; +if (registryServersStr !== null){ + let rs = JSON.parse(registryServersStr); + if (rs instanceof Array) { + registryServers = rs; + } +} + +const apiHost = location.protocol+'//'+location.host; +if (!registryServers.includes(apiHost)) { + let xhr = new XMLHttpRequest(); + xhr.open('GET', apiHost+"/v2/", true); + xhr.onload = function (e) { + if (xhr.readyState === 4) { + if (xhr.status === 200) { + const version = xhr.getResponseHeader('Docker-Distribution-Api-Version'); + if (version.startsWith('registry/2.')) { + registryServers.unshift(apiHost); + localStorage.setItem(REGISTRY_SERVER_KEY, JSON.stringify(registryServers)); + } + } + } + }; + xhr.send(); +}