aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2024-03-31 14:40:49 +0000
committerterminaldweller <devi@terminaldweller.com>2024-03-31 14:40:49 +0000
commit911bda1b171a6a25cdb09b839b035e195e95ed41 (patch)
tree6c902d24fcc844e2d0b8907c5dbd09a8b7e66914
parentadded new ticker endpoint that periodically sends crypto prices over telegram (diff)
downloadhived-tmp.tar.gz
hived-tmp.zip
changed redis to keydbtmp
-rw-r--r--arbiter/Dockerfile6
-rw-r--r--docker-compose-test.yaml20
-rw-r--r--docker-compose.yaml16
-rw-r--r--hived/Dockerfile6
-rw-r--r--hived/hived.go25
-rw-r--r--telebot/Dockerfile6
-rwxr-xr-xtest/endpoints.sh2
7 files changed, 26 insertions, 55 deletions
diff --git a/arbiter/Dockerfile b/arbiter/Dockerfile
index af0bb94..fc34460 100644
--- a/arbiter/Dockerfile
+++ b/arbiter/Dockerfile
@@ -1,4 +1,4 @@
-FROM alpine:3.18 as builder
+FROM alpine:3.19 as builder
RUN apk update && apk upgrade
RUN apk add go git
COPY go.* /arbiter/
@@ -6,13 +6,13 @@ RUN cd /arbiter && go mod download
COPY *.go /arbiter/
RUN cd /arbiter && go build
-FROM alpine:3.18 as certbuilder
+FROM alpine:3.19 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
-FROM alpine:3.18
+FROM alpine:3.19
COPY --from=certbuilder /certs /certs
COPY --from=builder /arbiter/arbiter /arbiter/
ENTRYPOINT ["/arbiter/arbiter"]
diff --git a/docker-compose-test.yaml b/docker-compose-test.yaml
index 75ff334..12c1cc6 100644
--- a/docker-compose-test.yaml
+++ b/docker-compose-test.yaml
@@ -1,12 +1,10 @@
-version: "3.4"
+version: "3.9"
services:
hived:
image: hived
build:
context: ./hived
secrets:
- - ch_api_key
- - ch_api_secret
- tg_bot_token
networks:
- mainnet
@@ -14,7 +12,7 @@ services:
ports:
- "10008:8008"
depends_on:
- - redis
+ - keydb
- telebot
entrypoint: ["/hived/docker-entrypoint.sh"]
cap_drop:
@@ -49,8 +47,8 @@ services:
- ALL
environment:
- SERVER_DEPLOYMENT_TYPE=test
- redis:
- image: redis:6.2-alpine
+ keydb:
+ image: eqalpha/keydb:alpine_x86_64_v6.3.4
networks:
- mainnet
ports:
@@ -58,18 +56,12 @@ services:
environment:
- ALLOW_EMPTY_PASSWORD=yes
volumes:
- - redis-data:/data/
+ - keydb-data:/data/
networks:
mainnet:
- driver: bridge
telenet:
- driver: bridge
secrets:
tg_bot_token:
file: ./tgtoken
- ch_api_key:
- file: ./changelly_api_key
- ch_api_secret:
- file: ./changelly_api_secret
volumes:
- redis-data:
+ keydb-data:
diff --git a/docker-compose.yaml b/docker-compose.yaml
index dc131b7..ae915ef 100644
--- a/docker-compose.yaml
+++ b/docker-compose.yaml
@@ -5,8 +5,6 @@ services:
build:
context: ./hived
secrets:
- - ch_api_key
- - ch_api_secret
- tg_bot_token
networks:
- mainnet
@@ -15,7 +13,7 @@ services:
ports:
- "8007:8008"
depends_on:
- - redis
+ - keydb
- telebot
entrypoint: ["/hived/docker-entrypoint.sh"]
volumes:
@@ -41,8 +39,8 @@ services:
- ALL
environment:
- SERVER_DEPLOYMENT_TYPE=deployment
- redis:
- image: redis:6.2-alpine
+ keydb:
+ image: eqalpha/keydb:alpine_x86_64_v6.3.4
networks:
- mainnet
restart: unless-stopped
@@ -51,7 +49,7 @@ services:
environment:
- ALLOW_EMPTY_PASSWORD=yes
volumes:
- - redis-data:/data/
+ - keydb-data:/data/
arbiter:
image: arbiter
build:
@@ -76,9 +74,5 @@ networks:
secrets:
tg_bot_token:
file: ./tgtoken
- ch_api_key:
- file: ./changelly_api_key
- ch_api_secret:
- file: ./changelly_api_secret
volumes:
- redis-data:
+ keydb-data:
diff --git a/hived/Dockerfile b/hived/Dockerfile
index ed7c38d..8bec902 100644
--- a/hived/Dockerfile
+++ b/hived/Dockerfile
@@ -1,4 +1,4 @@
-FROM alpine:3.18 as builder
+FROM alpine:3.19 as builder
RUN apk update && apk upgrade
RUN apk add go git
COPY go.* /hived/
@@ -6,13 +6,13 @@ RUN cd /hived && go mod download
COPY *.go /hived/
RUN cd /hived && go build
-FROM alpine:3.18 as certbuilder
+FROM alpine:3.19 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
-FROM alpine:3.18
+FROM alpine:3.19
COPY --from=certbuilder /certs /certs
COPY --from=builder /hived/hived /hived/
COPY ./docker-entrypoint.sh /hived/
diff --git a/hived/hived.go b/hived/hived.go
index d72d427..c0ba57e 100644
--- a/hived/hived.go
+++ b/hived/hived.go
@@ -31,9 +31,9 @@ const (
serverDeploymentType = "SERVER_DEPLOYMENT_TYPE"
httpClientTimeout = 5
getTimeout = 5
- serverTLSReadTimeout = 15
- serverTLSWriteTimeout = 15
- defaultGracefulShutdown = 15
+ serverTLSReadTimeout = 5
+ serverTLSWriteTimeout = 5
+ defaultGracefulShutdown = 5
redisContextTimeout = 2
pingTimeout = 5
alertCheckIntervalDefault = 600
@@ -140,24 +140,19 @@ func getPrice(ctx context.Context,
priceChan chan<- priceChanStruct,
errChan chan<- errorChanStruct,
) {
- fmt.Println("zcheckpoint 1: ", name)
val, err := rdb.Get(ctx, name+"_price").Float64()
- fmt.Println("zcheckpoint 2")
if err != nil {
- fmt.Println("zcheckpoint 3: ", name)
source := chooseGetPriceSource()
if source == CryptoCompareSource {
getPriceFromCryptoCompare(ctx, name, unit, waitGroup, priceChan, errChan)
}
} else {
- fmt.Println("zcheckpoint 4: ", name)
priceChan <- priceChanStruct{name: name, price: val}
errChan <- errorChanStruct{hasError: false, err: nil}
waitGroup.Done()
}
- fmt.Println("zcheckpoint 5: ", name)
}
func getPriceFromCryptoCompareErrorHandler(
@@ -181,14 +176,12 @@ func getPriceFromCryptoCompare(
errChan chan<- errorChanStruct,
) {
defer wg.Done()
- fmt.Println("xcheckpoint 1")
params := "fsym=" + url.QueryEscape(name) + "&" +
"tsyms=" + url.QueryEscape(unit)
path := cryptocomparePriceURL + params
client := GetProxiedClient()
- fmt.Println("xcheckpoint 2")
req, err := http.NewRequestWithContext(ctx, http.MethodGet, path, nil)
if err != nil {
@@ -196,7 +189,6 @@ func getPriceFromCryptoCompare(
return
}
- fmt.Println("xcheckpoint 3")
resp, err := client.Do(req)
if err != nil {
@@ -205,7 +197,6 @@ func getPriceFromCryptoCompare(
return
}
defer resp.Body.Close()
- fmt.Println("xcheckpoint 4")
jsonBody := make(map[string]float64)
@@ -214,15 +205,12 @@ func getPriceFromCryptoCompare(
getPriceFromCryptoCompareErrorHandler(err, name, priceChan, errChan)
}
- fmt.Println("xcheckpoint 5")
-
// add a price cache
err = rdb.Set(ctx, name+"_price", jsonBody[unit], time.Duration(*cacheDuration*redisCacheDurationMultiplier)).Err()
if err != nil {
log.Error().Err(err)
}
- fmt.Println("xcheckpoint 6")
priceChan <- priceChanStruct{name: name, price: jsonBody[unit]}
errChan <- errorChanStruct{hasError: false, err: nil}
@@ -588,12 +576,9 @@ func tickerManagerWorker(ticker tickerType) {
ctx, cancel := context.WithTimeout(context.Background(), getTimeout*time.Second)
defer cancel()
- fmt.Println("checkpoint 1: ", ticker.Name)
go getPrice(ctx, ticker.Name, "USD", &waitGroup, priceChan, errChan)
- fmt.Println("checkpoint 2")
waitGroup.Wait()
- fmt.Println("checkpoint 3")
select {
case err := <-errChan:
@@ -603,7 +588,6 @@ func tickerManagerWorker(ticker tickerType) {
default:
log.Error().Err(errBadLogic)
}
- fmt.Println("checkpoint 4")
var price priceChanStruct
select {
@@ -612,7 +596,6 @@ func tickerManagerWorker(ticker tickerType) {
default:
log.Error().Err(errBadLogic)
}
- fmt.Println("checkpoint 5")
token := os.Getenv(telegramBotTokenEnvVar)
msgText := "ticker: " + ticker.Name + ":" + strconv.FormatFloat(price.price, 'f', -1, 64)
@@ -785,7 +768,7 @@ func main() {
var gracefulWait time.Duration
flagPort := flag.String("port", "8008", "determined the port the sercice runs on")
- redisAddress := flag.String("redisaddress", "redis:6379", "determines the address of the redis instance")
+ redisAddress := flag.String("redisaddress", "keydb:6379", "determines the address of the redis instance")
redisPassword := flag.String("redispassword", "", "determines the password of the redis db")
redisDB := flag.Int64("redisdb", 0, "determines the db number")
alertsCheckInterval := flag.Int64(
diff --git a/telebot/Dockerfile b/telebot/Dockerfile
index cdf2a83..c8522de 100644
--- a/telebot/Dockerfile
+++ b/telebot/Dockerfile
@@ -1,4 +1,4 @@
-FROM alpine:3.18 as builder
+FROM alpine:3.19 as builder
RUN apk update && apk upgrade
RUN apk add go git
COPY go.* /telebot/
@@ -6,13 +6,13 @@ RUN cd /telebot && go mod download
COPY *.go /telebot/
RUN cd /telebot && go build
-FROM alpine:3.18 as certbuilder
+FROM alpine:3.19 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
-FROM alpine:3.18
+FROM alpine:3.19
COPY --from=certbuilder /certs /certs
COPY --from=builder /telebot/telebot /telebot/
COPY ./docker-entrypoint.sh /telebot/
diff --git a/test/endpoints.sh b/test/endpoints.sh
index 2b73614..7ffb5ab 100755
--- a/test/endpoints.sh
+++ b/test/endpoints.sh
@@ -3,6 +3,7 @@ set -e
set -x
curl -k -X GET "https://localhost:10008/crypto/v1/price?name=PEPE&unit=USD"
+curl -k -X GET "https://localhost:10008/crypto/v1/price?name=BTC&unit=USD"
curl -k -X GET "https://localhost:10008/crypto/v1/pair?one=ETH&two=CAKE&multiplier=4.0"
curl -k -X POST -H "Content-Type: application/json" -d '{"name":"alert1", "expr":"ETH>CAKE"}' https://localhost:10008/crypto/v1/alert
@@ -18,5 +19,6 @@ curl -k -X POST -H "Content-Type: application/json" -d '{"name":"XMR"}' https://
curl -k -X POST -H "Content-Type: application/json" -d '{"name":"STX"}' https://localhost:10008/crypto/v1/ticker
curl -k -X POST -H "Content-Type: application/json" -d '{"name":"LINK"}' https://localhost:10008/crypto/v1/ticker
curl -k -X POST -H "Content-Type: application/json" -d '{"name":"PEPE"}' https://localhost:10008/crypto/v1/ticker
+curl -k -X POST -H "Content-Type: application/json" -d '{"name":"SOL"}' https://localhost:10008/crypto/v1/ticker
curl -k -X GET -H "Content-Type: application/json" https://localhost:10008/crypto/v1/ticker?key=ETH
curl -k -X DELETE -H "Content-Type: application/json" https://localhost:10008/crypto/v1/ticker?key=ETH