Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: move back to fly.io #64

Merged
merged 1 commit into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 0 additions & 41 deletions .github/workflows/codeql.yml

This file was deleted.

14 changes: 14 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,17 @@ jobs:
environment: production
set_commits: skip
version: ${{ github.sha }}

deploy:
name: Deploy app
needs:
- ci
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: superfly/flyctl-actions/setup-flyctl@master

- run: flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ feature_flag:
dukun: false
under_attack: true
reminder: false
deletion: false
http_server: false
home_group_id: 0 # Assuming default value
admin_ids: [ ]
# Optional sentry.io DSN, you can track project errors & performance there
Expand Down Expand Up @@ -72,7 +74,9 @@ under_attack:
"badwords_insertion": false,
"dukun": false,
"under_attack": true,
"reminder": false
"reminder": false,
"deletion": false,
"http_server": false
},
"home_group_id": 0,
"admin_ids": [],
Expand Down Expand Up @@ -107,6 +111,8 @@ Optional:
* FEATURE_FLAG_DUKUN: (Default: "false")
* FEATURE_FLAG_UNDER_ATTACK: (Default: "true")
* FEATURE_FLAG_REMINDER: (Default: "false")
* FEATURE_FLAG_DELETION: (Default: "false")
* FEATURE_FLAG_HTTP_SERVER: (Default: "false")
* HOME_GROUP_ID: (No default value provided)
* ADMIN_IDS: (No default value provided, comma-separated string)
* SENTRY_DSN: (No default value provided)
Expand Down Expand Up @@ -199,7 +205,7 @@ Let's work together to make Telegram a safer and more enjoyable experience for e

```
Teknologi Umum Captcha Bot
Copyright (C) 2023 Teknologi Umum <[email protected]>
Copyright (C) 2024 Teknologi Umum <[email protected]>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
1 change: 1 addition & 0 deletions cmd/captcha/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type FeatureFlag struct {
UnderAttack bool `yaml:"under_attack" json:"under_attack" env:"FEATURE_FLAG_UNDER_ATTACK" env-default:"true"`
Reminder bool `yaml:"reminder" json:"reminder" env:"FEATURE_FLAG_REMINDER" env-default:"false"`
Deletion bool `yaml:"deletion" json:"deletion" env:"FEATURE_FLAG_DELETION" env-default:"false"`
HttpServer bool `yaml:"http_server" json:"http_server" env:"FEATURE_FLAG_HTTP_SERVER" env-default:"false"`
}

type Configuration struct {
Expand Down
31 changes: 20 additions & 11 deletions cmd/captcha/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,16 @@ func main() {
return
}

httpServer := server.New(server.Config{
DB: db,
Memory: cache,
Mongo: mongoClient,
MongoDBName: mongoDBName,
ListeningAddress: net.JoinHostPort(configuration.HTTPServer.ListeningHost, configuration.HTTPServer.ListeningPort),
})
var httpServer *http.Server
if configuration.FeatureFlag.HttpServer {
httpServer = server.New(server.Config{
DB: db,
Memory: cache,
Mongo: mongoClient,
MongoDBName: mongoDBName,
ListeningAddress: net.JoinHostPort(configuration.HTTPServer.ListeningHost, configuration.HTTPServer.ListeningPort),
})
}

// This is basically just for health check.
b.Handle("/start", func(c tb.Context) error {
Expand Down Expand Up @@ -412,6 +415,10 @@ func main() {
signal.Notify(exitSignal, os.Interrupt)

go func() {
if httpServer == nil {
return
}

// Start an HTTP server instance
log.Printf("Starting http server on %s", httpServer.Addr)
err := httpServer.ListenAndServe()
Expand All @@ -429,10 +436,12 @@ func main() {

b.Stop()

err = httpServer.Shutdown(shutdownCtx)
if err != nil {
log.Error().Err(err).Msg("Shutting down the http server")
sentry.CaptureException(err)
if httpServer != nil {
err := httpServer.Shutdown(shutdownCtx)
if err != nil {
log.Error().Err(err).Msg("Shutting down the http server")
sentry.CaptureException(err)
}
}

log.Debug().Msg("Starting a 10 second countdown until killing the application")
Expand Down
16 changes: 8 additions & 8 deletions cmd/captcha/transport_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ func (s *SentryTransportWrapper) RoundTrip(request *http.Request) (*http.Respons
ctx := request.Context()
var cleanRequestURL string
pathFragments := strings.Split(request.URL.Path, "/")
if len(pathFragments) >= 2 {
if pathFragments[0] == "" {
pathFragments[1] = "bot[Filtered]"
} else {
pathFragments[0] = "bot[Filtered]"
for i, value := range pathFragments {
if strings.HasPrefix(value, "bot") {
pathFragments[i] = "bot[Filtered]"
}

cleanRequestURL = strings.Join(pathFragments, "/")
}

span := sentry.StartSpan(ctx, "http.client", sentry.WithTransactionName(fmt.Sprintf("%s %s", request.Method, cleanRequestURL)))
cleanRequestURL = strings.Join(pathFragments, "/")
transactionName := fmt.Sprintf("%s %s", request.Method, cleanRequestURL)
span := sentry.StartSpan(ctx, "http.client",
sentry.WithTransactionName(transactionName),
sentry.WithDescription(transactionName))
defer span.Finish()

span.SetData("http.query", request.URL.Query().Encode())
Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Teknologi Umum Captcha Bot
// Copyright (C) 2023 Teknologi Umum <[email protected]>
// Copyright (C) 2024 Teknologi Umum <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down
42 changes: 8 additions & 34 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -1,38 +1,12 @@
# fly.toml app configuration file generated for teknologi-umum-captcha on 2024-06-23T10:31:45+07:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = "captcha-bot"

kill_signal = "SIGINT"
kill_timeout = 5

[env]

[experimental]
allowed_public_ports = []
auto_rollback = true

[[services]]
http_checks = []
internal_port = 8080
processes = ["app"]
protocol = "tcp"
script_checks = []

[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"

[[services.ports]]
handlers = ["http"]
port = 80
app = 'teknologi-umum-captcha'
primary_region = 'cdg'

[[services.ports]]
handlers = ["tls", "http"]
port = 443
[build]

[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 6
timeout = "2s"
[[vm]]
size = 'shared-cpu-1x'
Loading