🐳 Create Dockerfile and DockerCompose file and implement authentication with telegram api
This commit is contained in:
parent
6001cdba88
commit
18878de12c
22
Dockerfile
Normal file
22
Dockerfile
Normal file
@ -0,0 +1,22 @@
|
||||
# build stage
|
||||
FROM golang:1.13-stretch AS build-env
|
||||
COPY . /src
|
||||
WORKDIR /src
|
||||
ENV GO113MODULE=on
|
||||
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go test ./... -cover -coverprofile=c.out #gosetup
|
||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o goapp
|
||||
|
||||
# final stage
|
||||
FROM alpine
|
||||
LABEL maintainer="Alphyron <admin@dragon-labs.de>"
|
||||
|
||||
RUN apk update \
|
||||
&& apk upgrade \
|
||||
&& apk add --no-cache \
|
||||
ca-certificates \
|
||||
&& update-ca-certificates 2>/dev/null || true
|
||||
|
||||
WORKDIR /app
|
||||
COPY --from=build-env /src .
|
||||
RUN chmod +x ./goapp
|
||||
CMD [ "./goapp"]
|
@ -4,6 +4,7 @@ import "github.com/caarlos0/env"
|
||||
|
||||
type TelegramConfig struct {
|
||||
TelegramKey string `env:"TELEGRAM_KEY,required"`
|
||||
TelegramDebug bool `env:"TELEGRAM_DEBUG" envDefault:"false"`
|
||||
}
|
||||
|
||||
func (tc *TelegramConfig) LoadConfig() error {
|
||||
|
28
docker-compose.yml
Normal file
28
docker-compose.yml
Normal file
@ -0,0 +1,28 @@
|
||||
version: '3.7'
|
||||
|
||||
services:
|
||||
app:
|
||||
image: group_helper:latest
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
restart: on-failure
|
||||
environment:
|
||||
- TELEGRAM_KEY=340059059:AAG8MRgRmdk5nI_hye5HkSwQyV9wqwoUSbA
|
||||
- DB_DEBUG=true
|
||||
- DB_TYPE=mysql
|
||||
- DB_HOST=mysql
|
||||
- DB_PORT=3306
|
||||
- DB_USER=go
|
||||
- DB_PASS=go
|
||||
- DB_DATABASE=go
|
||||
|
||||
mysql:
|
||||
image: mysql:8
|
||||
environment:
|
||||
- MYSQL_RANDOM_ROOT_PASSWORD=true
|
||||
- MYSQL_USER=go
|
||||
- MYSQL_PASSWORD=go
|
||||
- MYSQL_DATABASE=go
|
||||
ports:
|
||||
- 3306:3306
|
2
go.mod
2
go.mod
@ -4,6 +4,8 @@ go 1.13
|
||||
|
||||
require (
|
||||
github.com/caarlos0/env v3.5.0+incompatible
|
||||
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible
|
||||
github.com/jinzhu/gorm v1.9.12
|
||||
github.com/stretchr/testify v1.5.1 // indirect
|
||||
github.com/technoweenie/multipartstreamer v1.0.1 // indirect
|
||||
)
|
||||
|
17
main.go
17
main.go
@ -3,20 +3,33 @@ package main
|
||||
import (
|
||||
"git.dragon-labs.de/alphyron/group_helper/config"
|
||||
"log"
|
||||
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := config.DatabaseConfig{}.LoadConfig()
|
||||
dbConfig := config.DatabaseConfig{}
|
||||
err := dbConfig.LoadConfig()
|
||||
|
||||
if err != nil {
|
||||
log.Println("Problem while loading database environment variables")
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
err = config.TelegramConfig{}.LoadConfig()
|
||||
tgConfig := config.TelegramConfig{}
|
||||
err = tgConfig.LoadConfig()
|
||||
|
||||
if err != nil {
|
||||
log.Println("Problem while loading telegram environment variables")
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
bot, err := tgbotapi.NewBotAPI(tgConfig.TelegramKey)
|
||||
if err != nil {
|
||||
log.Println("Problem while authenticate at telegram")
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
bot.Debug = tgConfig.TelegramDebug
|
||||
log.Printf("Authorized on account %s", bot.Self.UserName)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user