Skip to content

Commit 0b17bfe

Browse files
ZIJmotatoes
andauthored
Use DIGGER_GITHUB_HOSTNAME env var for job links (#1771)
* Use GITHUB_BASE_URL env var for job links --------- Co-authored-by: motatoes <[email protected]>
1 parent 9cd46a2 commit 0b17bfe

File tree

7 files changed

+32
-30
lines changed

7 files changed

+32
-30
lines changed

Dockerfile_backend

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ RUN go build -ldflags="-X 'main.Version=${COMMIT_SHA}'" -o backend_exe ./backend
2020

2121
# Multi-stage build will just copy the binary to an alpine image.
2222
FROM ubuntu:24.04 as runner
23-
ENV ATLAS_VERSION v0.16.0
23+
ENV ATLAS_VERSION v0.28.0
2424
ARG COMMIT_SHA
2525
WORKDIR /app
2626

Dockerfile_backend_ee

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ RUN go build -ldflags="-X 'main.Version=${COMMIT_SHA}'" -o backend_exe ./ee/back
2020

2121
# Multi-stage build will just copy the binary to an alpine image.
2222
FROM ubuntu:24.04 as runner
23-
ENV ATLAS_VERSION v0.16.0
23+
ENV ATLAS_VERSION v0.28.0
2424
ARG COMMIT_SHA
2525
WORKDIR /app
2626

Dockerfile_drift

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ RUN go build -ldflags="-X 'main.Version=${COMMIT_SHA}'" -o drift_exe ./ee/drift/
2020

2121
# Multi-stage build will just copy the binary to an alpine image.
2222
FROM ubuntu:24.04 as runner
23-
ENV ATLAS_VERSION v0.16.0
23+
ENV ATLAS_VERSION v0.28.0
2424
ARG COMMIT_SHA
2525
WORKDIR /app
2626

Dockerfile_next

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ RUN go build -ldflags="-X 'main.Version=${COMMIT_SHA}'" -o next_exe ./next/
2020

2121
# Multi-stage build will just copy the binary to an alpine image.
2222
FROM ubuntu:24.04 as runner
23-
ENV ATLAS_VERSION v0.16.0
23+
ENV ATLAS_VERSION v0.28.0
2424
ARG COMMIT_SHA
2525
WORKDIR /app
2626

Dockerfile_tasks

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ RUN go build -ldflags="-X 'main.Version=${COMMIT_SHA}'" -o tasks_exe ./backend/t
2020

2121
# Multi-stage build will just copy the binary to an alpine image.
2222
FROM ubuntu:24.04 as runner
23-
ENV ATLAS_VERSION v0.16.0
23+
ENV ATLAS_VERSION v0.28.0
2424
ARG COMMIT_SHA
2525
WORKDIR /app
2626

backend/controllers/github.go

+12-19
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ import (
66
"encoding/json"
77
"errors"
88
"fmt"
9+
"log"
10+
"math/rand"
11+
"net/http"
12+
"net/url"
13+
"os"
14+
"path"
15+
"reflect"
16+
"strconv"
17+
"strings"
18+
919
"github.com/diggerhq/digger/backend/ci_backends"
1020
"github.com/diggerhq/digger/backend/locking"
1121
"github.com/diggerhq/digger/backend/segment"
@@ -17,15 +27,6 @@ import (
1727
orchestrator_scheduler "github.com/diggerhq/digger/libs/scheduler"
1828
"github.com/google/uuid"
1929
"gorm.io/gorm"
20-
"log"
21-
"math/rand"
22-
"net/http"
23-
"net/url"
24-
"os"
25-
"path"
26-
"reflect"
27-
"strconv"
28-
"strings"
2930

3031
"github.com/diggerhq/digger/backend/middleware"
3132
"github.com/diggerhq/digger/backend/models"
@@ -187,7 +188,7 @@ func GithubAppSetup(c *gin.Context) {
187188
},
188189
}
189190

190-
githubHostname := getGithubHostname()
191+
githubHostname := utils.GetGithubHostname()
191192
url := &url.URL{
192193
Scheme: "https",
193194
Host: githubHostname,
@@ -209,14 +210,6 @@ func GithubAppSetup(c *gin.Context) {
209210
c.HTML(http.StatusOK, "github_setup.tmpl", gin.H{"Target": url.String(), "Manifest": string(jsonManifest)})
210211
}
211212

212-
func getGithubHostname() string {
213-
githubHostname := os.Getenv("DIGGER_GITHUB_HOSTNAME")
214-
if githubHostname == "" {
215-
githubHostname = "github.com"
216-
}
217-
return githubHostname
218-
}
219-
220213
// GithubSetupExchangeCode handles the user coming back from creating their app
221214
// A code query parameter is exchanged for this app's ID, key, and webhook_secret
222215
// Implements https://developer.github.com/apps/building-github-apps/creating-github-apps-from-a-manifest/#implementing-the-github-app-manifest-flow
@@ -1248,7 +1241,7 @@ func validateGithubCallback(githubClientProvider utils.GithubClientProvider, cli
12481241
}
12491242
httpClient := http.Client{}
12501243

1251-
githubHostname := getGithubHostname()
1244+
githubHostname := utils.GetGithubHostname()
12521245
reqURL := fmt.Sprintf("https://%v/login/oauth/access_token?client_id=%s&client_secret=%s&code=%s", githubHostname, clientId, clientSecret, code)
12531246
req, err := http.NewRequest(http.MethodPost, reqURL, nil)
12541247
if err != nil {

backend/utils/github.go

+15-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import (
44
"context"
55
"encoding/base64"
66
"fmt"
7+
"log"
8+
net "net/http"
9+
"os"
10+
"strings"
11+
"time"
12+
713
"github.com/bradleyfalzon/ghinstallation/v2"
814
"github.com/diggerhq/digger/backend/models"
915
"github.com/diggerhq/digger/libs/ci"
@@ -13,11 +19,6 @@ import (
1319
"github.com/go-git/go-git/v5/plumbing"
1420
"github.com/go-git/go-git/v5/plumbing/transport/http"
1521
"github.com/google/go-github/v61/github"
16-
"log"
17-
net "net/http"
18-
"os"
19-
"strings"
20-
"time"
2122
)
2223

2324
func createTempDir() string {
@@ -211,6 +212,14 @@ func SetPRStatusForJobs(prService ci.PullRequestService, prNumber int, jobs []sc
211212
return nil
212213
}
213214

215+
func GetGithubHostname() string {
216+
githubHostname := os.Getenv("DIGGER_GITHUB_HOSTNAME")
217+
if githubHostname == "" {
218+
githubHostname = "github.com"
219+
}
220+
return githubHostname
221+
}
222+
214223
func GetWorkflowIdAndUrlFromDiggerJobId(client *github.Client, repoOwner string, repoName string, diggerJobID string) (int64, string, error) {
215224
timeFilter := time.Now().Add(-5 * time.Minute)
216225
runs, _, err := client.Actions.ListRepositoryWorkflowRuns(context.Background(), repoOwner, repoName, &github.ListWorkflowRunsOptions{
@@ -230,7 +239,7 @@ func GetWorkflowIdAndUrlFromDiggerJobId(client *github.Client, repoOwner string,
230239
for _, workflowjob := range workflowjobs.Jobs {
231240
for _, step := range workflowjob.Steps {
232241
if strings.Contains(*step.Name, diggerJobID) {
233-
return *workflowRun.ID, fmt.Sprintf("https://github.com/%v/%v/actions/runs/%v", repoOwner, repoName, *workflowRun.ID), nil
242+
return *workflowRun.ID, fmt.Sprintf("https://%v/%v/%v/actions/runs/%v", GetGithubHostname(), repoOwner, repoName, *workflowRun.ID), nil
234243
}
235244
}
236245

0 commit comments

Comments
 (0)