Skip to content

Commit

Permalink
DASHBOARD_URL -> FRONTEND_URL + fix code accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Oct 27, 2024
1 parent 75213bc commit bc3f4b3
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 20 deletions.
4 changes: 2 additions & 2 deletions backend/cmd/gh-updater/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func main() {
slog.SetDefault(setUpLogging())
slog.Debug("gh-updater is starting")

dashboardURL := mustGetenv("REDIRECT_URL")
frontendURL := mustGetenv("FRONTEND_URL")

githubAppID := mustGetenvInt64("GITHUB_APP_ID")
privateKeyBase64 := mustGetenv("GITHUB_APP_PRIVATE_KEY_BASE64")
Expand Down Expand Up @@ -94,7 +94,7 @@ func main() {
minReconnectInterval := 10 * time.Second
maxReconnectInterval := time.Minute
dbListener := pq.NewListener(psqlInfo, minReconnectInterval, maxReconnectInterval, nil)
ghUpdater := updater.New(dbListener, repoRepo, userRepo, buildRepo, githubService, dashboardURL)
ghUpdater := updater.New(dbListener, repoRepo, userRepo, buildRepo, githubService, frontendURL)

err = ghUpdater.Start(ctx)
if err != nil {
Expand Down
10 changes: 7 additions & 3 deletions backend/cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func main() {
port := mustGetenv("PORT")

mainDomain := os.Getenv("MAIN_DOMAIN")
redirectURL := mustGetenv("REDIRECT_URL")
frontendURL := mustGetenv("FRONTEND_URL")

slog.Debug("server is starting...")

Expand Down Expand Up @@ -72,13 +72,17 @@ func main() {
repoRepo := data.NewPostgresRepoRepo(db)
logsRepo := data.NewInfluxLogsRepo(influxClient, influxOrg, influxBucket)

webhooks := webhook.NewWebhookHandler(userRepo, repoRepo, buildRepo, mainDomain, redirectURL, githubAppClientID, githubAppClientSecret, githubAppWebhookSecret, jwtSecret)
webhooks, err := webhook.NewHandler(userRepo, repoRepo, buildRepo, mainDomain, frontendURL, githubAppClientID, githubAppClientSecret, githubAppWebhookSecret, jwtSecret)
if err != nil {
slog.Error("error creating webhook handler", slog.Any("error", err))
os.Exit(1)
}
app := api.NewApp(buildRepo, logsRepo, repoRepo, userRepo, jwtSecret)

mux := http.NewServeMux()
mux.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) {
_, _ = fmt.Fprintf(w, "hello world\n\nthis is bee-ci backend server!\n\n")
_, _ = fmt.Fprintf(w, "SERVER_URL: %s\nMAIN_DOMAIN: %s\nREDIRECT_URL: %s\n", serverURL, mainDomain, redirectURL)
_, _ = fmt.Fprintf(w, "SERVER_URL: %s\nMAIN_DOMAIN: %s\nFRONTEND_URL: %s\n", serverURL, mainDomain, frontendURL)
})
mux.Handle("/webhook/", http.StripPrefix("/webhook", webhooks.Mux()))
mux.Handle("/api/", http.StripPrefix("/api", app.Mux()))
Expand Down
14 changes: 10 additions & 4 deletions backend/internal/server/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"log"
"log/slog"
"net/http"
"net/url"
"strconv"
"time"

Expand Down Expand Up @@ -52,17 +53,22 @@ type Handler struct {
jwtSecret []byte
}

func NewWebhookHandler(
func NewHandler(
userRepo data.UserRepo,
repoRepo data.RepoRepo,
buildRepo data.BuildRepo,
mainDomain string,
redirectURL string,
frontendURL string,
githubAppClientID string,
githubAppClientSecret string,
githubAppWebhookSecret string,
jwtSecret []byte,
) *Handler {
) (*Handler, error) {
redirectURL, err := url.JoinPath(frontendURL, "dashboard")
if err != nil {
return nil, fmt.Errorf("could not join path valid to create a redirect URL: %v", err)
}

return &Handler{
httpClient: &http.Client{Timeout: 10 * time.Second},
userRepo: userRepo,
Expand All @@ -74,7 +80,7 @@ func NewWebhookHandler(
githubAppClientSecret: githubAppClientSecret,
githubAppWebhookSecret: githubAppWebhookSecret,
jwtSecret: jwtSecret,
}
}, nil
}

func (h Handler) Mux() http.Handler {
Expand Down
20 changes: 14 additions & 6 deletions backend/internal/updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"log/slog"
"net/http"
"net/url"
"strconv"
"time"

Expand All @@ -30,7 +31,7 @@ type Updater struct {
userRepo data.UserRepo
buildRepo data.BuildRepo
githubService *ghs.GithubService
dashboardURL string
frontendURL string
}

func New(
Expand All @@ -39,7 +40,7 @@ func New(
userRepo data.UserRepo,
buildRepo data.BuildRepo,
githubService *ghs.GithubService,
dashboardURL string,
frontendURL string,
) *Updater {
return &Updater{
logger: slog.Default(), // TODO: add some "subsystem name" to this logger
Expand All @@ -50,7 +51,7 @@ func New(
userRepo: userRepo,
buildRepo: buildRepo,
githubService: githubService,
dashboardURL: dashboardURL,
frontendURL: frontendURL,
}
}

Expand Down Expand Up @@ -136,13 +137,20 @@ func (u Updater) createCheckRun(ctx context.Context, build data.Build) (checkRun
return 0, fmt.Errorf("get client for installation: %w", err)
}

buildID := strconv.FormatInt(build.ID, 10)

detailsURL, err := url.JoinPath(u.frontendURL, "pipeline", buildID)
if err != nil {
return 0, fmt.Errorf("join paths to create details URL: %w", err)
}

createCheckRunOptions := github.CreateCheckRunOptions{
// TODO: Get name from the BeeCI config file?
Name: build.CommitMsg + ", started at: " + fmt.Sprint(time.Now().Format(time.RFC822Z)),
HeadSHA: build.CommitSHA,
DetailsURL: github.String(fmt.Sprintf("%s/pipeline/%d", u.dashboardURL, build.ID)),
ExternalID: github.String(strconv.FormatInt(build.ID, 10)),
Status: github.String(build.Status),
DetailsURL: &detailsURL,
ExternalID: &buildID,
Status: &build.Status,
Conclusion: nil,
StartedAt: &github.Timestamp{Time: build.CreatedAt},
CompletedAt: nil,
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ services:
SERVER_URL: localhost:8080
PORT: 8080
MAIN_DOMAIN: "" # must be empty for localhost
REDIRECT_URL: http://localhost:3000/dashboard
FRONTEND_URL: http://localhost:3000
DB_HOST: ${DB_HOST}
DB_PORT: ${DB_PORT}
DB_USER: ${DB_USER}
Expand All @@ -47,7 +47,7 @@ services:
dockerfile: gh-updater.dockerfile
init: true
ports:
- "40001:40000" # debugger por
- "40001:40000" # debugger port
depends_on:
database-postgres:
condition: service_healthy
Expand All @@ -56,7 +56,7 @@ services:
env_file:
- .env
environment:
REDIRECT_URL: http://localhost:3000/dashboard
FRONTEND_URL: http://localhost:3000
DB_HOST: ${DB_HOST}
DB_PORT: ${DB_PORT}
DB_USER: ${DB_USER}
Expand Down
4 changes: 2 additions & 2 deletions infra/env.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ locals {
scope = "RUN_TIME",
},
{
key = "REDIRECT_URL",
value = "https://bee-ci.pacia.tech/dashboard",
key = "FRONTEND_URL",
value = "https://bee-ci.pacia.tech",
scope = "RUN_TIME"
},
{
Expand Down

0 comments on commit bc3f4b3

Please sign in to comment.