mirror of
https://github.com/Quiq/docker-registry-ui.git
synced 2025-09-29 22:38:00 +00:00
Compare commits
29 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
32d8ab87bd | ||
|
7a3bc551b3 | ||
|
7a752d3f8d | ||
|
80bdad8c91 | ||
|
734afe56b5 | ||
|
0f6bf65015 | ||
|
7525e87c1a | ||
|
97c189b195 | ||
|
2a0159b73e | ||
|
b563c6d1a1 | ||
|
1b8c502a60 | ||
|
9597890b67 | ||
|
e1656debc5 | ||
|
d1ce70490c | ||
|
e163b5af27 | ||
|
51c9a66195 | ||
|
4047019a3f | ||
|
0a268746c9 | ||
|
aaf65ed718 | ||
|
9a0674ea6b | ||
|
34fe1742cf | ||
|
0889821117 | ||
|
8aa9ac86f7 | ||
|
6b404abeaf | ||
|
16fd6d944f | ||
|
4db9ceb0a6 | ||
|
a8d57564fa | ||
|
a5fc3a5d30 | ||
|
eabcf48494 |
32
CHANGELOG.md
32
CHANGELOG.md
@@ -1,11 +1,39 @@
|
||||
## Changelog
|
||||
|
||||
### 0.6
|
||||
### 0.7.4 (2018-10-30)
|
||||
|
||||
* Switch to Go 1.11 and Go Modules to track dependencies.
|
||||
|
||||
### 0.7.3 (2018-08-14)
|
||||
|
||||
* Add `registry_password_file` option to the config file.
|
||||
* Improve no data message on empty tables on UI.
|
||||
* Show the root namespace "library" in the dropdown even when there are no repos in it.
|
||||
* Switch alpine Docker image to 3.8.
|
||||
|
||||
### 0.7.2 (2018-07-30)
|
||||
|
||||
* Make web root accessible w/o trailing slash when base_path is configured.
|
||||
|
||||
### 0.7.1 (2018-07-18)
|
||||
|
||||
* Fix panic when using MySQL for events storage and no table created yet.
|
||||
|
||||
### 0.7 (2018-07-04)
|
||||
|
||||
* When using MySQL for events storage, do not leak connections.
|
||||
* Last events were not shown when viewing a repo of non-default namespace.
|
||||
* Support repos with slash in the name.
|
||||
* Enable Sonatype Nexus compatibility.
|
||||
* Add `base_path` option to the config to run UI from non-root.
|
||||
* Add built-in cron feature for purging tags task.
|
||||
|
||||
### 0.6 (2018-05-28)
|
||||
|
||||
* Add MySQL along with sqlite3 support as a registry events storage.
|
||||
New config settings `event_database_driver`, `event_database_location`.
|
||||
* Bump Go version and dependencies.
|
||||
|
||||
### 0.5
|
||||
### 0.5 (2018-03-06)
|
||||
|
||||
* Initial public version.
|
||||
|
23
Dockerfile
23
Dockerfile
@@ -1,24 +1,21 @@
|
||||
FROM golang:1.10.2-alpine3.7 as builder
|
||||
FROM golang:1.11.1-alpine3.8 as builder
|
||||
|
||||
ENV GOPATH /opt
|
||||
ENV GO111MODULE on
|
||||
|
||||
RUN apk update && \
|
||||
apk add ca-certificates git build-base && \
|
||||
go get github.com/Masterminds/glide
|
||||
apk add ca-certificates git bash gcc musl-dev
|
||||
|
||||
ADD glide.* /opt/src/github.com/quiq/docker-registry-ui/
|
||||
RUN cd /opt/src/github.com/quiq/docker-registry-ui && \
|
||||
/opt/bin/glide install
|
||||
WORKDIR /opt/src/github.com/quiq/docker-registry-ui
|
||||
ADD events events
|
||||
ADD registry registry
|
||||
ADD *.go go.mod go.sum ./
|
||||
|
||||
ADD events /opt/src/github.com/quiq/docker-registry-ui/events
|
||||
ADD registry /opt/src/github.com/quiq/docker-registry-ui/registry
|
||||
ADD main.go /opt/src/github.com/quiq/docker-registry-ui/
|
||||
RUN cd /opt/src/github.com/quiq/docker-registry-ui && \
|
||||
go test -v ./registry && \
|
||||
go build -o /opt/docker-registry-ui github.com/quiq/docker-registry-ui
|
||||
RUN go test -v ./registry && \
|
||||
go build -o /opt/docker-registry-ui *.go
|
||||
|
||||
|
||||
FROM alpine:3.7
|
||||
FROM alpine:3.8
|
||||
|
||||
WORKDIR /opt
|
||||
RUN apk add --no-cache ca-certificates && \
|
||||
|
10
Makefile
Executable file
10
Makefile
Executable file
@@ -0,0 +1,10 @@
|
||||
IMAGE=quiq/docker-registry-ui
|
||||
VERSION=`sed -n '/version/ s/.* = //;s/"//g p' version.go`
|
||||
|
||||
.DEFAULT: build
|
||||
|
||||
build:
|
||||
@docker build -t ${IMAGE}:${VERSION} .
|
||||
@echo
|
||||
@echo "The image has been built: ${IMAGE}:${VERSION}"
|
||||
@echo
|
15
README.md
15
README.md
@@ -56,6 +56,7 @@ To receive events you need to configure Registry as follow:
|
||||
- application/octet-stream
|
||||
|
||||
Adjust url and token as appropriate.
|
||||
If you are running UI from non-root base path, e.g. /ui, the URL path for above will be `/ui/api/events`.
|
||||
|
||||
## Using MySQL instead of sqlite3 for event listener
|
||||
|
||||
@@ -76,6 +77,12 @@ You can create a table manually if you don't want to grant `CREATE` permission:
|
||||
|
||||
### Schedule a cron task for purging tags
|
||||
|
||||
To delete tags you need to enable the corresponding option in Docker Registry config. For example:
|
||||
|
||||
storage:
|
||||
delete:
|
||||
enabled: true
|
||||
|
||||
The following example shows how to run a cron task to purge tags older than X days but also keep
|
||||
at least Y tags no matter how old. Assuming container has been already running.
|
||||
|
||||
@@ -85,6 +92,14 @@ You can try to run in dry-run mode first to see what is going to be purged:
|
||||
|
||||
docker exec -t registry-ui /opt/docker-registry-ui -purge-tags -dry-run
|
||||
|
||||
Alternatively, you can schedule the purging task with built-in cron feature:
|
||||
|
||||
purge_tags_keep_days: 90
|
||||
purge_tags_keep_count: 2
|
||||
purge_tags_schedule: '0 10 3 * * *'
|
||||
|
||||
Note, the cron schedule format includes seconds! See https://godoc.org/github.com/robfig/cron
|
||||
|
||||
### Debug mode
|
||||
|
||||
To increase http request verbosity, run container with `-e GOREQUEST_DEBUG=1`.
|
||||
|
11
config.yml
11
config.yml
@@ -1,5 +1,7 @@
|
||||
# Listen interface.
|
||||
listen_addr: 0.0.0.0:8000
|
||||
# Base path of Docker Registry UI.
|
||||
base_path: /
|
||||
|
||||
# Registry URL with schema and port.
|
||||
registry_url: https://docker-registry.local
|
||||
@@ -10,8 +12,11 @@ verify_tls: true
|
||||
# They need to have a full access to the registry.
|
||||
# If token authentication service is enabled, it will be auto-discovered and those credentials
|
||||
# will be used to obtain access tokens.
|
||||
# When the registry_password_file entry is used, the password can be passed as a docker secret
|
||||
# and read from file. This overides the registry_password entry.
|
||||
registry_username: user
|
||||
registry_password: pass
|
||||
# registry_password_file: /run/secrets/registry_password_file
|
||||
|
||||
# Event listener token.
|
||||
# The same one should be configured on Docker registry as Authorization Bearer token.
|
||||
@@ -38,7 +43,11 @@ admins: []
|
||||
# Debug mode. Affects only templates.
|
||||
debug: true
|
||||
|
||||
# CLI options.
|
||||
# How many days to keep tags but also keep the minimal count provided no matter how old.
|
||||
purge_tags_keep_days: 90
|
||||
purge_tags_keep_count: 2
|
||||
# Enable built-in cron to schedule purging tags in server mode.
|
||||
# Empty string disables this feature.
|
||||
# Example: '25 54 17 * * *' will run it at 17:54:25 daily.
|
||||
# Note, the cron schedule format includes seconds! See https://godoc.org/github.com/robfig/cron
|
||||
purge_tags_schedule: ''
|
||||
|
@@ -144,13 +144,13 @@ func (e *EventListener) GetEvents(repository string) []EventRow {
|
||||
e.logger.Error("Error selecting from table: ", err)
|
||||
return events
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var row EventRow
|
||||
rows.Scan(&row.ID, &row.Action, &row.Repository, &row.Tag, &row.IP, &row.User, &row.Created)
|
||||
events = append(events, row)
|
||||
}
|
||||
rows.Close()
|
||||
return events
|
||||
}
|
||||
|
||||
@@ -171,9 +171,13 @@ func (e *EventListener) getDababaseHandler() (*sql.DB, error) {
|
||||
|
||||
if e.databaseDriver == "mysql" {
|
||||
schema = strings.Replace(schema, "AUTOINCREMENT", "AUTO_INCREMENT", 1)
|
||||
if _, err := db.Query("SELECT * FROM events LIMIT 1"); err != nil {
|
||||
rows, err := db.Query("SELECT * FROM events LIMIT 1")
|
||||
if err != nil {
|
||||
firstRun = true
|
||||
}
|
||||
if rows != nil {
|
||||
rows.Close()
|
||||
}
|
||||
}
|
||||
|
||||
// Create table on first run.
|
||||
|
1
example/.gitignore
vendored
Normal file
1
example/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/data
|
25
example/README.md
Normal file
25
example/README.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# Docker Registry UI Example
|
||||
|
||||
Start the local Docker Registry and UI.
|
||||
|
||||
```bash
|
||||
$ docker-compose up -d
|
||||
```
|
||||
|
||||
As an example, push the docker-registry-ui image to the local Docker Registry.
|
||||
|
||||
```bash
|
||||
$ docker tag quiq/docker-registry-ui localhost/quiq/docker-registry-ui
|
||||
$ docker push localhost/quiq/docker-registry-ui
|
||||
The push refers to repository [localhost:5000/quiq/docker-registry-ui]
|
||||
ab414a599bf8: Pushed
|
||||
a8da33adf86e: Pushed
|
||||
71a0e0a972a7: Pushed
|
||||
96dc74eb5456: Pushed
|
||||
ac362bf380d0: Pushed
|
||||
04a094fe844e: Pushed
|
||||
latest: digest: sha256:d88c1ca40986a358e59795992e87e364a0b3b97833aade5abcd79dda0a0477e8 size: 1571
|
||||
```
|
||||
|
||||
Then you will find the pushed repository 'quiq/docker-registry-ui' in the following URL.
|
||||
http://localhost/ui/quiq/docker-registry-ui
|
79
example/config/httpd.conf
Normal file
79
example/config/httpd.conf
Normal file
@@ -0,0 +1,79 @@
|
||||
LoadModule mpm_event_module modules/mod_mpm_event.so
|
||||
LoadModule headers_module modules/mod_headers.so
|
||||
|
||||
LoadModule authn_file_module modules/mod_authn_file.so
|
||||
LoadModule authn_core_module modules/mod_authn_core.so
|
||||
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
|
||||
LoadModule authz_user_module modules/mod_authz_user.so
|
||||
LoadModule authz_core_module modules/mod_authz_core.so
|
||||
LoadModule auth_basic_module modules/mod_auth_basic.so
|
||||
LoadModule access_compat_module modules/mod_access_compat.so
|
||||
|
||||
LoadModule log_config_module modules/mod_log_config.so
|
||||
|
||||
LoadModule proxy_module modules/mod_proxy.so
|
||||
LoadModule proxy_http_module modules/mod_proxy_http.so
|
||||
|
||||
LoadModule unixd_module modules/mod_unixd.so
|
||||
|
||||
<IfModule unixd_module>
|
||||
User daemon
|
||||
Group daemon
|
||||
</IfModule>
|
||||
|
||||
ServerAdmin you@example.com
|
||||
|
||||
ErrorLog /proc/self/fd/2
|
||||
|
||||
LogLevel warn
|
||||
|
||||
<IfModule log_config_module>
|
||||
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
|
||||
LogFormat "%h %l %u %t \"%r\" %>s %b" common
|
||||
|
||||
<IfModule logio_module>
|
||||
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
|
||||
</IfModule>
|
||||
|
||||
CustomLog /proc/self/fd/1 common
|
||||
</IfModule>
|
||||
|
||||
ServerRoot "/usr/local/apache2"
|
||||
|
||||
Listen 80
|
||||
|
||||
<Directory />
|
||||
AllowOverride none
|
||||
Require all denied
|
||||
</Directory>
|
||||
|
||||
<VirtualHost *:80>
|
||||
|
||||
ServerName myregistrydomain.com
|
||||
|
||||
Header always set "Docker-Distribution-Api-Version" "registry/2.0"
|
||||
Header onsuccess set "Docker-Distribution-Api-Version" "registry/2.0"
|
||||
|
||||
ProxyRequests off
|
||||
ProxyPreserveHost on
|
||||
|
||||
# no proxy for /error/ (Apache HTTPd errors messages)
|
||||
ProxyPass /error/ !
|
||||
|
||||
ProxyPass /v2 http://registry:5000/v2
|
||||
ProxyPassReverse /v2 http://registry:5000/v2
|
||||
|
||||
<Location /v2>
|
||||
Order deny,allow
|
||||
Allow from all
|
||||
</Location>
|
||||
|
||||
ProxyPass /ui/ http://registry-ui:8000/ui/
|
||||
ProxyPassReverse /ui/ http://registry-ui:8000/ui/
|
||||
|
||||
<Location /ui>
|
||||
Order deny,allow
|
||||
Allow from all
|
||||
</Location>
|
||||
|
||||
</VirtualHost>
|
46
example/config/registry-ui.yml
Normal file
46
example/config/registry-ui.yml
Normal file
@@ -0,0 +1,46 @@
|
||||
# Listen interface.
|
||||
listen_addr: 0.0.0.0:8000
|
||||
# Base path of Docker Registry UI.
|
||||
base_path: /ui
|
||||
|
||||
# Registry URL with schema and port.
|
||||
registry_url: http://registry:5000
|
||||
# Verify TLS certificate when using https.
|
||||
verify_tls: true
|
||||
|
||||
# Docker registry credentials.
|
||||
# They need to have a full access to the registry.
|
||||
# If token authentication service is enabled, it will be auto-discovered and those credentials
|
||||
# will be used to obtain access tokens.
|
||||
# registry_username: user
|
||||
# registry_password: pass
|
||||
|
||||
# Event listener token.
|
||||
# The same one should be configured on Docker registry as Authorization Bearer token.
|
||||
event_listener_token: token
|
||||
# Retention of records to keep.
|
||||
event_retention_days: 7
|
||||
|
||||
# Event listener storage.
|
||||
event_database_driver: sqlite3
|
||||
event_database_location: data/registry_events.db
|
||||
# event_database_driver: mysql
|
||||
# event_database_location: user:password@tcp(localhost:3306)/docker_events
|
||||
|
||||
# Cache refresh interval in minutes.
|
||||
# How long to cache repository list and tag counts.
|
||||
cache_refresh_interval: 10
|
||||
|
||||
# If users can delete tags. If set to False, then only admins listed below.
|
||||
anyone_can_delete: false
|
||||
# Users allowed to delete tags.
|
||||
# This should be sent via X-WEBAUTH-USER header from your proxy.
|
||||
admins: []
|
||||
|
||||
# Debug mode. Affects only templates.
|
||||
debug: true
|
||||
|
||||
# CLI options.
|
||||
# How many days to keep tags but also keep the minimal count provided no matter how old.
|
||||
purge_tags_keep_days: 90
|
||||
purge_tags_keep_count: 2
|
31
example/docker-compose.yml
Normal file
31
example/docker-compose.yml
Normal file
@@ -0,0 +1,31 @@
|
||||
version: "2.3"
|
||||
|
||||
services:
|
||||
httpd:
|
||||
image: httpd:2.4
|
||||
ports:
|
||||
- "80:80"
|
||||
volumes:
|
||||
- "./config/httpd.conf:/usr/local/apache2/conf/httpd.conf:ro"
|
||||
|
||||
registry:
|
||||
image: registry:2
|
||||
ports:
|
||||
- "5000"
|
||||
volumes:
|
||||
- "./data/registry:/var/lib/registry"
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-s", "localhost:5000/v2/"]
|
||||
interval: 5s
|
||||
timeout: 10s
|
||||
|
||||
registry-ui:
|
||||
image: quiq/docker-registry-ui:latest
|
||||
ports:
|
||||
- "8000"
|
||||
volumes:
|
||||
- "./data/registry-ui:/opt/data"
|
||||
- "./config/registry-ui.yml:/opt/config.yml:ro"
|
||||
depends_on:
|
||||
registry:
|
||||
condition: service_healthy
|
78
glide.lock
generated
78
glide.lock
generated
@@ -1,78 +0,0 @@
|
||||
hash: d156899e94e2d0d92ed200d5729bec5d0d205b5b98bbf2bd89f7f91c9ed7a518
|
||||
updated: 2018-05-28T13:28:11.313447+03:00
|
||||
imports:
|
||||
- name: github.com/CloudyKit/fastprinter
|
||||
version: 74b38d55f37af5d6c05ca11147d616b613a3420e
|
||||
- name: github.com/CloudyKit/jet
|
||||
version: 2b064536b25ab0e9c54245f9e2cc5bd4766033fe
|
||||
- name: github.com/dgrijalva/jwt-go
|
||||
version: 06ea1031745cb8b3dab3f6a236daf2b0aa468b7e
|
||||
- name: github.com/go-sql-driver/mysql
|
||||
version: 64db0f7ebe171b596aa9b26f39a79f7413a3b617
|
||||
- name: github.com/hhkbp2/go-logging
|
||||
version: 377ba05d98977baa2a0d9e13f13aac2f3a47ac4d
|
||||
- name: github.com/hhkbp2/go-strftime
|
||||
version: d82166ec6782f870431668391c2e321069632fe7
|
||||
- name: github.com/labstack/echo
|
||||
version: 6d227dfea4d2e52cb76856120b3c17f758139b4e
|
||||
subpackages:
|
||||
- middleware
|
||||
- name: github.com/labstack/gommon
|
||||
version: 0a22a0df01a7c84944c607e8a6e91cfe421ea7ed
|
||||
subpackages:
|
||||
- bytes
|
||||
- color
|
||||
- log
|
||||
- random
|
||||
- name: github.com/mattn/go-colorable
|
||||
version: efa589957cd060542a26d2dd7832fd6a6c6c3ade
|
||||
- name: github.com/mattn/go-isatty
|
||||
version: 6ca4dbf54d38eea1a992b3c722a76a5d1c4cb25c
|
||||
- name: github.com/mattn/go-sqlite3
|
||||
version: 323a32be5a2421b8c7087225079c6c900ec397cd
|
||||
- name: github.com/moul/http2curl
|
||||
version: 9ac6cf4d929b2fa8fd2d2e6dec5bb0feb4f4911d
|
||||
- name: github.com/parnurzeal/gorequest
|
||||
version: a578a48e8d6ca8b01a3b18314c43c6716bb5f5a3
|
||||
- name: github.com/pkg/errors
|
||||
version: 816c9085562cd7ee03e7f8188a1cfd942858cded
|
||||
- name: github.com/tidwall/gjson
|
||||
version: 01f00f129617a6fe98941fb920d6c760241b54d2
|
||||
- name: github.com/tidwall/match
|
||||
version: 1731857f09b1f38450e2c12409748407822dc6be
|
||||
- name: github.com/valyala/bytebufferpool
|
||||
version: e746df99fe4a3986f4d4f79e13c1e0117ce9c2f7
|
||||
- name: github.com/valyala/fasttemplate
|
||||
version: dcecefd839c4193db0d35b88ec65b4c12d360ab0
|
||||
- name: golang.org/x/crypto
|
||||
version: 1a580b3eff7814fc9b40602fd35256c63b50f491
|
||||
subpackages:
|
||||
- acme
|
||||
- acme/autocert
|
||||
- name: golang.org/x/net
|
||||
version: dfa909b99c79129e1100513e5cd36307665e5723
|
||||
subpackages:
|
||||
- publicsuffix
|
||||
- name: golang.org/x/sys
|
||||
version: 7c87d13f8e835d2fb3a70a2912c811ed0c1d241b
|
||||
subpackages:
|
||||
- unix
|
||||
- name: google.golang.org/appengine
|
||||
version: b1f26356af11148e710935ed1ac8a7f5702c7612
|
||||
subpackages:
|
||||
- cloudsql
|
||||
- name: gopkg.in/yaml.v2
|
||||
version: 5420a8b6744d3b0345ab293f6fcba19c978f1183
|
||||
testImports:
|
||||
- name: github.com/jtolds/gls
|
||||
version: 9a4a02dbe491bef4bab3c24fd9f3087d6c4c6690
|
||||
- name: github.com/smartystreets/assertions
|
||||
version: 01fedaa993c0a9f9aa55111501cd7c81a49e812e
|
||||
subpackages:
|
||||
- internal/oglematchers
|
||||
- name: github.com/smartystreets/goconvey
|
||||
version: d4c757aa9afd1e2fc1832aaab209b5794eb336e1
|
||||
subpackages:
|
||||
- convey
|
||||
- convey/gotest
|
||||
- convey/reporting
|
21
glide.yaml
21
glide.yaml
@@ -1,21 +0,0 @@
|
||||
package: github.com/quiq/docker-registry-ui
|
||||
import:
|
||||
- package: github.com/CloudyKit/jet
|
||||
version: v2.1.2
|
||||
- package: github.com/labstack/echo
|
||||
version: v3.3.5
|
||||
subpackages:
|
||||
- middleware
|
||||
- package: github.com/parnurzeal/gorequest
|
||||
version: v0.2.15
|
||||
- package: github.com/hhkbp2/go-logging
|
||||
- package: github.com/tidwall/gjson
|
||||
version: v1.1.0
|
||||
- package: github.com/mattn/go-sqlite3
|
||||
version: 1.7.0
|
||||
- package: github.com/go-sql-driver/mysql
|
||||
testImport:
|
||||
- package: github.com/smartystreets/goconvey
|
||||
version: 1.6.2
|
||||
subpackages:
|
||||
- convey
|
31
go.mod
Normal file
31
go.mod
Normal file
@@ -0,0 +1,31 @@
|
||||
module github.com/quiq/docker-registry-ui
|
||||
|
||||
require (
|
||||
github.com/CloudyKit/fastprinter v0.0.0-20170127035650-74b38d55f37a // indirect
|
||||
github.com/CloudyKit/jet v2.1.2+incompatible
|
||||
github.com/elazarl/goproxy v0.0.0-20181003060214-f58a169a71a5 // indirect
|
||||
github.com/go-sql-driver/mysql v0.0.0-20180526092451-64db0f7ebe17
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 // indirect
|
||||
github.com/hhkbp2/go-logging v0.0.0-20171106042747-377ba05d9897
|
||||
github.com/hhkbp2/go-strftime v0.0.0-20150709091403-d82166ec6782 // indirect
|
||||
github.com/hhkbp2/testify v0.0.0-20150512090439-112845ebc045 // indirect
|
||||
github.com/jtolds/gls v4.2.1+incompatible // indirect
|
||||
github.com/labstack/echo v0.0.0-20180911044237-1abaa3049251
|
||||
github.com/labstack/gommon v0.0.0-20180506140623-0a22a0df01a7 // indirect
|
||||
github.com/mattn/go-isatty v0.0.4 // indirect
|
||||
github.com/mattn/go-sqlite3 v1.7.0
|
||||
github.com/moul/http2curl v0.0.0-20170919181001-9ac6cf4d929b // indirect
|
||||
github.com/parnurzeal/gorequest v0.2.15
|
||||
github.com/pkg/errors v0.0.0-20180311214515-816c9085562c // indirect
|
||||
github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect
|
||||
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a
|
||||
github.com/tidwall/gjson v1.1.0
|
||||
github.com/tidwall/match v0.0.0-20171002075945-1731857f09b1 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
golang.org/x/crypto v0.0.0-20180515001509-1a580b3eff78 // indirect
|
||||
golang.org/x/net v0.0.0-20180524181706-dfa909b99c79 // indirect
|
||||
golang.org/x/sys v0.0.0-20180514143608-7c87d13f8e83 // indirect
|
||||
google.golang.org/appengine v1.1.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.2.1
|
||||
)
|
73
go.sum
Normal file
73
go.sum
Normal file
@@ -0,0 +1,73 @@
|
||||
github.com/CloudyKit/fastprinter v0.0.0-20170127035650-74b38d55f37a h1:3SgJcK9l5uPdBC/X17wanyJAMxM33+4ZhEIV96MIH8U=
|
||||
github.com/CloudyKit/fastprinter v0.0.0-20170127035650-74b38d55f37a/go.mod h1:EFZQ978U7x8IRnstaskI3IysnWY5Ao3QgZUKOXlsAdw=
|
||||
github.com/CloudyKit/jet v2.1.2+incompatible h1:ybZoYzMBdoijK6I+Ke3vg9GZsmlKo/ZhKdNMWz0P26c=
|
||||
github.com/CloudyKit/jet v2.1.2+incompatible/go.mod h1:HPYO+50pSWkPoj9Q/eq0aRGByCL6ScRlUmiEX5Zgm+w=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/elazarl/goproxy v0.0.0-20181003060214-f58a169a71a5 h1:LCoguo7Zd0MByKMbQbTvcZw7HiBcbvew+MOcwsJVwrY=
|
||||
github.com/elazarl/goproxy v0.0.0-20181003060214-f58a169a71a5/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
|
||||
github.com/go-sql-driver/mysql v0.0.0-20180526092451-64db0f7ebe17 h1:0J5ldStBfM6jDep4uzPGSC1Tqwk3UVDW1QPAaIxPhAQ=
|
||||
github.com/go-sql-driver/mysql v0.0.0-20180526092451-64db0f7ebe17/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/hhkbp2/go-logging v0.0.0-20171106042747-377ba05d9897 h1:0vxLTAKJQ8n7revuQ11xssUZbuyGwMuDGMRdaxrviuM=
|
||||
github.com/hhkbp2/go-logging v0.0.0-20171106042747-377ba05d9897/go.mod h1:zAp/KbVJna4DHUdeSPYGsRNn9c62x569NIr9ssBuZ/I=
|
||||
github.com/hhkbp2/go-strftime v0.0.0-20150709091403-d82166ec6782 h1:Evl9i7wBY3bjJ3NqHs0ldhnKOdQL4Kaum9ve1JAmiCE=
|
||||
github.com/hhkbp2/go-strftime v0.0.0-20150709091403-d82166ec6782/go.mod h1:x8/IOQ5qQ4DKfiTmD9wBhQ40edg5wh7gMRwdLg07mMw=
|
||||
github.com/hhkbp2/testify v0.0.0-20150512090439-112845ebc045 h1:MmQwR3zANTXzs2yZexVBDY6qcH2vJXOl/2dZFkWVM7w=
|
||||
github.com/hhkbp2/testify v0.0.0-20150512090439-112845ebc045/go.mod h1:8DUHF4igllRoOCbQKJsylsDqROcRtPTdb+SQUfjCYLo=
|
||||
github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE=
|
||||
github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/labstack/echo v0.0.0-20180911044237-1abaa3049251 h1:4q++nZ4OEtmbHazhA/7i3T9B+CBWtnHpuMMcW55ZjRk=
|
||||
github.com/labstack/echo v0.0.0-20180911044237-1abaa3049251/go.mod h1:rWD2DNQgFb1IY9lVYZVLWn2Ko4dyHZ/LpHORyBLP3hI=
|
||||
github.com/labstack/gommon v0.0.0-20180312174116-6fe1405d73ec/go.mod h1:/tj9csK2iPSBvn+3NLM9e52usepMtrd5ilFYA+wQNJ4=
|
||||
github.com/labstack/gommon v0.0.0-20180506140623-0a22a0df01a7 h1:zBqzrh1EkrO1zj/pDGT+UrB1M1Ihzqjc0K9MOynW2tI=
|
||||
github.com/labstack/gommon v0.0.0-20180506140623-0a22a0df01a7/go.mod h1:/tj9csK2iPSBvn+3NLM9e52usepMtrd5ilFYA+wQNJ4=
|
||||
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
|
||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||
github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
|
||||
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||
github.com/mattn/go-sqlite3 v1.7.0 h1:CiYZ8slwBLIMkDbDJCF+Zd2M8bZ1Gz02TMsm1V33Lk0=
|
||||
github.com/mattn/go-sqlite3 v1.7.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||
github.com/moul/http2curl v0.0.0-20170919181001-9ac6cf4d929b h1:Pip12xNtMvEFUBF4f8/b5yRXj94LLrNdLWELfOr2KcY=
|
||||
github.com/moul/http2curl v0.0.0-20170919181001-9ac6cf4d929b/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ=
|
||||
github.com/parnurzeal/gorequest v0.2.15 h1:oPjDCsF5IkD4gUk6vIgsxYNaSgvAnIh1EJeROn3HdJU=
|
||||
github.com/parnurzeal/gorequest v0.2.15/go.mod h1:3Kh2QUMJoqw3icWAecsyzkpY7UzRfDhbRdTjtNwNiUE=
|
||||
github.com/pkg/errors v0.0.0-20180311214515-816c9085562c h1:F5RoIh7F9wB47PvXvpP1+Ihq1TkyC8iRdvwfKkESEZQ=
|
||||
github.com/pkg/errors v0.0.0-20180311214515-816c9085562c/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967 h1:x7xEyJDP7Hv3LVgvWhzioQqbC/KtuUhTigKlH/8ehhE=
|
||||
github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a h1:JSvGDIbmil4Ui/dDdFBExb7/cmkNjyX5F97oglmvCDo=
|
||||
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s=
|
||||
github.com/stretchr/testify v1.2.1 h1:52QO5WkIUcHGIR7EnGagH88x1bUzqGXTC5/1bDTUQ7U=
|
||||
github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/tidwall/gjson v1.1.0 h1:/7OBSUzFP8NhuzLlHg0vETJrRL02C++0ql5uSY3DITs=
|
||||
github.com/tidwall/gjson v1.1.0/go.mod h1:c/nTNbUr0E0OrXEhq1pwa8iEgc2DOt4ZZqAt1HtCkPA=
|
||||
github.com/tidwall/match v0.0.0-20171002075945-1731857f09b1 h1:pWIN9LOlFRCJFqWIOEbHLvY0WWJddsjH2FQ6N0HKZdU=
|
||||
github.com/tidwall/match v0.0.0-20171002075945-1731857f09b1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
|
||||
github.com/valyala/bytebufferpool v0.0.0-20160817181652-e746df99fe4a/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasttemplate v0.0.0-20170224212429-dcecefd839c4 h1:gKMu1Bf6QINDnvyZuTaACm9ofY+PRh+5vFz4oxBZeF8=
|
||||
github.com/valyala/fasttemplate v0.0.0-20170224212429-dcecefd839c4/go.mod h1:50wTf68f99/Zt14pr046Tgt3Lp2vLyFZKzbFXTOabXw=
|
||||
golang.org/x/crypto v0.0.0-20180312195533-182114d58262/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20180515001509-1a580b3eff78 h1:uJIReYEB1ZZLarzi83Pmig1HhZ/cwFCysx05l0PFBIk=
|
||||
golang.org/x/crypto v0.0.0-20180515001509-1a580b3eff78/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/net v0.0.0-20180524181706-dfa909b99c79 h1:1FDlG4HI84rVePw1/0E/crL5tt2N+1blLJpY6UZ6krs=
|
||||
golang.org/x/net v0.0.0-20180524181706-dfa909b99c79/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/sys v0.0.0-20180312081825-c28acc882ebc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180514143608-7c87d13f8e83 h1:RBQVaDuCnVU3bRWKyzSxMStfh2k1xl+FdtjOsarwO28=
|
||||
golang.org/x/sys v0.0.0-20180514143608-7c87d13f8e83/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
google.golang.org/appengine v1.1.0 h1:igQkv0AAhEIvTEpD5LIpAfav2eeVO9HBTjvKHVJPRSs=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
114
main.go
114
main.go
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -15,16 +14,19 @@ import (
|
||||
"github.com/labstack/echo/middleware"
|
||||
"github.com/quiq/docker-registry-ui/events"
|
||||
"github.com/quiq/docker-registry-ui/registry"
|
||||
"github.com/robfig/cron"
|
||||
"github.com/tidwall/gjson"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
type configData struct {
|
||||
ListenAddr string `yaml:"listen_addr"`
|
||||
BasePath string `yaml:"base_path"`
|
||||
RegistryURL string `yaml:"registry_url"`
|
||||
VerifyTLS bool `yaml:"verify_tls"`
|
||||
Username string `yaml:"registry_username"`
|
||||
Password string `yaml:"registry_password"`
|
||||
PasswordFile string `yaml:"registry_password_file"`
|
||||
EventListenerToken string `yaml:"event_listener_token"`
|
||||
EventRetentionDays int `yaml:"event_retention_days"`
|
||||
EventDatabaseDriver string `yaml:"event_database_driver"`
|
||||
@@ -35,6 +37,7 @@ type configData struct {
|
||||
Debug bool `yaml:"debug"`
|
||||
PurgeTagsKeepDays int `yaml:"purge_tags_keep_days"`
|
||||
PurgeTagsKeepCount int `yaml:"purge_tags_keep_count"`
|
||||
PurgeTagsSchedule string `yaml:"purge_tags_schedule"`
|
||||
}
|
||||
|
||||
type template struct {
|
||||
@@ -75,6 +78,26 @@ func main() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// Normalize base path.
|
||||
if a.config.BasePath != "" {
|
||||
if !strings.HasPrefix(a.config.BasePath, "/") {
|
||||
a.config.BasePath = "/" + a.config.BasePath
|
||||
}
|
||||
if strings.HasSuffix(a.config.BasePath, "/") {
|
||||
a.config.BasePath = a.config.BasePath[0 : len(a.config.BasePath)-1]
|
||||
}
|
||||
}
|
||||
// Read password from file.
|
||||
if a.config.PasswordFile != "" {
|
||||
if _, err := os.Stat(a.config.PasswordFile); os.IsNotExist(err) {
|
||||
panic(err)
|
||||
}
|
||||
passwordBytes, err := ioutil.ReadFile(a.config.PasswordFile)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
a.config.Password = strings.TrimSuffix(string(passwordBytes[:]), "\n")
|
||||
}
|
||||
|
||||
// Init registry API client.
|
||||
a.client = registry.NewClient(a.config.RegistryURL, a.config.VerifyTLS, a.config.Username, a.config.Password)
|
||||
@@ -84,9 +107,20 @@ func main() {
|
||||
|
||||
// Execute CLI task and exit.
|
||||
if purgeTags {
|
||||
registry.PurgeOldTags(a.client, purgeDryRun, a.config.PurgeTagsKeepDays, a.config.PurgeTagsKeepCount)
|
||||
a.purgeOldTags(purgeDryRun)
|
||||
return
|
||||
}
|
||||
// Schedules to purge tags.
|
||||
if a.config.PurgeTagsSchedule != "" {
|
||||
c := cron.New()
|
||||
task := func() {
|
||||
a.purgeOldTags(purgeDryRun)
|
||||
}
|
||||
if err := c.AddFunc(a.config.PurgeTagsSchedule, task); err != nil {
|
||||
panic(fmt.Errorf("Invalid schedule format: %s", a.config.PurgeTagsSchedule))
|
||||
}
|
||||
c.Start()
|
||||
}
|
||||
|
||||
// Count tags in background.
|
||||
go a.client.CountTags(a.config.CacheRefreshInterval)
|
||||
@@ -97,45 +131,23 @@ func main() {
|
||||
a.eventListener = events.NewEventListener(a.config.EventDatabaseDriver, a.config.EventDatabaseLocation, a.config.EventRetentionDays)
|
||||
|
||||
// Template engine init.
|
||||
view := jet.NewHTMLSet("templates")
|
||||
view.SetDevelopmentMode(a.config.Debug)
|
||||
view.AddGlobal("registryHost", u.Host)
|
||||
view.AddGlobal("pretty_size", func(size interface{}) string {
|
||||
var value float64
|
||||
switch i := size.(type) {
|
||||
case gjson.Result:
|
||||
value = float64(i.Int())
|
||||
case int64:
|
||||
value = float64(i)
|
||||
}
|
||||
return registry.PrettySize(value)
|
||||
})
|
||||
view.AddGlobal("pretty_time", func(datetime interface{}) string {
|
||||
d := strings.Replace(datetime.(string), "T", " ", 1)
|
||||
d = strings.Replace(d, "Z", "", 1)
|
||||
return strings.Split(d, ".")[0]
|
||||
})
|
||||
view.AddGlobal("parse_map", func(m interface{}) string {
|
||||
var res string
|
||||
for _, k := range registry.SortedMapKeys(m) {
|
||||
res = res + fmt.Sprintf(`<tr><td style="padding: 0 10px; width: 20%%">%s</td><td style="padding: 0 10px">%v</td></tr>`, k, m.(map[string]interface{})[k])
|
||||
}
|
||||
return res
|
||||
})
|
||||
e := echo.New()
|
||||
e.Renderer = &template{View: view}
|
||||
e.Renderer = setupRenderer(a.config.Debug, u.Host, a.config.BasePath)
|
||||
|
||||
// Web routes.
|
||||
e.Static("/static", "static")
|
||||
e.GET("/", a.viewRepositories)
|
||||
e.GET("/:namespace", a.viewRepositories)
|
||||
e.GET("/:namespace/:repo", a.viewTags)
|
||||
e.GET("/:namespace/:repo/:tag", a.viewTagInfo)
|
||||
e.GET("/:namespace/:repo/:tag/delete", a.deleteTag)
|
||||
e.GET("/events", a.viewLog)
|
||||
e.Static(a.config.BasePath+"/static", "static")
|
||||
if a.config.BasePath != "" {
|
||||
e.GET(a.config.BasePath, a.viewRepositories)
|
||||
}
|
||||
e.GET(a.config.BasePath+"/", a.viewRepositories)
|
||||
e.GET(a.config.BasePath+"/:namespace", a.viewRepositories)
|
||||
e.GET(a.config.BasePath+"/:namespace/:repo", a.viewTags)
|
||||
e.GET(a.config.BasePath+"/:namespace/:repo/:tag", a.viewTagInfo)
|
||||
e.GET(a.config.BasePath+"/:namespace/:repo/:tag/delete", a.deleteTag)
|
||||
e.GET(a.config.BasePath+"/events", a.viewLog)
|
||||
|
||||
// Protected event listener.
|
||||
p := e.Group("/api")
|
||||
p := e.Group(a.config.BasePath + "/api")
|
||||
p.Use(middleware.KeyAuthWithConfig(middleware.KeyAuthConfig{
|
||||
Validator: middleware.KeyAuthValidator(func(token string, c echo.Context) (bool, error) {
|
||||
return token == a.config.EventListenerToken, nil
|
||||
@@ -146,23 +158,6 @@ func main() {
|
||||
e.Logger.Fatal(e.Start(a.config.ListenAddr))
|
||||
}
|
||||
|
||||
// Render render template.
|
||||
func (r *template) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
|
||||
t, err := r.View.GetTemplate(name)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("Fatal error template file: %s", err))
|
||||
}
|
||||
vars, ok := data.(jet.VarMap)
|
||||
if !ok {
|
||||
vars = jet.VarMap{}
|
||||
}
|
||||
err = t.Execute(w, vars, nil)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("Error rendering template %s: %s", name, err))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *apiClient) viewRepositories(c echo.Context) error {
|
||||
namespace := c.Param("namespace")
|
||||
if namespace == "" {
|
||||
@@ -170,7 +165,6 @@ func (a *apiClient) viewRepositories(c echo.Context) error {
|
||||
}
|
||||
|
||||
repos, _ := a.client.Repositories(true)[namespace]
|
||||
|
||||
data := jet.VarMap{}
|
||||
data.Set("namespace", namespace)
|
||||
data.Set("namespaces", a.client.Namespaces())
|
||||
@@ -196,7 +190,8 @@ func (a *apiClient) viewTags(c echo.Context) error {
|
||||
data.Set("repo", repo)
|
||||
data.Set("tags", tags)
|
||||
data.Set("deleteAllowed", deleteAllowed)
|
||||
data.Set("events", a.eventListener.GetEvents(repo))
|
||||
repoPath, _ = url.PathUnescape(repoPath)
|
||||
data.Set("events", a.eventListener.GetEvents(repoPath))
|
||||
|
||||
return c.Render(http.StatusOK, "tags.html", data)
|
||||
}
|
||||
@@ -212,7 +207,7 @@ func (a *apiClient) viewTagInfo(c echo.Context) error {
|
||||
|
||||
sha256, infoV1, infoV2 := a.client.TagInfo(repoPath, tag, false)
|
||||
if infoV1 == "" || infoV2 == "" {
|
||||
return c.Redirect(http.StatusSeeOther, fmt.Sprintf("/%s/%s", namespace, repo))
|
||||
return c.Redirect(http.StatusSeeOther, fmt.Sprintf("%s/%s/%s", a.config.BasePath, namespace, repo))
|
||||
}
|
||||
|
||||
var imageSize int64
|
||||
@@ -272,7 +267,7 @@ func (a *apiClient) deleteTag(c echo.Context) error {
|
||||
a.client.DeleteTag(repoPath, tag)
|
||||
}
|
||||
|
||||
return c.Redirect(http.StatusSeeOther, fmt.Sprintf("/%s/%s", namespace, repo))
|
||||
return c.Redirect(http.StatusSeeOther, fmt.Sprintf("%s/%s/%s", a.config.BasePath, namespace, repo))
|
||||
}
|
||||
|
||||
// checkDeletePermission check if tag deletion is allowed whether by anyone or permitted users.
|
||||
@@ -302,3 +297,8 @@ func (a *apiClient) receiveEvents(c echo.Context) error {
|
||||
a.eventListener.ProcessEvents(c.Request())
|
||||
return c.String(http.StatusOK, "OK")
|
||||
}
|
||||
|
||||
// purgeOldTags purges old tags.
|
||||
func (a *apiClient) purgeOldTags(dryRun bool) {
|
||||
registry.PurgeOldTags(a.client, dryRun, a.config.PurgeTagsKeepDays, a.config.PurgeTagsKeepCount)
|
||||
}
|
||||
|
@@ -69,7 +69,7 @@ func NewClient(url string, verifyTLS bool, username, password string) *Client {
|
||||
c.logger.Warn("No token auth service discovered from ", c.url)
|
||||
return nil
|
||||
}
|
||||
} else if strings.HasPrefix(authHeader, "Basic") {
|
||||
} else if strings.HasPrefix(strings.ToLower(authHeader), "basic") {
|
||||
c.request = c.request.SetBasicAuth(c.username, c.password)
|
||||
c.logger.Info("It was discovered the registry is configured with HTTP basic auth.")
|
||||
}
|
||||
@@ -148,6 +148,9 @@ func (c *Client) Namespaces() []string {
|
||||
for k := range c.repos {
|
||||
namespaces = append(namespaces, k)
|
||||
}
|
||||
if !ItemInSlice("library", namespaces) {
|
||||
namespaces = append(namespaces, "library")
|
||||
}
|
||||
sort.Strings(namespaces)
|
||||
return namespaces
|
||||
}
|
||||
|
@@ -42,3 +42,13 @@ func PrettySize(size float64) string {
|
||||
}
|
||||
return fmt.Sprintf("%.*f %s", 0, size, units[i])
|
||||
}
|
||||
|
||||
// ItemInSlice check if item is an element of slice
|
||||
func ItemInSlice(item string, slice []string) bool {
|
||||
for _, i := range slice {
|
||||
if i == item {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@@ -45,3 +45,13 @@ func TestPrettySize(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestItemInSlice(t *testing.T) {
|
||||
a := []string{"abc", "def", "ghi"}
|
||||
convey.Convey("Check whether element is in slice", t, func() {
|
||||
convey.So(ItemInSlice("abc", a), convey.ShouldBeTrue)
|
||||
convey.So(ItemInSlice("ghi", a), convey.ShouldBeTrue)
|
||||
convey.So(ItemInSlice("abc1", a), convey.ShouldBeFalse)
|
||||
convey.So(ItemInSlice("gh", a), convey.ShouldBeFalse)
|
||||
})
|
||||
}
|
||||
|
76
template.go
Normal file
76
template.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/CloudyKit/jet"
|
||||
"github.com/labstack/echo"
|
||||
"github.com/quiq/docker-registry-ui/registry"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
// Template Jet template.
|
||||
type Template struct {
|
||||
View *jet.Set
|
||||
}
|
||||
|
||||
// Render render template.
|
||||
func (r *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
|
||||
t, err := r.View.GetTemplate(name)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("Fatal error template file: %s", err))
|
||||
}
|
||||
vars, ok := data.(jet.VarMap)
|
||||
if !ok {
|
||||
vars = jet.VarMap{}
|
||||
}
|
||||
err = t.Execute(w, vars, nil)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("Error rendering template %s: %s", name, err))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// setupRenderer template engine init.
|
||||
func setupRenderer(debug bool, registryHost, basePath string) *Template {
|
||||
view := jet.NewHTMLSet("templates")
|
||||
view.SetDevelopmentMode(debug)
|
||||
|
||||
view.AddGlobal("version", version)
|
||||
view.AddGlobal("basePath", basePath)
|
||||
view.AddGlobal("registryHost", registryHost)
|
||||
view.AddGlobal("pretty_size", func(size interface{}) string {
|
||||
var value float64
|
||||
switch i := size.(type) {
|
||||
case gjson.Result:
|
||||
value = float64(i.Int())
|
||||
case int64:
|
||||
value = float64(i)
|
||||
}
|
||||
return registry.PrettySize(value)
|
||||
})
|
||||
view.AddGlobal("pretty_time", func(datetime interface{}) string {
|
||||
d := strings.Replace(datetime.(string), "T", " ", 1)
|
||||
d = strings.Replace(d, "Z", "", 1)
|
||||
return strings.Split(d, ".")[0]
|
||||
})
|
||||
view.AddGlobal("parse_map", func(m interface{}) string {
|
||||
var res string
|
||||
for _, k := range registry.SortedMapKeys(m) {
|
||||
res = res + fmt.Sprintf(`<tr><td style="padding: 0 10px; width: 20%%">%s</td><td style="padding: 0 10px">%v</td></tr>`, k, m.(map[string]interface{})[k])
|
||||
}
|
||||
return res
|
||||
})
|
||||
view.AddGlobal("url_decode", func(m interface{}) string {
|
||||
res, err := url.PathUnescape(m.(string))
|
||||
if err != nil {
|
||||
return m.(string)
|
||||
}
|
||||
return res
|
||||
})
|
||||
|
||||
return &Template{View: view}
|
||||
}
|
@@ -15,15 +15,15 @@
|
||||
<h2>Docker Registry UI</h2>
|
||||
</div>
|
||||
<div style="float: right">
|
||||
<a href="/events">Event Log</a>
|
||||
<a href="{{ basePath }}/events">Event Log</a>
|
||||
</div>
|
||||
<div style="clear: both"></div>
|
||||
|
||||
{{yield body()}}
|
||||
|
||||
<div style="padding: 10px 0; margin-bottom: 20px">
|
||||
<div style="float: left">
|
||||
© 2017-2018 <a href="https://goquiq.com">Quiq Inc.</a>
|
||||
<div style="text-align: center; color:darkgrey">
|
||||
Docker Registry UI v{{version}} © 2017-2018 <a href="https://goquiq.com">Quiq Inc.</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -6,7 +6,10 @@
|
||||
$('#datatable').DataTable({
|
||||
"pageLength": 10,
|
||||
"order": [[ 4, 'desc' ]],
|
||||
"stateSave": true
|
||||
"stateSave": true,
|
||||
"language": {
|
||||
"emptyTable": "No events."
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -14,7 +17,7 @@
|
||||
|
||||
{{block body()}}
|
||||
<ol class="breadcrumb">
|
||||
<li><a href="/">Home</a></li>
|
||||
<li><a href="{{ basePath }}/">Home</a></li>
|
||||
<li class="active">Event Log</li>
|
||||
</ol>
|
||||
|
||||
|
@@ -3,19 +3,25 @@
|
||||
{{block head()}}
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$('#datatable').DataTable({
|
||||
"pageLength": 25,
|
||||
"stateSave": true
|
||||
});
|
||||
$('#namespace').on('change', function (e) {
|
||||
window.location = '/' + this.value;
|
||||
window.location = '{{ basePath }}/' + this.value;
|
||||
});
|
||||
if (window.location.pathname == '/') {
|
||||
namespace = window.location.pathname;
|
||||
namespace = namespace.replace("{{ basePath }}", "");
|
||||
if (namespace == '/') {
|
||||
namespace = 'library';
|
||||
} else {
|
||||
namespace = window.location.pathname.split('/')[1]
|
||||
namespace = namespace.split('/')[1]
|
||||
}
|
||||
$('#namespace').val(namespace);
|
||||
|
||||
$('#datatable').DataTable({
|
||||
"pageLength": 25,
|
||||
"stateSave": true,
|
||||
"language": {
|
||||
"emptyTable": "No repositories in \"" + namespace + "\" namespace."
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{{end}}
|
||||
@@ -23,15 +29,19 @@
|
||||
{{block body()}}
|
||||
<div style="float: right">
|
||||
<select id="namespace" class="form-control input-sm" style="height: 36px">
|
||||
<option value="" disabled>-- Namespace --</option>
|
||||
{{range namespace := namespaces}}
|
||||
<option value="{{ namespace }}">{{ namespace }}</option>
|
||||
{{end}}
|
||||
</select>
|
||||
</div>
|
||||
<div style="float: right">
|
||||
<ol class="breadcrumb">
|
||||
<li class="active">Namespace</li>
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
<ol class="breadcrumb">
|
||||
<li><a href="/">Home</a></li>
|
||||
<li><a href="{{ basePath }}/">Home</a></li>
|
||||
</ol>
|
||||
|
||||
<table id="datatable" class="table table-striped table-bordered">
|
||||
@@ -44,7 +54,7 @@
|
||||
<tbody>
|
||||
{{range repo := repos}}
|
||||
<tr>
|
||||
<td><a href="/{{ namespace }}/{{ repo }}">{{ repo }}</a></td>
|
||||
<td><a href="{{ basePath }}/{{ namespace }}/{{ repo|url }}">{{ repo }}</a></td>
|
||||
<td>{{ tagCounts[namespace+"/"+repo] }}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
|
@@ -4,11 +4,11 @@
|
||||
|
||||
{{block body()}}
|
||||
<ol class="breadcrumb">
|
||||
<li><a href="/">Home</a></li>
|
||||
<li><a href="{{ basePath }}/">Home</a></li>
|
||||
{{if namespace != "library"}}
|
||||
<li><a href="/{{ namespace }}">{{ namespace }}</a></li>
|
||||
<li><a href="{{ basePath }}/{{ namespace }}">{{ namespace }}</a></li>
|
||||
{{end}}
|
||||
<li><a href="/{{ namespace }}/{{ repo }}">{{ repo }}</a></li>
|
||||
<li><a href="{{ basePath }}/{{ namespace }}/{{ repo }}">{{ repo|url_decode }}</a></li>
|
||||
<li class="active">{{ tag }}</li>
|
||||
</ol>
|
||||
<table class="table table-striped table-bordered">
|
||||
|
@@ -1,7 +1,7 @@
|
||||
{{extends "base.html"}}
|
||||
|
||||
{{block head()}}
|
||||
<script type="text/javascript" src="/static/bootstrap-confirmation.min.js"></script>
|
||||
<script type="text/javascript" src="{{ basePath }}/static/bootstrap-confirmation.min.js"></script>
|
||||
<script type="text/javascript" src="https://cdn.datatables.net/plug-ins/1.10.16/sorting/natural.js"></script>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
@@ -11,7 +11,10 @@
|
||||
"stateSave": true,
|
||||
columnDefs: [
|
||||
{ type: 'natural', targets: 0 }
|
||||
]
|
||||
],
|
||||
"language": {
|
||||
"emptyTable": "No tags in this repository."
|
||||
}
|
||||
})
|
||||
function populateConfirmation() {
|
||||
$('[data-toggle=confirmation]').confirmation({
|
||||
@@ -29,11 +32,11 @@
|
||||
|
||||
{{block body()}}
|
||||
<ol class="breadcrumb">
|
||||
<li><a href="/">Home</a></li>
|
||||
<li><a href="{{ basePath }}/">Home</a></li>
|
||||
{{if namespace != "library"}}
|
||||
<li><a href="/{{ namespace }}">{{ namespace }}</a></li>
|
||||
<li><a href="{{ basePath }}/{{ namespace }}">{{ namespace }}</a></li>
|
||||
{{end}}
|
||||
<li class="active">{{ repo }}</li>
|
||||
<li class="active">{{ repo|url_decode }}</li>
|
||||
</ol>
|
||||
|
||||
<table id="datatable" class="table table-striped table-bordered">
|
||||
@@ -46,9 +49,9 @@
|
||||
{{range tag := tags}}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="/{{ namespace }}/{{ repo }}/{{ tag }}">{{ tag }}</a>
|
||||
<a href="{{ basePath }}/{{ namespace }}/{{ repo }}/{{ tag }}">{{ tag }}</a>
|
||||
{{if deleteAllowed}}
|
||||
<a href="/{{ namespace }}/{{ repo }}/{{ tag }}/delete" data-toggle="confirmation" class="btn btn-danger btn-xs pull-right" role="button">Delete</a>
|
||||
<a href="{{ basePath }}/{{ namespace }}/{{ repo }}/{{ tag }}/delete" data-toggle="confirmation" class="btn btn-danger btn-xs pull-right" role="button">Delete</a>
|
||||
{{end}}
|
||||
</td>
|
||||
</tr>
|
||||
|
3
version.go
Normal file
3
version.go
Normal file
@@ -0,0 +1,3 @@
|
||||
package main
|
||||
|
||||
const version = "0.7.4"
|
Reference in New Issue
Block a user