From 2dee4c3b6dbb16e8c04dd34236b73e4d34f32733 Mon Sep 17 00:00:00 2001 From: Ambrose Chua Date: Thu, 11 Jan 2018 17:13:31 +0800 Subject: [PATCH] Simple microservice --- .drone.yml | 7 +++++++ .gitignore | 1 + Dockerfile | 16 ++++++++++++++++ LICENSE | 21 +++++++++++++++++++++ README.md | 2 ++ text-server.go | 18 ++++++++++++++++++ 6 files changed, 65 insertions(+) create mode 100644 .drone.yml create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 text-server.go diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..0164b69 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,7 @@ +pipeline: + docker: + image: plugins/docker + registry: registry.labs.0x.no + repo: registry.labs.0x.no/text-server + tags: + - latest diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..147a297 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +text-server diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1fe6ed2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM golang:1.9-alpine as go + +WORKDIR /go/src/text-server +COPY . . +ENV CGO_ENABLED=0 +ENV GOOS=linux +ENV GOARCH=amd64 +RUN go build -ldflags '-extldflags "-static"' -o text-server + + +FROM scratch + +EXPOSE 8080 +COPY --from=go /go/src/text-server/text-server text-server + +ENTRYPOINT ["/text-server"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a1003e6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Ambrose Chua + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 37c86d2..bcce6d6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ + # text-server + I'm a tiny Daniel. diff --git a/text-server.go b/text-server.go new file mode 100644 index 0000000..e18302d --- /dev/null +++ b/text-server.go @@ -0,0 +1,18 @@ +package main + +import ( + "fmt" + "net/http" + "os" +) + +func handler(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Content-Type", "text/html; charset=utf-8") + fmt.Fprintf(w, "%s", os.Getenv("TEXT")) +} + +func main() { + fmt.Println("Listening on port 8080...") + http.HandleFunc("/", handler) + http.ListenAndServe(":8080", nil) +}