Skip to content

Commit

Permalink
Dockerfile is now OK in Alpine
Browse files Browse the repository at this point in the history
  • Loading branch information
matcornic committed Feb 12, 2017
1 parent 63fadc5 commit 5815049
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 36 deletions.
23 changes: 8 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM mhart/alpine-node:base
FROM node:alpine
LABEL Name=docktor Authors="@gwleclerc,@matcornic,@Thiht"

WORKDIR /opt/docktor

ENV GOPATH="/opt/go/"
ENV DOCKTOR_PATH="${GOPATH}/src/github.com/soprasteria/docktor"
ENV PATH "$PATH:$GOPATH/bin:/opt/yarn/bin"
ENV PATH "$PATH:$GOPATH/bin"

COPY . "${DOCKTOR_PATH}"

Expand All @@ -14,6 +14,8 @@ COPY . "${DOCKTOR_PATH}"
# 3. Delete dependencies and temp files
# Note : Just one layer for this steps to avoid dependencies being commited to different layers,
# resulting in a larger image.

# Gopkg.in error : https://github.com/niemeyer/gopkg/issues/50
RUN set -ex \
&& apk add --no-cache --virtual .build-deps \
bash \
Expand All @@ -23,31 +25,22 @@ RUN set -ex \
make \
g++ \
curl \
&& curl -sL https://yarnpkg.com/latest.tar.gz -o yarn.tar.gz \
&& tar xvf yarn.tar.gz \
&& mv dist /opt/yarn \
&& go get -v github.com/kardianos/govendor \
&& echo '{ "allow_root": true }' > /root/.bowerrc \
&& git config --global http.https://gopkg.in.followRedirects true \
\
&& cd "${DOCKTOR_PATH}" \
&& govendor sync -v \
&& yarn install \
&& yarn run dist \
&& npm install \
&& npm run dist \
&& mv dist/* /opt/docktor \
\
&& yarn cache clean \
&& rm /opt/docktor/yarn.tar.gz \
&& npm cache clean \
&& apk del .build-deps \
&& rm -rf "$GOPATH" \
&& rm -rf /opt/yarn \
&& rm -rf /root && mkdir /root \
&& rm -rf /usr/bin/node

# TODO : add docktor user instead of root
# TODO : add link to mongo
# TODO : create docker-compose with mongo
# TODO : Make Docktor able to handle env variables like DOCKTOR_MONGO_URL for example.

ENTRYPOINT ["./docktor"]
CMD ["serve"]

Expand Down
44 changes: 27 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,39 @@ Here is an example file:
env = "dev"

[server]
mongo-addr = "localhost:27017"
[server.mongo]
addr = "localhost:27017"
username = ""
password = ""
[server.redis]
addr = "localhost:6379"
password = ""

[auth]
jwt-secret = "a-unique-secret-for-secure-password-hosting"
jwt-secret = "a-unique-secret-for-secure-password-hosting"
reset-pwd-secret = "a-unique-secret-for-reset-password-token-generation"
bcrypt-pepper = "a-pepper-used-when-storing-password-to-db"

[smtp]
server = ""
user = ""
identity = ""
server = ""
user = ""
identity = ""
password = ""
sender = ""

[ldap]
address = ""
baseDN = ""
bindDN = ""
bindPassword = ""
searchFilter = ""

[ldap.attr]
username = ""
firstname = ""
lastname = ""
realname = ""
email = ""
address = ""
baseDN = ""
bindDN = ""
bindPassword = ""
searchFilter = ""

[ldap.attr]
username = ""
firstname = ""
lastname = ""
realname = ""
email = ""
```

Then, you can run Docktor in dev mode, with live reload, with the command:
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func Execute() {
func init() {
cobra.OnInitialize(initLogger, initConfig)
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "Config file (default is $HOME/.docktor.yaml)")
RootCmd.PersistentFlags().StringP("level", "l", "warning", "Choose the logger level: debug, info, warning, error, fatal, panic")
RootCmd.PersistentFlags().StringP("level", "l", "info", "Choose the logger level: debug, info, warning, error, fatal, panic")
RootCmd.PersistentFlags().Int("log-max-size", 100, "Max log file size in megabytes")
RootCmd.PersistentFlags().Int("log-max-age", 30, "Max log file age in days")
RootCmd.PersistentFlags().Int("log-max-backups", 3, "Max backup files to keep")
Expand Down
10 changes: 8 additions & 2 deletions model/docktor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"gopkg.in/mgo.v2"

"strings"
"time"

"github.com/soprasteria/docktor/model/daemons"
"github.com/soprasteria/docktor/model/groups"
Expand All @@ -15,21 +16,26 @@ import (
"github.com/spf13/viper"
)

const mongoTimeout = 10 * time.Second

// Session stores mongo session
var session *mgo.Session

// Connect connects to mongodb
func Connect() {
uri := viper.GetString("server.mongo.addr")
log.WithField("uris", uri).WithField("timeout", mongoTimeout).Info("Connecting to Mongo cluster...")
s, err := mgo.DialWithInfo(&mgo.DialInfo{
Addrs: strings.Split(uri, ","),
Addrs: strings.Split(uri, ","),
Timeout: mongoTimeout,
})

if err != nil {
log.WithError(err).Fatal("Can't connect to mongo")
}

s.SetSafe(&mgo.Safe{})
log.Info("Connected to ", uri)
log.WithField("uris", uri).Info("Connecting to Mongo cluster [OK]")
session = s
}

Expand Down
4 changes: 3 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"net/http"

log "github.com/Sirupsen/logrus"
redis "gopkg.in/redis.v3"

"github.com/labstack/echo"
Expand Down Expand Up @@ -34,7 +35,6 @@ func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Con

//New instane of the server
func New(version string) {

redisClient := redis.NewClient(&redis.Options{
Addr: viper.GetString("server.redis.addr"),
Password: viper.GetString("server.redis.password"), // no password set
Expand Down Expand Up @@ -181,7 +181,9 @@ func New(version string) {
engine.Static("/fonts", "client/dist/fonts")

engine.GET("/*", GetIndex(version))
log.WithField("version", version).Info("Starting server...")
if err := engine.Start(":8080"); err != nil {
log.WithError(err).Fatal("Can't start server")
engine.Logger.Fatal(err.Error())
}
}
Expand Down

0 comments on commit 5815049

Please sign in to comment.