-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A server for showing a svg badge with the deployment reference
- Loading branch information
Showing
9 changed files
with
158 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,29 @@ | ||
DOCKER_IMAGE := toolhouse/verify-deployment-manifest | ||
COMMIT := $(strip $(shell git rev-parse --short HEAD)) | ||
VERSION := $(strip $(shell git describe --always --dirty)) | ||
|
||
.PHONY: docker-build docker-push help | ||
.DEFAULT_GOAL := help | ||
|
||
docker-image: ## Build a docker image | ||
docker-images: ## Build a docker image | ||
docker build \ | ||
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \ | ||
--build-arg VERSION=$(VERSION) \ | ||
--build-arg VCS_REF=$(COMMIT) \ | ||
-t $(DOCKER_IMAGE):$(VERSION) \ | ||
-t toolhouse/verify-deployment-manifest:$(VERSION) \ | ||
-f ./cmd/verify-deployment-manifest/Dockerfile \ | ||
. | ||
|
||
docker build \ | ||
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \ | ||
--build-arg VERSION=$(VERSION) \ | ||
--build-arg VCS_REF=$(COMMIT) \ | ||
-t toolhouse/deployment-badge-server:$(VERSION) \ | ||
-f ./cmd/deployment-badge-server/Dockerfile \ | ||
. | ||
|
||
docker-push: ## Push the docker image to DockerHub | ||
docker push $(DOCKER_IMAGE):$(VERSION) | ||
docker push toolhouse/verify-deployment-manifest:$(VERSION) | ||
docker push toolhouse/deployment-badge-server:$(VERSION) | ||
|
||
help: ## Print available commands | ||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
ARG GO_VERSION=1.12.1 | ||
|
||
FROM golang:${GO_VERSION}-alpine as builder | ||
|
||
# Install git (required to fetch dependencies) | ||
RUN apk update && apk add git && rm -rf /var/cache/apk/* | ||
|
||
# Build Settings | ||
ENV CGO_ENABLED=0 | ||
ENV GOOS=linux | ||
|
||
WORKDIR /src | ||
|
||
# Install dependencies | ||
COPY ./go.mod ./go.sum ./ | ||
RUN go mod download | ||
|
||
# Build go binary | ||
COPY . . | ||
RUN go build -installsuffix 'static' ./cmd/deployment-badge-server/ | ||
|
||
FROM alpine:3.9.2 | ||
|
||
# SSL CA Root Certs | ||
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/* | ||
COPY --from=builder /src/deployment-badge-server /deployment-badge-server | ||
|
||
# Run as non-root user on port 8000 | ||
EXPOSE 8000 | ||
USER nobody | ||
CMD ["/deployment-badge-server"] | ||
|
||
# Labels: http://label-schema.org | ||
ARG BUILD_DATE | ||
ARG VCS_REF | ||
ARG VERSION | ||
LABEL org.label-schema.build-date=$BUILD_DATE \ | ||
org.label-schema.name="deployment-badge-server" \ | ||
org.label-schema.description="A server to display image badges with deployment information" \ | ||
org.label-schema.url="https://github.com/toolhouse/deployment-manifest/tree/master/cmd/deployment-badge-server" \ | ||
org.label-schema.vcs-ref=$VCS_REF \ | ||
org.label-schema.vcs-url="https://github.com/toolhouse/deployment-manifest" \ | ||
org.label-schema.version=$VERSION \ | ||
org.label-schema.schema-version="1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# `deployment-badge-server` | ||
|
||
[![](https://images.microbadger.com/badges/image/toolhouse/deployment-badge-server.svg)](https://microbadger.com/images/toolhouse/deployment-badge-server "Docker Image") | ||
|
||
A server for showing the deployment reference from a deployment manifest in a | ||
badge suitable for README files and wiki pages. | ||
|
||
## How to use | ||
|
||
The application is primarily designed to be run inside a Docker container | ||
(although it can also be run as a standalone binary) and will serve content | ||
on port `8000`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package main | ||
|
||
import ( | ||
"html" | ||
"net/http" | ||
"net/url" | ||
|
||
"github.com/toolhouse/deployment-manifest/pkg/deployment" | ||
|
||
badge "github.com/narqo/go-badge" | ||
) | ||
|
||
func main() { | ||
mux := http.NewServeMux() | ||
mux.HandleFunc("/", handler) | ||
http.ListenAndServe(":8000", mux) | ||
} | ||
|
||
func handler(w http.ResponseWriter, r *http.Request) { | ||
|
||
u, err := manifestURLFromReq(r) | ||
if err != nil { | ||
errorResp(w, "error", "invalid url") | ||
return | ||
} | ||
|
||
env := environmentURLFromReq(r) | ||
|
||
manifest, err := deployment.FetchManifest(u) | ||
if err != nil { | ||
errorResp(w, env, "no manifest") | ||
return | ||
} | ||
|
||
validResp(w, env, manifest.Ref) | ||
} | ||
|
||
func manifestURLFromReq(r *http.Request) (string, error) { | ||
u := "https:/" + r.URL.Path | ||
_, err := url.ParseRequestURI(u) | ||
|
||
return u, err | ||
} | ||
|
||
func environmentURLFromReq(r *http.Request) string { | ||
env := r.URL.Query().Get("env") | ||
if env == "" { | ||
return "deployed" | ||
} | ||
|
||
return env | ||
} | ||
|
||
func errorResp(w http.ResponseWriter, label, value string) { | ||
resp(w, label, value, badge.ColorYellow) | ||
} | ||
|
||
func validResp(w http.ResponseWriter, env, value string) { | ||
resp(w, env, value, badge.ColorBlue) | ||
} | ||
|
||
func resp(w http.ResponseWriter, label, value string, color badge.Color) { | ||
w.Header().Set("Content-Type", "image/svg+xml") | ||
badge.Render(html.EscapeString(label), html.EscapeString(value), color, w) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters