Merge remote-tracking branch 'upstream/master'

This commit is contained in:
kunw 2016-04-05 11:21:46 +08:00
commit 69846a7a7c
9 changed files with 124 additions and 103 deletions

View File

@ -1,10 +1,12 @@
log: version: '2'
services:
log:
build: ./log/ build: ./log/
volumes: volumes:
- /var/log/harbor/:/var/log/docker/ - /var/log/harbor/:/var/log/docker/
ports: ports:
- 1514:514 - 1514:514
registry: registry:
image: library/registry:2.3.0 image: library/registry:2.3.0
volumes: volumes:
- /data/registry:/storage - /data/registry:/storage
@ -13,50 +15,53 @@ registry:
- 5001:5001 - 5001:5001
command: command:
/etc/registry/config.yml /etc/registry/config.yml
links: depends_on:
- log - log
log_driver: "syslog" logging:
log_opt: driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514" syslog-address: "tcp://127.0.0.1:1514"
syslog-tag: "registry" syslog-tag: "registry"
mysql: mysql:
build: ./db/ build: ./db/
volumes: volumes:
- /data/database:/var/lib/mysql - /data/database:/var/lib/mysql
env_file: env_file:
- ./config/db/env - ./config/db/env
links: depends_on:
- log - log
log_driver: "syslog" logging:
log_opt: driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514" syslog-address: "tcp://127.0.0.1:1514"
syslog-tag: "mysql" syslog-tag: "mysql"
ui: ui:
build: ../ build: ../
env_file: env_file:
- ./config/ui/env - ./config/ui/env
volumes: volumes:
- ./config/ui/app.conf:/etc/ui/app.conf - ./config/ui/app.conf:/etc/ui/app.conf
- ./config/ui/private_key.pem:/etc/ui/private_key.pem - ./config/ui/private_key.pem:/etc/ui/private_key.pem
links: depends_on:
- registry
- mysql
- log - log
log_driver: "syslog" logging:
log_opt: driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514" syslog-address: "tcp://127.0.0.1:1514"
syslog-tag: "ui" syslog-tag: "ui"
proxy: proxy:
image: library/nginx:1.9 image: library/nginx:1.9
volumes: volumes:
- ./config/nginx:/etc/nginx - ./config/nginx:/etc/nginx
links:
- ui
- registry
- log
ports: ports:
- 80:80 - 80:80
log_driver: "syslog" depends_on:
log_opt: - mysql
- registry
- ui
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514" syslog-address: "tcp://127.0.0.1:1514"
syslog-tag: "proxy" syslog-tag: "proxy"

View File

@ -1,25 +1,34 @@
## CONFIGURATIONS ## Configuration file of Harbor
#The endpoint for user to access UI and registry service
hostname = mydomain.com #The IP address or hostname to access admin UI and registry service.
#The protocol for accessing the UI and token/notification service, by default it is http #DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
#User can set it to https if ssl is setup on nginx hostname = reg.mydomain.com
#The protocol for accessing the UI and token/notification service, by default it is http.
#It can be set to https if ssl is enabled on nginx.
ui_url_protocol = http ui_url_protocol = http
#Email settings for ui to send password resetting emails
#Email account settings for sending out password resetting emails.
email_server = smtp.mydomain.com email_server = smtp.mydomain.com
email_server_port = 25 email_server_port = 25
email_username = sample_admin@mydomain.com email_username = sample_admin@mydomain.com
email_password = abc email_password = abc
email_from = admin <sample_admin@mydomain.com> email_from = admin <sample_admin@mydomain.com>
##The password of harbor admin
##The password of Harbor admin, change this before any production use.
harbor_admin_password= Harbor12345 harbor_admin_password= Harbor12345
##By default the auth mode is db_auth, i.e. the creadentials are stored in a databse
#please set it to ldap_auth if you want to verify user's credentials against an ldap server. ##By default the auth mode is db_auth, i.e. the credentials are stored in a local database.
#Set it to ldap_auth if you want to verify a user's credentials against an LDAP server.
auth_mode = db_auth auth_mode = db_auth
#The url for ldap endpoint
#The url for an ldap endpoint.
ldap_url = ldaps://ldap.mydomain.com ldap_url = ldaps://ldap.mydomain.com
#The basedn template for verifying the user's password
#The basedn template to look up a user in LDAP and verify the user's password.
ldap_basedn = uid=%s,ou=people,dc=mydomain,dc=com ldap_basedn = uid=%s,ou=people,dc=mydomain,dc=com
#The password for root user of db
#The password for the root user of mysql db, change this before any production use.
db_password = root123 db_password = root123
#Switch for self-registration feature #Switch for self-registration feature
self_registration = on self_registration = on

View File

