From dc26124aa3366f141f0be06c56122a2b0357b782 Mon Sep 17 00:00:00 2001 From: Alexander Kiryukhin Date: Wed, 17 Apr 2019 15:30:49 +0300 Subject: Refactoring --- Dockerfile | 17 +++++++++++++++++ bot.go | 35 ----------------------------------- bot/bot.go | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 35 deletions(-) create mode 100644 Dockerfile delete mode 100644 bot.go create mode 100644 bot/bot.go diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ceffaa6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM golang:1.12 as builder + +ARG MODE=bot +ARG PROXY= +WORKDIR /usr/src +COPY go.mod go.mod +COPY go.sum go.sum +RUN GOPROXY=${PROXY} go mod download +COPY . . +RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o transport ./${MODE} + +FROM alpine:latest + +RUN apk update && apk add --no-cache --virtual ca-certificates +WORKDIR /usr/app +COPY --from=builder /usr/src/transport . +CMD ["./transport"] diff --git a/bot.go b/bot.go deleted file mode 100644 index d3d8a8e..0000000 --- a/bot.go +++ /dev/null @@ -1,35 +0,0 @@ -package main - -import ( - "log" - "os" - - "github.com/neonxp/rutina" - - "transport/lib" - "transport/plugins" -) - -func main() { - tamtamToken := os.Getenv("TAMTAM") - telegramToken := os.Getenv("TELEGRAM") - r := rutina.New() - - routes := []lib.Routing{ - {TgID: -1001046507545, TTID: -69062921115159}, - } - - tt2tg := make(chan lib.Message, 1) - tg2tt := make(chan lib.Message, 1) - - tg := plugins.NewTelegram(telegramToken, tt2tg, tg2tt, routes) - tt := plugins.NewTamTam(tamtamToken, tg2tt, tt2tg, routes) - - r.Go(tg.Run, rutina.ShutdownIfDone, rutina.RestartIfFail) - r.Go(tt.Run, rutina.ShutdownIfDone, rutina.RestartIfFail) - - r.ListenOsSignals() - if err := r.Wait(); err != nil { - log.Fatal(err) - } -} diff --git a/bot/bot.go b/bot/bot.go new file mode 100644 index 0000000..d3d8a8e --- /dev/null +++ b/bot/bot.go @@ -0,0 +1,35 @@ +package main + +import ( + "log" + "os" + + "github.com/neonxp/rutina" + + "transport/lib" + "transport/plugins" +) + +func main() { + tamtamToken := os.Getenv("TAMTAM") + telegramToken := os.Getenv("TELEGRAM") + r := rutina.New() + + routes := []lib.Routing{ + {TgID: -1001046507545, TTID: -69062921115159}, + } + + tt2tg := make(chan lib.Message, 1) + tg2tt := make(chan lib.Message, 1) + + tg := plugins.NewTelegram(telegramToken, tt2tg, tg2tt, routes) + tt := plugins.NewTamTam(tamtamToken, tg2tt, tt2tg, routes) + + r.Go(tg.Run, rutina.ShutdownIfDone, rutina.RestartIfFail) + r.Go(tt.Run, rutina.ShutdownIfDone, rutina.RestartIfFail) + + r.ListenOsSignals() + if err := r.Wait(); err != nil { + log.Fatal(err) + } +} -- cgit v1.2.3