Permalink
Browse files

Add option to run Supergiant in a container

- Dockerfile.dev and docker-compose for development
- Dockerfile.build for creating binaries
- Dockerfile for creating a tiny image for production
  • Loading branch information...
maikelvl committed Apr 10, 2017
1 parent a9e8bb0 commit 8506674c24cdb70498d04555d90656ce3ed6f483
Showing with 239 additions and 0 deletions.
  1. +1 −0 .dockerignore
  2. +2 −0 .gitignore
  3. +26 −0 Makefile
  4. +7 −0 README.md
  5. +48 −0 build/Dockerfile
  6. +30 −0 build/Dockerfile.build
  7. +45 −0 build/Dockerfile.dev
  8. +28 −0 build/bin/supergiant-server-wrapper
  9. +7 −0 build/entrypoint.sh
  10. +45 −0 docker-compose.yml
View
@@ -0,0 +1 @@
.git/
View
@@ -5,3 +5,5 @@ tmp/*
config/config.json
.sass-cache
/bindata/
/build/dist/
/data/
View
@@ -0,0 +1,26 @@
DOCKER_IMAGE_NAME := supergiant/supergiant
DOCKER_IMAGE_TAG := $(shell git describe --tags --always | tr -d v || echo 'latest')
.PHONY: build test push release
build-builder:
docker build -t supergiant-builder --file build/Dockerfile.build .
docker create --name supergiant-builder supergiant-builder
rm -rf build/dist
docker cp supergiant-builder:/go/src/github.com/supergiant/supergiant/dist build/dist
docker rm supergiant-builder
build-image:
docker build -t $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG) --file build/Dockerfile .
docker build -t $(DOCKER_IMAGE_NAME):latest --file build/Dockerfile .
test:
docker build -t supergiant --file build/Dockerfile.build .
docker run --rm supergiant govendor test +local
build: build-builder build-image
push:
docker push $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)
release: build push
View
@@ -139,6 +139,13 @@ Contribution Guidelines. Please see these links to get started.
## Development
#### Use Docker in development
docker-compose build server
docker-compose run --rm --service-ports server
#### Native go on your host
If you would like to contribute changes to Supergiant, first see the pages in
the section above, [Community and Contributing][Community and Contributing Anchor].
View
@@ -0,0 +1,48 @@
# This Dockerfile creates the image for production
# (does not contain go and sources, only binaries)
FROM alpine:3.5
RUN apk add --no-cache \
ca-certificates \
tzdata
ENV KUBECTL_VERSION="1.5.6"
RUN apk add --no-cache curl \
&& kubectl_version_latest="$(curl --silent --url https://github.com/kubernetes/kubernetes/releases/latest | sed -rn 's/.*tag\/v([^\"]*).*/\1/p')" \
&& kubectl_version="${KUBECTL_VERSION:-$kubectl_version_latest}" \
&& echo "current kubectl version: $kubectl_version" \
&& echo "latest kubectl version: $kubectl_version_latest" \
&& curl \
--url https://storage.googleapis.com/kubernetes-release/release/v${kubectl_version}/bin/linux/amd64/kubectl \
--output /usr/bin/kubectl \
&& chmod +x /usr/bin/kubectl \
&& apk del curl \
&& ( [ $(stat -c %s /usr/bin/kubectl) -gt 500 ] || exit 1 )
RUN apk add --no-cache openssl \
&& wget https://pkg.cfssl.org/R1.2/cfssl_linux-amd64 -O /usr/bin/cfssl \
&& wget https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64 -O /usr/bin/cfssljson \
&& chmod +x /usr/bin/cfssl* \
&& apk del openssl
EXPOSE 80 443
ENV SUPERGIANT_SQLITE_FILE="/data/.supergiant.db" \
SUPERGIANT_PUBLISH_HOST="0.0.0.0" \
SUPERGIANT_HTTP_PORT="80" \
SUPERGIANT_HTTPS_PORT="443" \
SUPERGIANT_SSL_CERT_FILE="/data/ssl/cert.pem" \
SUPERGIANT_SSL_KEY_FILE="/data/ssl/key.pem" \
SUPERGIANT_UI_ENABLED="true" \
SUPERGIANT_LOG_FILE="/dev/stdout" \
SUPERGIANT_LOG_LEVEL="debug" \
SUPERGIANT_DATA_DIR="/data" \
TIMEZONE="Etc/UTC"
COPY build/entrypoint.sh /
COPY build/bin/* /usr/local/bin/
COPY build/dist/bin /usr/bin
COPY build/dist/config-example /etc/supergiant-example
ENTRYPOINT ["/entrypoint.sh"]
CMD ["/usr/local/bin/supergiant-server-wrapper"]
View
@@ -0,0 +1,30 @@
# This Dockerfile only compiles the go binaries
FROM golang:1.7.4-alpine
RUN apk add --no-cache \
build-base \
git \
jq \
&& go get -u github.com/jteeuwen/go-bindata/... \
&& go get -u github.com/kardianos/govendor
WORKDIR /go/src/github.com/supergiant/supergiant
COPY config /go/src/github.com/supergiant/supergiant/config
COPY ui /go/src/github.com/supergiant/supergiant/ui
RUN go-bindata -pkg bindata -o bindata/bindata.go config/providers/... ui/assets/... ui/views/...
COPY cmd /go/src/github.com/supergiant/supergiant/cmd
COPY pkg /go/src/github.com/supergiant/supergiant/pkg
COPY test /go/src/github.com/supergiant/supergiant/test
COPY vendor /go/src/github.com/supergiant/supergiant/vendor
RUN go build -o dist/bin/supergiant-server cmd/server/server.go
RUN cp -rf config dist/config-example \
&& jq -M 'del(.sqlite_file, .ui_enabled, .publish_host, .http_port, .log_file, .log_level)' dist/config-example/config.json.example > dist/config-example/config-server.json \
&& rm dist/config-example/config.json.example \
&& go build -o dist/bin/supergiant cmd/cli/cli.go \
&& mkdir -p /go/src/github.com/supergiant/supergiant/tmp
CMD ["ash"]
View
@@ -0,0 +1,45 @@
# This Dockerfile is used to run local for development
FROM golang:1.7.4-alpine
RUN apk add --no-cache \
bash \
build-base \
ca-certificates \
git \
inotify-tools \
jq \
tzdata \
&& go get -u github.com/codegangsta/gin \
&& go get -u github.com/jteeuwen/go-bindata/... \
&& go get -u github.com/kardianos/govendor
ENV KUBECTL_VERSION="1.5.3"
RUN apk add --no-cache curl \
&& kubectl_version_latest="$(curl --silent --url https://github.com/kubernetes/kubernetes/releases/latest | sed -rn 's/.*tag\/v([^\"]*).*/\1/p')" \
&& kubectl_version="${KUBECTL_VERSION:-$kubectl_version_latest}" \
&& echo "current kubectl version: $kubectl_version" \
&& echo "latest kubectl version: $kubectl_version_latest" \
&& curl \
--url https://storage.googleapis.com/kubernetes-release/release/v${kubectl_version}/bin/linux/amd64/kubectl \
--output /usr/bin/kubectl \
&& chmod +x /usr/bin/kubectl \
&& apk del curl \
&& ( [ $(stat -c %s /usr/bin/kubectl) -gt 500 ] || exit 1 )
EXPOSE 80
WORKDIR /go/src/github.com/supergiant/supergiant
CMD ["go", "run", "cmd/server/server.go", "--sqlite-file=/data/supergiant.db", "--publish-host=0.0.0.0", "--http-port=80", "--ui-enabled=true", "--log-file=/dev/stdout", "--log-level=debug"]
COPY config/providers /go/src/github.com/supergiant/supergiant/config/providers
COPY ui/assets /go/src/github.com/supergiant/supergiant/ui/assets
COPY ui/views /go/src/github.com/supergiant/supergiant/ui/views
RUN go-bindata \
-pkg=bindata \
-o=bindata/bindata.go \
config/providers/... \
ui/assets/... \
ui/views/...
@@ -0,0 +1,28 @@
#!/bin/ash
set -e
[ $DEBUG ] && set -x
mkdir -p "$SUPERGIANT_DATA_DIR"
if [ ! -e "$SUPERGIANT_DATA_DIR/config-server.json" ];then
cp -f /etc/supergiant-example/config-server.json "$SUPERGIANT_DATA_DIR/config-server.json"
fi
touch $SUPERGIANT_DATA_DIR/config-client.json
if [ -e "$SUPERGIANT_SSL_CERT_FILE" ] && [ -e "$SUPERGIANT_SSL_KEY_FILE" ];then
ssl_options=$ssl_options --ssl-cert-file="$SUPERGIANT_SSL_CERT_FILE"
ssl_options=$ssl_options --ssl-key-file="$SUPERGIANT_SSL_KEY_FILE"
else
echo "[WARNING] Missing ssl certificate or key: $SUPERGIANT_SSL_CERT_FILE, $SUPERGIANT_SSL_KEY_FILE" >> "$SUPERGIANT_LOG_FILE"
fi
/usr/bin/supergiant-server \
--sqlite-file="$SUPERGIANT_SQLITE_FILE" \
--publish-host=$SUPERGIANT_PUBLISH_HOST \
--http-port=$SUPERGIANT_HTTP_PORT \
--https-port=$SUPERGIANT_HTTPS_PORT \
$ssl_options \
--ui-enabled=$SUPERGIANT_UI_ENABLED \
--log-file="$SUPERGIANT_LOG_FILE" \
--log-level=$SUPERGIANT_LOG_LEVEL \
--config-file="$SUPERGIANT_DATA_DIR/config-server.json"
View
@@ -0,0 +1,7 @@
#!/bin/ash
set -e
[ $DEBUG ] && set -x
cp -f /usr/share/zoneinfo/$TIMEZONE /etc/localtime
$@
View
@@ -0,0 +1,45 @@
version: "2"
services:
server:
build:
context: .
dockerfile: build/Dockerfile.dev
command:
- go
- run
- cmd/server/server.go
- --psql-host=postgresql
- --psql-db=default
- --psql-user=admin
- --psql-pass=secret
- --publish-host=0.0.0.0
- --http-port=80
- --ui-enabled=true
- --log-file=/dev/stdout
- --log-level=debug
depends_on:
- postgresql
ports:
- "80:80"
volumes:
- ./cmd:/go/src/github.com/supergiant/supergiant/cmd
- ./pkg:/go/src/github.com/supergiant/supergiant/pkg
- ./test:/go/src/github.com/supergiant/supergiant/test
- ./vendor:/go/src/github.com/supergiant/supergiant/vendor
- ./data:/data
postgresql:
image: mediamoose/postgresql:9.4-2
ports:
- "5432:5432"
volumes:
- postgresql:/var/lib/postgresql
environment:
POSTGRESQL_DB_NAME: default
POSTGRESQL_DB_USER: admin
POSTGRESQL_DB_PASS: secret
volumes:
postgresql: {}

0 comments on commit 8506674

Please sign in to comment.