From 24c28ac95cafdc57603925e9f81117ff875ebe35 Mon Sep 17 00:00:00 2001 From: Aaron Fischer Date: Fri, 19 Mar 2021 20:33:55 +0100 Subject: [PATCH] Clean up the project and add a docker compose file --- .gitignore | 17 ++--------------- AUTHOR.mkd | 2 -- Dockerfile | 2 +- LICENSE.mkd | 18 ------------------ Makefile | 6 ------ README.md | 11 +++++++++++ docker-compose.yml | 12 ++++++++++++ go.mod | 2 +- cmd/buchdesmonats/main.go => src/bdm.go | 10 ++++++---- 9 files changed, 33 insertions(+), 47 deletions(-) delete mode 100644 AUTHOR.mkd delete mode 100644 LICENSE.mkd delete mode 100644 Makefile create mode 100644 README.md create mode 100644 docker-compose.yml rename cmd/buchdesmonats/main.go => src/bdm.go (90%) diff --git a/.gitignore b/.gitignore index 1a5a84a..9fc8a47 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,2 @@ -/target -/classes -/checkouts -pom.xml -pom.xml.asc -*.jar -*.class -/.lein-* -/.nrepl-port -/.project - -/public/book.html -/public/comic.html -/public/comic-covers/ -/public/book-covers/ +/data +/covers diff --git a/AUTHOR.mkd b/AUTHOR.mkd deleted file mode 100644 index c425c75..0000000 --- a/AUTHOR.mkd +++ /dev/null @@ -1,2 +0,0 @@ -* Aaron Fischer -* Michael Reutter diff --git a/Dockerfile b/Dockerfile index 282c6b6..6ea5280 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM golang:alpine AS build COPY . /app WORKDIR /app -RUN GOOS=linux go build -o bdm cmd/buchdesmonats/main.go +RUN GOOS=linux go build -o bdm src/bdm.go FROM alpine diff --git a/LICENSE.mkd b/LICENSE.mkd deleted file mode 100644 index 80a3b39..0000000 --- a/LICENSE.mkd +++ /dev/null @@ -1,18 +0,0 @@ -Copyright (C) 2014-2015 Aaron Fischer - -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/Makefile b/Makefile deleted file mode 100644 index 510328c..0000000 --- a/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -build: - mkdir -p bin - go build -o bin/buchdesmonats cmd/buchdesmonats/main.go - -run: - go run cmd/buchdesmonats/main.go diff --git a/README.md b/README.md new file mode 100644 index 0000000..1788f66 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# Book of the month + +## Deploy + + $ docker-compose build + $ docker-compose up -d + +## Authors + +* Aaron Fischer +* Michael Reutter diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0ba6933 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: "3" + +services: + webservice: + build: . + image: bdm:latest + restart: always + volumes: + - ./data:/app/covers + ports: + - 127.0.0.1:9783:9783 + diff --git a/go.mod b/go.mod index 466732e..2d8832a 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module okoyono.de/buchdesmonats -go 1.15 +go 1.16 diff --git a/cmd/buchdesmonats/main.go b/src/bdm.go similarity index 90% rename from cmd/buchdesmonats/main.go rename to src/bdm.go index 5e3c2f7..f097a80 100644 --- a/cmd/buchdesmonats/main.go +++ b/src/bdm.go @@ -57,14 +57,14 @@ func getItems(filename string) []Item { resp, err := http.Get(url) if err != nil { - panic(filename + " is missing") + log.Fatal(filename + " is missing") } defer resp.Body.Close() content, err := ioutil.ReadAll(resp.Body) if err != nil { - panic("Can not download the file. Network problem?") + log.Fatal("Can not download the file. Network problem?") } re := regexp.MustCompile(`[0-9]{13}`) @@ -98,13 +98,14 @@ func main() { fileServer := http.FileServer(http.Dir("./static")) http.Handle("/static/", http.StripPrefix("/static", fileServer)) - // Images + // Cover images imageServer := http.FileServer(http.Dir("./covers/")) http.Handle("/covers/", http.StripPrefix("/covers", imageServer)) // Update "Hook" /update?filename=COMIC.mkd http.HandleFunc("/update", func(w http.ResponseWriter, r *http.Request) { filename := r.URL.Query().Get("filename") + log.Printf("Update hook triggered for %v", filename) // Get all items from the git repo items := getItems(filename) @@ -119,7 +120,6 @@ func main() { } }) - // Spawn webserver /comic http.HandleFunc("/book", func(w http.ResponseWriter, r *http.Request) { log.Print("/book") getHTML("BOOK.mkd", w) @@ -129,6 +129,8 @@ func main() { getHTML("COMIC.mkd", w) }) + // Spawn the webserver (blocking) + log.Print("Spawn webserver on port :9783 and waiting for requests ...") err := http.ListenAndServe(":9783", nil) if err != nil { panic(err)