Skip to content

Commit

Permalink
go 1.19 (#10)
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Paskal <paskal.maksim@gmail.com>
  • Loading branch information
maksim-paskal authored Sep 7, 2022
1 parent f3b8f6a commit c88299d
Show file tree
Hide file tree
Showing 15 changed files with 170 additions and 338 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
on:
pull_request:
push:
tags:
- v*
Expand All @@ -20,12 +19,14 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.19
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ jobs:
- uses: actions/setup-go@v2
with:
stable: 'false'
go-version: '1.17'
go-version: '1.19'
- run: go test -race ./cmd
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ linters:
- funlen
- cyclop
- exhaustivestruct
- exhaustruct
- wrapcheck
- varnamelen
31 changes: 26 additions & 5 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
project_name: telegram-gateway
release:
footer: |
## Docker Images
- `paskalmaksim/telegram-gateway:latest`
- `paskalmaksim/telegram-gateway:{{ .Tag }}`
- `paskalmaksim/{{.ProjectName}}:latest`
- `paskalmaksim/{{.ProjectName}}:{{.Tag}}`
dockers:
- goos: linux
- use: buildx
goos: linux
goarch: amd64
image_templates:
- paskalmaksim/telegram-gateway:latest
- paskalmaksim/telegram-gateway:{{ .Tag }}
- paskalmaksim/{{.ProjectName}}:latest
- paskalmaksim/{{.ProjectName}}:{{.Tag}}
build_flag_templates:
- "--platform=linux/amd64"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- use: buildx
goos: linux
goarch: arm64
image_templates:
- paskalmaksim/{{.ProjectName}}:latest
- paskalmaksim/{{.ProjectName}}:{{.Tag}}
build_flag_templates:
- "--platform=linux/arm64/v8"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
builds:
- dir: ./cmd
env:
Expand All @@ -21,6 +41,7 @@ builds:
- linux
goarch:
- amd64
- arm64
checksum:
name_template: 'checksums.txt'
snapshot:
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ FROM alpine:latest
COPY ./telegram-gateway /usr/local/bin/telegram-gateway
RUN apk upgrade && apk add --no-cache ca-certificates

CMD telegram-gateway
USER 30001

ENTRYPOINT [ "/usr/local/bin/telegram-gateway" ]
18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
tag=dev
image=paskalmaksim/telegram-gateway:$(tag)
KUBECONFIG=$(HOME)/.kube/dev

test:
@scripts/validate-license.sh
Expand All @@ -8,11 +9,13 @@ test:
go test -race ./cmd
go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run -v
test-release:
git tag -d `git tag -l "helm-chart-*"`
go run github.com/goreleaser/goreleaser@latest release --snapshot --skip-publish --rm-dist
build:
git tag -d `git tag -l "helm-chart-*"`
go run github.com/goreleaser/goreleaser@latest build --rm-dist --skip-validate
mv ./dist/telegram-gateway_linux_amd64/telegram-gateway telegram-gateway
docker build --pull . -t $(image)
mv ./dist/telegram-gateway_linux_amd64_v1/telegram-gateway telegram-gateway
docker build --pull --push . -t $(image)
push:
docker push $(image)
run:
Expand All @@ -26,4 +29,13 @@ heap:
scan:
@trivy image \
-ignore-unfixed --no-progress --severity HIGH,CRITICAL \
$(image)
$(image)
deploy:
helm upgrade telegram-gateway ./charts/telegram-gateway \
--install \
--create-namespace \
--namespace telegram-gateway-test \
--set registry.image=$(image) \
--set registry.imagePullPolicy=Always
clean:
kubectl delete namespace telegram-gateway-test
2 changes: 1 addition & 1 deletion charts/telegram-gateway/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
icon: https://helm.sh/img/helm.svg
name: telegram-gateway
version: 1.0.2
version: 1.0.3
description: Telegram gateway for Prometheus and Sentry
maintainers:
- name: maksim-paskal # Maksim Paskal
Expand Down
15 changes: 11 additions & 4 deletions charts/telegram-gateway/templates/telegram-gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ spec:
labels:
app: telegram-gateway
spec:
topologySpreadConstraints:
{{ toYaml .Values.topologySpreadConstraints | indent 7 }}
affinity:
{{ toYaml .Values.affinity | indent 7 }}
volumes:
Expand All @@ -30,8 +28,17 @@ spec:
{{ toYaml .Values.resources | indent 9 }}
image: {{ .Values.registry.image }}
imagePullPolicy: {{ .Values.registry.imagePullPolicy }}
command:
- /usr/local/bin/telegram-gateway
securityContext:
runAsNonRoot: true
runAsUser: 30001
runAsGroup: 30001
privileged: false
readOnlyRootFilesystem: true
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
args:
- -config=/config/telegram-gateway.yaml
{{- if .Values.args }}
{{ toYaml .Values.args | indent 8 }}
Expand Down
14 changes: 3 additions & 11 deletions charts/telegram-gateway/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,9 @@ config:
- name: Info
value: "https://test.com#{{ .alertname | ToLower }}"

domains:
- name: default
chatID: -479832859

topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: telegram-gateway
domains:
- name: default
chatID: -479832859

affinity:
podAntiAffinity:
Expand Down
4 changes: 2 additions & 2 deletions cmd/handleProm.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
"time"
Expand Down Expand Up @@ -49,7 +49,7 @@ func handleProm(w http.ResponseWriter, r *http.Request) {

var err error

bodyBytes, err := ioutil.ReadAll(r.Body)
bodyBytes, err := io.ReadAll(r.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
log.WithError(err).Error()
Expand Down
4 changes: 2 additions & 2 deletions cmd/handleSentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"

Expand Down Expand Up @@ -60,7 +60,7 @@ func handleSentry(w http.ResponseWriter, r *http.Request) {

var err error

bodyBytes, err := ioutil.ReadAll(r.Body)
bodyBytes, err := io.ReadAll(r.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
log.WithError(err).Error()
Expand Down
4 changes: 2 additions & 2 deletions cmd/handleTest.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ limitations under the License.
package main

import (
"io/ioutil"
"io"
"net/http"

tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
Expand Down Expand Up @@ -50,7 +50,7 @@ func handleTest(w http.ResponseWriter, r *http.Request) {
log.WithError(err).Error()
}

bodyBytes, err := ioutil.ReadAll(r.Body)
bodyBytes, err := io.ReadAll(r.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
log.WithError(err).Error()
Expand Down
20 changes: 17 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"net/http"
pprof "net/http/pprof"
"os"
"time"

tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/gorilla/mux"
Expand All @@ -34,6 +34,12 @@ var (
domains map[string]ConfigDomains
)

const (
serverReadTimeout = 5 * time.Second
serverRequestTimeout = 60 * time.Second
serverWriteTimeout = 70 * time.Second
)

func main() {
flag.Parse()

Expand Down Expand Up @@ -72,7 +78,7 @@ func main() {
log.Infof("Starting telegram-gateway %s", appConfig.Version)

// load config file
yamlFile, err := ioutil.ReadFile(*appConfig.configFileName)
yamlFile, err := os.ReadFile(*appConfig.configFileName)
if err != nil {
log.WithError(err).Fatalf("error in reading config %s", *appConfig.configFileName)
}
Expand Down Expand Up @@ -154,7 +160,15 @@ func main() {

log.Printf("Staring server on port %d", *appConfig.port)

err = http.ListenAndServe(fmt.Sprintf(":%d", *appConfig.port), router)
timeoutMessage := fmt.Sprintf("Server timeout after %s", serverRequestTimeout)

server := &http.Server{
Addr: fmt.Sprintf(":%d", *appConfig.port),
Handler: http.TimeoutHandler(router, serverRequestTimeout, timeoutMessage),
ReadTimeout: serverReadTimeout,
WriteTimeout: serverWriteTimeout,
}
err = server.ListenAndServe()

if err != nil {
log.WithError(err).Fatal("ListenAndServe")
Expand Down
20 changes: 10 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
module github.com/maksim-paskal/telegram-gateway

go 1.17
go 1.19

require (
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible
github.com/gorilla/mux v1.8.0
github.com/maksim-paskal/logrus-hook-sentry v0.0.9
github.com/prometheus/alertmanager v0.23.0
github.com/sirupsen/logrus v1.8.1
github.com/prometheus/alertmanager v0.24.0
github.com/sirupsen/logrus v1.9.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/getsentry/sentry-go v0.13.0 // indirect
github.com/golang/protobuf v1.4.3 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_golang v1.12.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.30.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 // indirect
github.com/technoweenie/multipartstreamer v1.0.1 // indirect
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect
google.golang.org/protobuf v1.26.0-rc.1 // indirect
golang.org/x/sys v0.0.0-20220907062415-87db552b00fd // indirect
google.golang.org/protobuf v1.26.0 // indirect
)
Loading

0 comments on commit c88299d

Please sign in to comment.