Skip to content
Snippets Groups Projects
Verified Commit 9391c747 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
/.idea/
/vendor/
/node_modules/
\ No newline at end of file
FROM golang:alpine as builder
RUN apk add --no-cache curl git gcc musl-dev
RUN curl https://glide.sh/get | sh
WORKDIR /go/src/app
COPY glide.lock glide.yaml ./
RUN glide install
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -a app .
FROM node:alpine as asset_builder
WORKDIR /app
COPY package* /app/
RUN npm install
COPY assets /app/assets
RUN npm run build
ENTRYPOINT ["/app"]
FROM scratch
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /go/src/app/app /app
COPY templates /templates
COPY --from=asset_builder /app/assets /assets
ENTRYPOINT ["/app"]
\ No newline at end of file
# KStats WFrontend
## Configuration
| Name | Example | Description |
| ------------------------ | ---------------------------------------------- | ------------------------------------------------------ |
|`KSTATS_DATABASE_TYPE`* |`postgres` | Database driver (only postgres is supported currently) |
|`KSTATS_DATABASE_URL`* |`postgresql://kstats:hunter2@localhost/statsbot`| Database URL |
build.sh 0 → 100755
#!/bin/sh
IMAGE=k8r.eu/justjanne/statsbot-frontend
TAGS=$(git describe --always --tags HEAD)
docker build -t $IMAGE:$TAGS .
docker tag $IMAGE:$TAGS $IMAGE:latest
echo Successfully tagged $IMAGE:latest
docker push $IMAGE:$TAGS
docker push $IMAGE:latest
\ No newline at end of file
#!/bin/sh
IMAGE=k8r.eu/justjanne/statsbot-frontend
TAGS=$(git describe --always --tags HEAD)
DEPLOYMENT=statsbot-frontend
POD=statsbot-frontend
kubectl set image deployment/$DEPLOYMENT $POD=$IMAGE:$TAGS
\ No newline at end of file
hash: e3afe7d6be6078ab261a84bcc69e2f87d9805c7553025546d12074b9926fd288
updated: 2018-05-24T12:12:33.899483528+02:00
imports:
- name: github.com/lib/pq
version: 90697d60dd844d5ef6ff15135d0203f65d2f53b8
subpackages:
- oid
testImports: []
package: git.kuschku.de/justjanne/statsbot
import:
- package: github.com/lib/pq
\ No newline at end of file
main.go 0 → 100644
package main
import (
"database/sql"
"fmt"
_ "github.com/lib/pq"
"os"
"net/http"
"html/template"
"path"
)
type Config struct {
Database DatabaseConfig
}
type DatabaseConfig struct {
Format string
Url string
}
func NewConfigFromEnv() Config {
var err error
config := Config{}
config.Database.Format = os.Getenv("KSTATS_DATABASE_TYPE")
config.Database.Url = os.Getenv("KSTATS_DATABASE_URL")
return config
}
func formatTemplate(w http.ResponseWriter, templateName string, data interface{}) error {
pageTemplate, err := template.ParseFiles(fmt.Sprintf("templates/%s", templateName))
if err != nil {
return err
}
err = pageTemplate.Execute(w, data)
if err != nil {
return err
}
return nil
}
type ChannelData struct {
Id int
Name string
TotalWords int
TotalCharacters int
}
func main() {
config := NewConfigFromEnv()
db, err := sql.Open(config.Database.Format, config.Database.Url)
if err != nil {
panic(err)
}
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("OK"))
})
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
_, channel := path.Split(r.URL.Path)
channelData := ChannelData{}
db.QueryRow("SELECT id, channel FROM channels WHERE channel ILIKE $1", channel).Scan(&channelData.Id, &channelData.Name)
db.QueryRow("SELECT SUM(characters), SUM(words) FROM messages WHERE channel = $1").Scan(&channelData.TotalCharacters, &channelData.TotalWords)
formatTemplate(w, "statistics", channelData)
})
}
This diff is collapsed.
{
"scripts": {
"sass": "node_modules/node-sass/bin/node-sass --output-style compressed assets/sass -o assets/css",
"build": "npm run sass"
},
"devDependencies": {
"node-sass": "^4.7.2"
}
}
<!DOCTYPE html>
<meta charset="utf-8">
<title>{{.Name}}</title>
<link rel="shortcut icon" href="/favicon.png">
<link rel="shortcut icon" href="/favicon.svg">
<meta name="generator" content="Human v1.0">
<meta name="referrer" content="origin">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="HandheldFriendly" content="True">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0, width=device-width">
<meta name="theme-color" content="#FFC107">
<meta name="msapplication-navbutton-color" content="#FFC107">
<meta name="apple-mobile-web-app-status-bar-style" content="#FFC107">
<link href="/assets/css/style.css" rel="stylesheet">
<p>Total: {{.TotalCharacters}} Characters, {{.TotalWords}} Words</p>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment