-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
377 additions
and
285 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: Build and Publish | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
PACKAGE_NAME: ${{ github.repository }} | ||
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }} | ||
GITHUB_SHA: ${{ github.sha }} | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
publish-image: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Print Go version | ||
run: | | ||
go version | ||
- name: Log in to the Container registry | ||
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Set image name | ||
run: | | ||
echo "IMAGE_NAME=${REGISTRY}/${GITHUB_REPOSITORY_OWNER,,}/${PACKAGE_NAME,,}:${GITHUB_SHA}" >> ${GITHUB_ENV} | ||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ env.IMAGE_NAME }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
|
||
- name: Log image name | ||
run: | | ||
echo "Image URI: ${IMAGE_NAME}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.iml | ||
.idea | ||
config.toml | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Build container | ||
FROM golang:1.22 AS builder | ||
|
||
RUN go version | ||
|
||
RUN apt-get update && apt-get upgrade -y && apt-get install -y ca-certificates git zlib1g-dev | ||
|
||
COPY . /go/src/github.com/TicketsBot/votelistener | ||
WORKDIR /go/src/github.com/TicketsBot/votelistener | ||
|
||
RUN git submodule update --init --recursive --remote | ||
|
||
RUN set -Eeux && \ | ||
go mod download && \ | ||
go mod verify | ||
|
||
RUN GOOS=linux GOARCH=amd64 \ | ||
go build \ | ||
-trimpath \ | ||
-o main cmd/votelistener/main.go | ||
|
||
# Prod container | ||
FROM ubuntu:latest | ||
|
||
RUN apt-get update && apt-get upgrade -y && apt-get install -y ca-certificates curl | ||
|
||
COPY --from=builder /go/src/github.com/TicketsBot/votelistener/main /srv/votelistener/main | ||
|
||
RUN chmod +x /srv/votelistener/main | ||
|
||
RUN useradd -m container | ||
USER container | ||
WORKDIR /srv/votelistener | ||
|
||
CMD ["/srv/votelistener/main"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,42 @@ | ||
package main | ||
|
||
import ( | ||
crypto "crypto/rand" | ||
"encoding/binary" | ||
"github.com/TicketsBot/VoteListener/database" | ||
"github.com/TicketsBot/VoteListener/http" | ||
"io" | ||
"math/rand" | ||
"context" | ||
"github.com/TicketsBot/VoteListener/pkg/config" | ||
"github.com/TicketsBot/VoteListener/pkg/server" | ||
"github.com/TicketsBot/common/observability" | ||
"github.com/TicketsBot/database" | ||
"github.com/jackc/pgx/v4/pgxpool" | ||
"time" | ||
) | ||
|
||
func main() { | ||
// seed random | ||
b := make([]byte, 8) | ||
if _, err := io.ReadFull(crypto.Reader, b); err != nil { | ||
cfg, err := config.LoadFromEnv() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
rand.Seed(int64(binary.LittleEndian.Uint64(b))) | ||
logger, err := observability.Configure(cfg.SentryDsn, cfg.JsonLogs, cfg.LogLevel) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
logger.Info("Connecting to database...") | ||
db := connectToDatabase(cfg) | ||
logger.Info("Connected to database") | ||
|
||
s := server.NewServer(logger, cfg, db) | ||
s.Run() | ||
} | ||
|
||
func connectToDatabase(cfg config.Config) *database.Database { | ||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) | ||
defer cancel() | ||
|
||
pool, err := pgxpool.Connect(ctx, cfg.DatabaseUri) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
database.ConnectDatabase() | ||
http.StartServer() | ||
return database.NewDatabase(pool) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
- BOT_ID | ||
- TOPGG_TOKEN | ||
- SENTRY_DSN | ||
- JSON_LOGS | ||
- LOG_LEVEL | ||
- DBL_TOKEN | ||
- SERVER_ADDR | ||
- DATABASE_URI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,50 @@ | ||
module github.com/TicketsBot/VoteListener | ||
|
||
go 1.14 | ||
go 1.22 | ||
|
||
toolchain go1.22.4 | ||
|
||
require ( | ||
github.com/BurntSushi/toml v0.3.1 | ||
github.com/TicketsBot/database v0.0.0-20200617201314-8bc6099808fb // indirect | ||
github.com/gin-gonic/gin v1.6.3 // indirect | ||
github.com/go-ozzo/ozzo-routing v2.1.4+incompatible // indirect | ||
github.com/go-sql-driver/mysql v1.5.0 | ||
github.com/golang/gddo v0.0.0-20200324184333-3c2cc9a6329d // indirect | ||
github.com/TicketsBot/common v0.0.0-20240829145439-0700328a02e7 | ||
github.com/TicketsBot/database v0.0.0-20240829143833-9d42609021c0 | ||
github.com/caarlos0/env/v11 v11.2.2 | ||
github.com/gin-gonic/gin v1.8.1 | ||
github.com/jackc/pgx/v4 v4.6.0 | ||
github.com/qiangxue/fasthttp-routing v0.0.0-20160225050629-6ccdc2a18d87 | ||
github.com/valyala/fasthttp v1.12.0 | ||
go.uber.org/zap v1.27.0 | ||
) | ||
|
||
require ( | ||
github.com/getsentry/sentry-go v0.21.0 // indirect | ||
github.com/gin-contrib/sse v0.1.0 // indirect | ||
github.com/go-playground/locales v0.14.0 // indirect | ||
github.com/go-playground/universal-translator v0.18.0 // indirect | ||
github.com/go-playground/validator/v10 v10.11.1 // indirect | ||
github.com/goccy/go-json v0.9.11 // indirect | ||
github.com/google/uuid v1.6.0 // indirect | ||
github.com/jackc/chunkreader/v2 v2.0.1 // indirect | ||
github.com/jackc/pgconn v1.5.0 // indirect | ||
github.com/jackc/pgio v1.0.0 // indirect | ||
github.com/jackc/pgpassfile v1.0.0 // indirect | ||
github.com/jackc/pgproto3/v2 v2.0.1 // indirect | ||
github.com/jackc/pgservicefile v0.0.0-20200307190119-3430c5407db8 // indirect | ||
github.com/jackc/pgtype v1.3.0 // indirect | ||
github.com/jackc/pgx v3.6.2+incompatible // indirect | ||
github.com/jackc/puddle v1.1.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/leodido/go-urn v1.2.1 // indirect | ||
github.com/lib/pq v1.3.0 // indirect | ||
github.com/mattn/go-isatty v0.0.17 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/pelletier/go-toml/v2 v2.0.5 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/ugorji/go/codec v1.2.7 // indirect | ||
go.uber.org/multierr v1.10.0 // indirect | ||
golang.org/x/crypto v0.7.0 // indirect | ||
golang.org/x/net v0.8.0 // indirect | ||
golang.org/x/sys v0.6.0 // indirect | ||
golang.org/x/text v0.8.0 // indirect | ||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect | ||
google.golang.org/protobuf v1.29.1 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
) |
Oops, something went wrong.