add Dockerfile (#94)

* add Dockerfile to build
This commit is contained in:
Victor Vrantchan 2016-08-25 09:25:02 -04:00 committed by GitHub
parent 41fe404ef1
commit 2946eeabfc
5 changed files with 91 additions and 24 deletions

6
Dockerfile Normal file
View File

@ -0,0 +1,6 @@
FROM alpine:3.4
MAINTAINER Kolide Developers <engineering@kolide.co>
COPY ./build/kolide /kolide
CMD ["/kolide", "serve"]

View File

@ -45,3 +45,11 @@ restart: stop
kolide serve & echo $$! > $(PID_FILE)
endif
docker:
# pull the latest version of the build container
docker pull kolide/kolide-builder:1.6
# run build step to build linux binary
docker run --rm -it -v $(shell pwd):/go/src/github.com/kolide/kolide-ose -v ${GOPATH}/pkg:/go/pkg kolide/kolide-builder:1.6 -B
# compose up
docker-compose up

27
development.yml Normal file
View File

@ -0,0 +1,27 @@
mysql:
image: mysql:5.7.13
environment:
MYSQL_ROOT_PASSWORD: toor
MYSQL_DATABASE: kolide
MYSQL_USER: kolide
MYSQL_PASSWORD: kolide
ports:
- "3306:3306"
mailhog:
image: mailhog/mailhog:latest
ports:
- "8025:8025"
- "1025:1025"
test:
image: kolide/kolide-builder:1.6
environment:
MYSQL_ADDR: 127.0.0.1
links:
- mysql
- mailhog
command:
- -C
volumes:
- ./:/go/src/github.com/kolide/kolide-ose

View File

@ -8,20 +8,14 @@ mysql:
ports:
- "3306:3306"
mailhog:
image: mailhog/mailhog:latest
ports:
- "8025:8025"
- "1025:1025"
test:
image: kolide/kolide-builder:1.6
environment:
MYSQL_ADDR: 127.0.0.1
links:
- mysql
- mailhog
command:
- -C
volumes:
- ./:/go/src/github.com/kolide/kolide-ose
kolide:
build: .
environment:
KOLIDE_SERVER_CERT: /osquery/kolide.crt
KOLIDE_SERVER_KEY: /osquery/kolide.key
ports:
- "8080:8080"
links:
- mysql
volumes:
- ./tools/osquery:/osquery

View File

@ -158,13 +158,22 @@ $7777777....$....$777$.....+DI..DDD..DDI...8D...D8......$D:..8D....8D...8D......
},
}
connString := fmt.Sprintf(
"%s:%s@(%s)/%s?charset=utf8&parseTime=True&loc=Local",
viper.GetString("mysql.username"),
viper.GetString("mysql.password"),
viper.GetString("mysql.address"),
viper.GetString("mysql.database"),
)
// get mysql connection from config or docker link
// temporary until config is redone
var connString string
if os.Getenv("MYSQL_PORT_3306_TCP_ADDR") != "" {
// try connection from docker link
connString = dockerMySQLconnString()
} else {
connString = fmt.Sprintf(
"%s:%s@(%s)/%s?charset=utf8&parseTime=True&loc=Local",
viper.GetString("mysql.username"),
viper.GetString("mysql.password"),
viper.GetString("mysql.address"),
viper.GetString("mysql.database"),
)
}
ds, err := datastore.New("gorm-mysql", connString)
if err != nil {
logrus.WithError(err).Fatal("error creating db connection")
@ -228,6 +237,29 @@ var dbCmd = &cobra.Command{
},
}
// detect that docker --link to mysql container is up and use
// the default env vars
func dockerMySQLconnString() string {
var (
username = os.Getenv("MYSQL_ENV_MYSQL_USER")
password = os.Getenv("MYSQL_ENV_MYSQL_PASSWORD")
host = os.Getenv("MYSQL_PORT_3306_TCP_ADDR")
port = os.Getenv("MYSQL_PORT_3306_TCP_PORT")
dbName = os.Getenv("MYSQL_ENV_MYSQL_DATABASE")
)
if host == "" {
return "" // no docker conn detected
}
logrus.Infoln("detected docker mysql link, using link environment vars")
connString := fmt.Sprintf(
"%s:%s@(%s:%s)/%s?charset=utf8&parseTime=True&loc=Local",
username, password, host, port, dbName,
)
return connString
}
// Due to a deficiency in viper (https://github.com/spf13/viper/issues/71), one
// can not set the default values of nested config elements. For example, if the
// "mysql" section of the config allows a user to define "username", "password",