@ -61,6 +61,7 @@ for f in conf_files:
render(os.path.join(templates_dir, "ui", "env"), render(os.path.join(templates_dir, "ui", "env"),
ui_conf_env, ui_conf_env,
hostname=hostname, hostname=hostname,
db_password=db_password,
ui_url=ui_url, ui_url=ui_url,
auth_mode=auth_mode, auth_mode=auth_mode,
admin_pwd=harbor_admin_password, admin_pwd=harbor_admin_password,

View File

@ -27,7 +27,7 @@ notifications:
endpoints: endpoints:
- name: harbor - name: harbor
disabled: false disabled: false
url: $ui_url/service/notifications url: http://ui/service/notifications
timeout: 500 timeout: 500
threshold: 5 threshold: 5
backoff: 1000 backoff: 1000

View File

@ -1,5 +1,7 @@
MYSQL_HOST=mysql MYSQL_HOST=mysql
MYSQL_PORT=3306
MYSQL_USR=root MYSQL_USR=root
MYSQL_PWD=$db_password
REGISTRY_URL=http://registry:5000 REGISTRY_URL=http://registry:5000
CONFIG_PATH=/etc/ui/app.conf CONFIG_PATH=/etc/ui/app.conf
HARBOR_REG_URL=$hostname HARBOR_REG_URL=$hostname

View File

@ -66,18 +66,11 @@ func GenerateRandomString() (string, error) {
func InitDB() { func InitDB() {
orm.RegisterDriver("mysql", orm.DRMySQL) orm.RegisterDriver("mysql", orm.DRMySQL)
addr := os.Getenv("MYSQL_HOST") addr := os.Getenv("MYSQL_HOST")
if len(addr) == 0 { port := os.Getenv("MYSQL_PORT")
addr = os.Getenv("MYSQL_PORT_3306_TCP_ADDR")
}
port := os.Getenv("MYSQL_PORT_3306_TCP_PORT")
username := os.Getenv("MYSQL_USR") username := os.Getenv("MYSQL_USR")
password := os.Getenv("MYSQL_PWD")
password := os.Getenv("MYSQL_ENV_MYSQL_ROOT_PASSWORD") log.Debugf("db url: %s:%s, db user: %s", addr, port, username)
if len(password) == 0 {
password = os.Getenv("MYSQL_PWD")
}
dbStr := username + ":" + password + "@tcp(" + addr + ":" + port + ")/registry" dbStr := username + ":" + password + "@tcp(" + addr + ":" + port + ")/registry"
ch := make(chan int, 1) ch := make(chan int, 1)
go func() { go func() {

View File

@ -128,8 +128,8 @@ func TestMain(m *testing.M) {
log.Infof("DB_HOST: %s, DB_USR: %s, DB_PORT: %s, DB_PWD: %s\n", dbHost, dbUser, dbPort, dbPassword) log.Infof("DB_HOST: %s, DB_USR: %s, DB_PORT: %s, DB_PWD: %s\n", dbHost, dbUser, dbPort, dbPassword)
os.Setenv("MYSQL_PORT_3306_TCP_ADDR", dbHost) os.Setenv("MYSQL_HOST", dbHost)
os.Setenv("MYSQL_PORT_3306_TCP_PORT", dbPort) os.Setenv("MYSQL_PORT", dbPort)
os.Setenv("MYSQL_USR", dbUser) os.Setenv("MYSQL_USR", dbUser)
os.Setenv("MYSQL_PWD", dbPassword) os.Setenv("MYSQL_PWD", dbPassword)
os.Setenv("AUTH_MODE", "db_auth") os.Setenv("AUTH_MODE", "db_auth")

View File

@ -5,7 +5,7 @@ Harbor can be installed from the source code by using "docker-compose up" comman
Harbor is deployed as several Docker containers. Hence, it can be deployed on any Linux distribution that supports Docker. Harbor is deployed as several Docker containers. Hence, it can be deployed on any Linux distribution that supports Docker.
Before deploying Harbor, the target machine requires Python, Docker, Docker Compose to be installed. Before deploying Harbor, the target machine requires Python, Docker, Docker Compose to be installed.
* Python should be version 2.7 or higher. Some Linux distributions (Gentoo, Arch) may not have a Python interpreter installed by default. On those systems, you need to install Python manually. * Python should be version 2.7 or higher. Some Linux distributions (Gentoo, Arch) may not have a Python interpreter installed by default. On those systems, you need to install Python manually.
* The Docker engine should be version 1.8 or higher. For the details to install Docker engine, please refer to: https://docs.docker.com/engine/installation/ * The Docker engine should be version 1.10 or higher. For the details to install Docker engine, please refer to: https://docs.docker.com/engine/installation/
* The Docker Compose needs to be version 1.6.0 or higher. For the details to install Docker compose, please refer to: https://docs.docker.com/compose/install/ * The Docker Compose needs to be version 1.6.0 or higher. For the details to install Docker compose, please refer to: https://docs.docker.com/compose/install/
### Configuration of Harbor ### Configuration of Harbor

View File

@ -27,6 +27,8 @@ import (
var logger = New(os.Stdout, NewTextFormatter(), WarningLevel) var logger = New(os.Stdout, NewTextFormatter(), WarningLevel)
func init() { func init() {
logger.callDepth = 3
// TODO add item in configuaration file // TODO add item in configuaration file
lvl := os.Getenv("LOG_LEVEL") lvl := os.Getenv("LOG_LEVEL")
if len(lvl) == 0 { if len(lvl) == 0 {
@ -49,6 +51,7 @@ type Logger struct {
out io.Writer out io.Writer
fmtter Formatter fmtter Formatter
lvl Level lvl Level
callDepth int
mu sync.Mutex mu sync.Mutex
} }
@ -58,6 +61,7 @@ func New(out io.Writer, fmtter Formatter, lvl Level) *Logger {
out: out, out: out,
fmtter: fmtter, fmtter: fmtter,
lvl: lvl, lvl: lvl,
callDepth: 2,
} }
} }
@ -117,7 +121,7 @@ func (l *Logger) output(record *Record) (err error) {
// Debug ... // Debug ...
func (l *Logger) Debug(v ...interface{}) { func (l *Logger) Debug(v ...interface{}) {
if l.lvl <= DebugLevel { if l.lvl <= DebugLevel {
line := line(2) line := line(l.callDepth)
record := NewRecord(time.Now(), fmt.Sprint(v...), line, DebugLevel) record := NewRecord(time.Now(), fmt.Sprint(v...), line, DebugLevel)
l.output(record) l.output(record)
} }
@ -126,7 +130,7 @@ func (l *Logger) Debug(v ...interface{}) {
// Debugf ... // Debugf ...
func (l *Logger) Debugf(format string, v ...interface{}) { func (l *Logger) Debugf(format string, v ...interface{}) {
if l.lvl <= DebugLevel { if l.lvl <= DebugLevel {
line := line(2) line := line(l.callDepth)
record := NewRecord(time.Now(), fmt.Sprintf(format, v...), line, DebugLevel) record := NewRecord(time.Now(), fmt.Sprintf(format, v...), line, DebugLevel)
l.output(record) l.output(record)
} }
@ -167,7 +171,7 @@ func (l *Logger) Warningf(format string, v ...interface{}) {
// Error ... // Error ...
func (l *Logger) Error(v ...interface{}) { func (l *Logger) Error(v ...interface{}) {
if l.lvl <= ErrorLevel { if l.lvl <= ErrorLevel {
line := line(2) line := line(l.callDepth)
record := NewRecord(time.Now(), fmt.Sprint(v...), line, ErrorLevel) record := NewRecord(time.Now(), fmt.Sprint(v...), line, ErrorLevel)
l.output(record) l.output(record)
} }
@ -176,7 +180,7 @@ func (l *Logger) Error(v ...interface{}) {
// Errorf ... // Errorf ...
func (l *Logger) Errorf(format string, v ...interface{}) { func (l *Logger) Errorf(format string, v ...interface{}) {
if l.lvl <= ErrorLevel { if l.lvl <= ErrorLevel {
line := line(2) line := line(l.callDepth)
record := NewRecord(time.Now(), fmt.Sprintf(format, v...), line, ErrorLevel) record := NewRecord(time.Now(), fmt.Sprintf(format, v...), line, ErrorLevel)
l.output(record) l.output(record)
} }
@ -185,7 +189,7 @@ func (l *Logger) Errorf(format string, v ...interface{}) {
// Fatal ... // Fatal ...
func (l *Logger) Fatal(v ...interface{}) { func (l *Logger) Fatal(v ...interface{}) {
if l.lvl <= FatalLevel { if l.lvl <= FatalLevel {
line := line(2) line := line(l.callDepth)
record := NewRecord(time.Now(), fmt.Sprint(v...), line, FatalLevel) record := NewRecord(time.Now(), fmt.Sprint(v...), line, FatalLevel)
l.output(record) l.output(record)
} }
@ -195,7 +199,7 @@ func (l *Logger) Fatal(v ...interface{}) {
// Fatalf ... // Fatalf ...
func (l *Logger) Fatalf(format string, v ...interface{}) { func (l *Logger) Fatalf(format string, v ...interface{}) {
if l.lvl <= FatalLevel { if l.lvl <= FatalLevel {
line := line(2) line := line(l.callDepth)
record := NewRecord(time.Now(), fmt.Sprintf(format, v...), line, FatalLevel) record := NewRecord(time.Now(), fmt.Sprintf(format, v...), line, FatalLevel)
l.output(record) l.output(record)
} }
@ -259,5 +263,12 @@ func line(calldepth int) string {
line = 0 line = 0
} }
return fmt.Sprintf("%s:%d", file, line) for i := len(file) - 2; i > 0; i-- {
if file[i] == os.PathSeparator {
file = file[i+1:]
break
}
}
return fmt.Sprintf("[%s:%d]:", file, line)
} }