From 5e0e8a03b1c04dbba802b63b03297ada43c9fe4b Mon Sep 17 00:00:00 2001 From: Ben Clapp Date: Thu, 26 Jul 2018 18:07:39 +1200 Subject: [PATCH 1/3] add dockerfile --- .dockerignore | 3 +++ Dockerfile | 11 +++++++++++ README.md | 8 ++++++++ 3 files changed, 22 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6d2ba94 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +README.md +LICENSE +Dockerfile \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f7cfdb1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM golang:1.10 as build-env +ADD . /go/src/github.com/iamseth/azure_sql_exporter +WORKDIR /go/src/github.com/iamseth/azure_sql_exporter +RUN make +RUN mv dist/azure_sql_exporter* dist/azure_sql_exporter + +FROM debian:latest +WORKDIR /app +COPY --from=build-env /go/src/github.com/iamseth/azure_sql_exporter/dist/azure_sql_exporter /app/ +VOLUME [ "/config" ] +ENTRYPOINT /app/azure_sql_exporter -config.file=/config/config.yaml diff --git a/README.md b/README.md index c19a7d3..e00d766 100644 --- a/README.md +++ b/README.md @@ -54,3 +54,11 @@ databases: ## Binary releases Pre-compiled versions may be found in the [release section](https://github.com/iamseth/azure_sql_exporter/releases). + +## Docker + +A Dockerfile is provided, or images are available on [Docker Hub](https://hub.docker.com/r/benclapp/azure-sql-exporter/). The image is expecting a config.yaml file to exist at /config/config.yaml. To run: + +```bash +docker run -d -p 9139:9139 -v ./config.yaml:/config/config.yaml benclapp/azure-sql-exporter:latest +``` \ No newline at end of file From 122e30fd3fdf6eb2f261724947a8a4d31c2bb518 Mon Sep 17 00:00:00 2001 From: Ben Clapp Date: Wed, 5 Jun 2019 11:22:27 +1200 Subject: [PATCH 2/3] docker builds 1.12, from scratch --- .gitignore | 1 + Dockerfile | 20 +++++++++++++------- Makefile | 4 ++-- VERSION | 1 + 4 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 VERSION diff --git a/.gitignore b/.gitignore index 98c98f4..b0057a9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ azure_sql_exporter dist/ +config/ config.yaml diff --git a/Dockerfile b/Dockerfile index f7cfdb1..9b96e09 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,17 @@ -FROM golang:1.10 as build-env +FROM alpine:latest as certificates +RUN apk update && apk add --no-cache ca-certificates && update-ca-certificates + + +FROM golang:1.12 as builder ADD . /go/src/github.com/iamseth/azure_sql_exporter WORKDIR /go/src/github.com/iamseth/azure_sql_exporter -RUN make -RUN mv dist/azure_sql_exporter* dist/azure_sql_exporter +RUN CGO_ENABLED=0 go build -ldflags "-X main.Version=$(cat VERSION)" + +FROM scratch + +# Copy certs from alpine as they don't exist from scratch +COPY --from=certificates /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=builder /go/src/github.com/iamseth/azure_sql_exporter/azure_sql_exporter /app/ -FROM debian:latest WORKDIR /app -COPY --from=build-env /go/src/github.com/iamseth/azure_sql_exporter/dist/azure_sql_exporter /app/ -VOLUME [ "/config" ] -ENTRYPOINT /app/azure_sql_exporter -config.file=/config/config.yaml +ENTRYPOINT ["/app/azure_sql_exporter"] diff --git a/Makefile b/Makefile index 96ed227..b86f8da 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION := 0.1.0 +VERSION := 0.1.1 LDFLAGS := -X main.Version=$(VERSION) GOFLAGS := -ldflags "$(LDFLAGS)" @@ -26,4 +26,4 @@ format: .PHONY: docker docker: - docker run --rm -v "$$PWD":/go/src/github.com/iamseth/azure_sql_exporter -w /go/src/github.com/iamseth/azure_sql_exporter golang:1.6 bash -c make + docker build -t benclapp/azure_sql_exporter:$(VERSION) -t benclapp/azure_sql_exporter:latest . diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..6da28dd --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.1 \ No newline at end of file From 9cbe1477efb5c73c70defe6361647f8d2f0e8eda Mon Sep 17 00:00:00 2001 From: Ben Clapp Date: Wed, 5 Jun 2019 11:27:19 +1200 Subject: [PATCH 3/3] update readme with updated docker image --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e00d766..0d522c9 100644 --- a/README.md +++ b/README.md @@ -57,8 +57,8 @@ Pre-compiled versions may be found in the [release section](https://github.com/i ## Docker -A Dockerfile is provided, or images are available on [Docker Hub](https://hub.docker.com/r/benclapp/azure-sql-exporter/). The image is expecting a config.yaml file to exist at /config/config.yaml. To run: +A Dockerfile is provided, or images are available on [Docker Hub](https://hub.docker.com/r/benclapp/azure_sql_exporter/). For example: ```bash -docker run -d -p 9139:9139 -v ./config.yaml:/config/config.yaml benclapp/azure-sql-exporter:latest +docker run -d -p 9139:9139 -v ./config.yaml:/config/config.yaml benclapp/azure_sql_exporter:latest -config.file /config/config.yaml ``` \ No newline at end of file