aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2021-11-12 08:27:17 +0000
committerterminaldweller <thabogre@gmail.com>2021-11-12 08:27:17 +0000
commit0fad033ff38707e07011b7008d506cf4fcdaa7ec (patch)
treedb66c3a19708738c9c6e776c5cc6cf9369a3d5fe
parentadded a dev and deployment docker-compose (diff)
downloadhived-0fad033ff38707e07011b7008d506cf4fcdaa7ec.tar.gz
hived-0fad033ff38707e07011b7008d506cf4fcdaa7ec.zip
restructured the repo-WIP
-rw-r--r--.travis.yml18
-rw-r--r--hived/Dockerfile (renamed from Dockerfile)0
-rwxr-xr-xhived/docker-entrypoint.sh (renamed from docker-entrypoint.sh)0
-rw-r--r--hived/go.mod (renamed from go.mod)2
-rw-r--r--hived/go.sum (renamed from go.sum)0
-rw-r--r--hived/hived.go (renamed from hived.go)0
-rwxr-xr-xrun.sh2
-rwxr-xr-xruntravis.sh2
-rw-r--r--telebot/Dockerfile18
-rwxr-xr-xtelebot/docker-entrypoint.sh8
-rw-r--r--telebot/go.mod10
-rw-r--r--telebot/go.sum35
-rw-r--r--telebot/main.go92
-rwxr-xr-xtelebot/telebotbin0 -> 7115842 bytes
14 files changed, 164 insertions, 23 deletions
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index f0314d1..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,18 +0,0 @@
-language: go
-go:
- - 1.15
-env:
- matrix:
- - DOCKER_COMPOSE_VERSION=1.25.0
- global:
- - secure: JW0y+F2BaxmKH00lv/jfiAo2ezMe383oqhA7PozarjYDrksU/cGKgdUay89STXZrN68p+oOIAaGnVM3SGWoKi0gCuDIZKYVVhhCitctnG13toQkvQda8+ceme8spv6ryicX0f2Kpfoe/2tp0cQo1aU16UZ7Zy6pX0Kok62h3wxm5m7ce0lBCyOJkNmHNNCAPgV9VqwpQLPnJyMh0tLuSQLDnKYV+LmNNL2IHVKpg6HRQh01fHvWWI2W+wGhrX4Yerdlm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lzOBc+8+MiZNVG/YRqDuc4u2vacn8Xhm8=
- - secure: ZhSnKN3JLlAXfK9bTTnqTwYINp5j71ZqYlbPAhRKKl3VuUM1OhrC9iWRmxLj0t6r82u5dS9M7dYJWowwLhqkPSWlI/lYqy+4EYtmn+Qa2r7GrRkMsx/CkdC/C3okumJf9gpaYIpJMr7pkUeWbJd6zh/cGxD426NeAv2r2paiGd2rn+AlD67xDcOhJCqAczOHKjSMKLAVsRU6p7rB6Vie1dvY/FrL+enkjlJfWcaEyA5nWiky34Qz81IxqHKaz/4h9Kg3iVwu60Rh86WHu877AbPVykJS+/bZ+l/2FWI3zduifmpm5okf3YLV9XnYFZXmgD8efQi5b/cy5AdbjdnKtTJ/jiM0Ygbd3YfVc/bWb+unLWcr5/f6xaHUKEAlDSIXX8Mu4a2yrBkiUB99XZ+pqo7tC2Heqzytx0iqVxAeTLTx23Ce0e3gzRMGnSV5TW983W/xTlFmGSvgzAfzr/tZC+4DUcRRf6cSWH/CxxTRWrF8p4XeBfbZudD6629i16K1v8iM8sZvAWg1QnhU1qWIHOkVAkMbwPewLN6MVhc2JRMG0eFTn5EMIK5MpCPot2inY10VfcPnswHBSocVUEjhAQ+RtNQyBk9Oc3BhCckZUctR66IWH9bcXvO5MAqOVrEWxzNf2Kf837TZLLJBX36OKwzZCIhLz3Hx3Pd2/7AD+Qs=
-services:
-- docker
-before_install:
-- docker pull redis:6.2-alpine
-install:
-# - docker build -t hived ./ && docker-compose -f ./docker-compose-travis.yaml up -d
-# - "./test/endpoints.sh"
- - go build
diff --git a/Dockerfile b/hived/Dockerfile
index 0a9e3e2..0a9e3e2 100644
--- a/Dockerfile
+++ b/hived/Dockerfile
diff --git a/docker-entrypoint.sh b/hived/docker-entrypoint.sh
index 932c9c9..932c9c9 100755
--- a/docker-entrypoint.sh
+++ b/hived/docker-entrypoint.sh
diff --git a/go.mod b/hived/go.mod
index 97de2d8..9df31fa 100644
--- a/go.mod
+++ b/hived/go.mod
@@ -1,6 +1,6 @@
module github.com/terminaldweller/hived
-go 1.15
+go 1.17
require (
github.com/Knetic/govaluate v3.0.0+incompatible
diff --git a/go.sum b/hived/go.sum
index 07ad2bc..07ad2bc 100644
--- a/go.sum
+++ b/hived/go.sum
diff --git a/hived.go b/hived/hived.go
index 5345e70..5345e70 100644
--- a/hived.go
+++ b/hived/hived.go
diff --git a/run.sh b/run.sh
deleted file mode 100755
index 4031990..0000000
--- a/run.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/usr/bin/env sh
-docker build -t hived ./ && docker-compose up
diff --git a/runtravis.sh b/runtravis.sh
deleted file mode 100755
index 10ee492..0000000
--- a/runtravis.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/usr/bin/env sh
-
diff --git a/telebot/Dockerfile b/telebot/Dockerfile
new file mode 100644
index 0000000..0a9e3e2
--- /dev/null
+++ b/telebot/Dockerfile
@@ -0,0 +1,18 @@
+FROM alpine:3.13 as builder
+RUN apk update && apk upgrade
+RUN apk add go git
+COPY go.* /hived/
+RUN cd /hived && go mod download
+COPY *.go /hived/
+RUN cd /hived && go build
+
+FROM node:lts-alpine3.13 AS certbuilder
+RUN apk add openssl
+WORKDIR /certs
+RUN openssl req -nodes -new -x509 -subj="/C=US/ST=Denial/L=springfield/O=Dis/CN=localhost" -keyout server.key -out server.cert
+
+FROM gcr.io/distroless/static-debian10
+COPY --from=certbuilder /cert/ /cert/
+COPY --from=builder /hived/hived /hived/
+COPY ./docker-entrypoint.sh /hived/
+ENTRYPOINT ["/hived/docker-entrypoint.sh"]
diff --git a/telebot/docker-entrypoint.sh b/telebot/docker-entrypoint.sh
new file mode 100755
index 0000000..932c9c9
--- /dev/null
+++ b/telebot/docker-entrypoint.sh
@@ -0,0 +1,8 @@
+#!/usr/bin/env sh
+set -ex
+
+export $(cat /run/secrets/tg_bot_token)
+export $(cat /run/secrets/ch_api_key)
+export $(cat /run/secrets/ch_api_secret)
+
+"/hived/hived" "$@"
diff --git a/telebot/go.mod b/telebot/go.mod
new file mode 100644
index 0000000..71766e5
--- /dev/null
+++ b/telebot/go.mod
@@ -0,0 +1,10 @@
+module telebot
+
+go 1.15
+
+require (
+ github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible
+ github.com/gorilla/mux v1.8.0
+ github.com/rs/zerolog v1.26.0
+ github.com/technoweenie/multipartstreamer v1.0.1 // indirect
+)
diff --git a/telebot/go.sum b/telebot/go.sum
new file mode 100644
index 0000000..ca57a1e
--- /dev/null
+++ b/telebot/go.sum
@@ -0,0 +1,35 @@
+github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
+github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible h1:2cauKuaELYAEARXRkq2LrJ0yDDv1rW7+wrTEdVL3uaU=
+github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible/go.mod h1:qf9acutJ8cwBUhm1bqgz6Bei9/C/c93FPDljKWwsOgM=
+github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
+github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
+github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
+github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
+github.com/rs/zerolog v1.26.0 h1:ORM4ibhEZeTeQlCojCK2kPz1ogAY4bGs4tD+SaAdGaE=
+github.com/rs/zerolog v1.26.0/go.mod h1:yBiM87lvSqX8h0Ww4sdzNSkVYZ8dL2xjZJG1lAuGZEo=
+github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM=
+github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog=
+github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
+golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
+golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
+golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
+golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
diff --git a/telebot/main.go b/telebot/main.go
new file mode 100644
index 0000000..f6a3bf7
--- /dev/null
+++ b/telebot/main.go
@@ -0,0 +1,92 @@
+package main
+
+import (
+ "context"
+ "encoding/json"
+ "flag"
+ "net/http"
+ "os"
+ "os/signal"
+ "time"
+
+ tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
+ "github.com/gorilla/mux"
+ "github.com/rs/zerolog/log"
+)
+
+var flagPort = flag.String("port", "8000", "determined the port the sercice runs on")
+
+// FIXME-the client should provide the channel ID
+var botChannelID = flag.Int64("botchannelid", 146328407, "determines the channel id the telgram bot should send messages to")
+
+const TELEGRAM_BOT_TOKEN_ENV_VAR = "TELEGRAM_BOT_TOKEN"
+
+func getTGBot() *tgbotapi.BotAPI {
+ token := os.Getenv(TELEGRAM_BOT_TOKEN_ENV_VAR)
+ bot, err := tgbotapi.NewBotAPI(token[1 : len(token)-1])
+ if err != nil {
+ log.Error().Err(err)
+ }
+ return bot
+}
+
+func sendMessage(bot *tgbotapi.BotAPI, msgText string) error {
+ msg := tgbotapi.NewMessage(*botChannelID, msgText)
+ bot.Send(msg)
+ return nil
+}
+
+func healthHandler(w http.ResponseWriter, r *http.Request) {
+ var telebotError string
+ IsTelebotOk := true
+
+ w.Header().Add("Content-Type", "application/json")
+ if r.Method != "GET" {
+ http.Error(w, "Method is not supported.", http.StatusNotFound)
+ }
+
+ w.WriteHeader(http.StatusOK)
+
+ json.NewEncoder(w).Encode(struct {
+ IsHivedOk bool `json:"isTelebotOK"`
+ TelebotError string `json:"telebotError"`
+ }{IsHivedOk: IsTelebotOk, TelebotError: telebotError})
+}
+
+func msgHandler(w http.ResponseWriter, r *http.Request) {
+
+}
+
+func startServer(gracefulWait time.Duration) {
+ r := mux.NewRouter()
+ srv := &http.Server{
+ Addr: "0.0.0.0:" + *flagPort,
+ WriteTimeout: time.Second * 15,
+ ReadTimeout: time.Second * 15,
+ Handler: r,
+ }
+ r.HandleFunc("/health", healthHandler)
+ r.HandleFunc("/msg", msgHandler)
+
+ go func() {
+ if err := srv.ListenAndServe(); err != nil {
+ log.Fatal().Err(err)
+ }
+ }()
+
+ c := make(chan os.Signal, 1)
+
+ signal.Notify(c, os.Interrupt)
+ <-c
+ ctx, cancel := context.WithTimeout(context.Background(), gracefulWait)
+ defer cancel()
+ srv.Shutdown(ctx)
+ log.Info().Msg("gracefully shut down the server")
+}
+
+func main() {
+ var gracefulWait time.Duration
+ flag.DurationVar(&gracefulWait, "gracefulwait", time.Second*15, "the duration to wait during the graceful shutdown")
+ flag.Parse()
+ startServer(gracefulWait)
+}
diff --git a/telebot/telebot b/telebot/telebot
new file mode 100755
index 0000000..21b84aa
--- /dev/null
+++ b/telebot/telebot
Binary files differ