Skip to content

Commit d5f42f3

Browse files
committed
Add docker-compose infra to build and run the admin
Signed-off-by: Florent Poinsard <[email protected]>
1 parent e8fd1b3 commit d5f42f3

File tree

9 files changed

+86
-20
lines changed

9 files changed

+86
-20
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
FROM golang:1.22.5-bookworm AS build-stage
15+
FROM golang:1.23.0-bookworm AS build-stage
1616

1717
WORKDIR /build
1818

Dockerfile.admin

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright 2023 The Vitess Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
FROM golang:1.23.0-bookworm AS build-stage
16+
17+
WORKDIR /build
18+
19+
COPY go.mod go.sum ./
20+
21+
RUN go mod download
22+
23+
COPY . .
24+
25+
# Build arewefastyet
26+
RUN CGO_ENABLED=0 GOOS=linux go build -o /arewefastyetcli ./go/main.go
27+
28+
FROM debian:bookworm AS run-stage
29+
30+
# Copy the source code to the working directory
31+
COPY --from=build-stage /arewefastyetcli /arewefastyetcli
32+
COPY --from=build-stage /build/go/admin/templates/ /go/admin/templates/
33+
COPY --from=build-stage /build/go/admin/assets/ /go/admin/assets/
34+
35+
EXPOSE 8081
36+
37+
# Configuration files MUST be attached to the container using a volume.
38+
# The configuration files are not mounted on the Docker image for obvious
39+
# security reasons.
40+
CMD ["/arewefastyetcli", "admin", "--config", "/config/config.yaml", "--secrets", "/config/secrets.yaml"]

docker-compose.prod.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,24 @@ services:
7070
- "traefik.http.services.api.loadbalancer.server.port=8080"
7171
network_mode: bridge
7272

73+
admin:
74+
restart: always
75+
build:
76+
context: .
77+
dockerfile: Dockerfile.admin
78+
image: "arewefastyet-admin"
79+
container_name: "admin"
80+
volumes:
81+
- "./config/prod/config.yaml:/config/config.yaml"
82+
- "./config/prod/secrets.yaml:/config/secrets.yaml"
83+
labels:
84+
- "traefik.enable=true"
85+
- "traefik.http.routers.admin.rule=Host(`benchmark.vitess.io`) && PathPrefix(`/admin`)"
86+
- "traefik.http.routers.admin.entrypoints=https"
87+
- "traefik.http.routers.admin.tls.certresolver=tlsresolver"
88+
- "traefik.http.services.admin.loadbalancer.server.port=8081"
89+
network_mode: bridge
90+
7391
cleanup_executions:
7492
image: alpine
7593
restart: on-failure

docker-compose.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ services:
5353
- "traefik.http.services.api.loadbalancer.server.port=8080"
5454
network_mode: bridge
5555

56+
admin:
57+
restart: always
58+
build:
59+
context: .
60+
dockerfile: Dockerfile.admin
61+
image: "arewefastyet-admin"
62+
container_name: "admin"
63+
volumes:
64+
- "./config/dev/config.yaml:/config/config.yaml"
65+
- "./config/dev/secrets.yaml:/config/secrets.yaml"
66+
labels:
67+
- "traefik.enable=true"
68+
- "traefik.http.routers.admin.rule=Host(`localhost`)"
69+
- "traefik.http.routers.admin.rule=PathPrefix(`/admin`)"
70+
- "traefik.http.routers.admin.entrypoints=http"
71+
- "traefik.http.services.admin.loadbalancer.server.port=8081"
72+
network_mode: bridge
73+
5674
frontend:
5775
build:
5876
context: ./website

go/admin/admin.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,9 @@ package admin
2121
import (
2222
"errors"
2323
"net/http"
24-
"path/filepath"
25-
"runtime"
2624
"time"
2725

2826
"github.com/gin-contrib/cors"
29-
"github.com/gin-contrib/sessions"
30-
"github.com/gin-contrib/sessions/cookie"
3127
"github.com/gin-gonic/gin"
3228
"github.com/spf13/cobra"
3329
"github.com/spf13/viper"
@@ -51,7 +47,7 @@ type Admin struct {
5147

5248
ghAppId string
5349
ghAppSecret string
54-
auth string
50+
auth string
5551

5652
dbCfg *psdb.Config
5753
dbClient *psdb.Client
@@ -113,18 +109,12 @@ func (a *Admin) Run() error {
113109
return errors.New(server.ErrorIncorrectConfiguration)
114110
}
115111

116-
_, b, _, _ := runtime.Caller(0)
117-
basepath := filepath.Dir(b)
118-
119112
a.Mode.SetGin()
120113
a.router = gin.Default()
121114

122-
store := cookie.NewStore([]byte("secret"))
123-
a.router.Use(sessions.Sessions("admin-session", store))
124-
125-
a.router.Static("/assets", filepath.Join(basepath, "assets"))
115+
a.router.Static("/admin/assets", "/go/admin/assets")
126116

127-
a.router.LoadHTMLGlob(filepath.Join(basepath, "templates/*"))
117+
a.router.LoadHTMLGlob("/go/admin/templates/*")
128118

129119
a.router.Use(cors.New(cors.Config{
130120
AllowOrigins: []string{"*"},

go/admin/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var (
3939
oauthConf = &oauth2.Config{
4040
Scopes: []string{"read:org"}, // Request access to read organization membership
4141
Endpoint: github.Endpoint,
42-
RedirectURL: "http://localhost:8081/admin/auth/callback",
42+
RedirectURL: "http://localhost/admin/auth/callback",
4343
}
4444
oauthStateString = random.String(10) // A random string to protect against CSRF attacks
4545
client *goGithub.Client
@@ -258,7 +258,7 @@ func (a *Admin) handleExecutionsAdd(c *gin.Context) {
258258
return
259259
}
260260

261-
serverAPIURL := "http://localhost:8080/api/executions/add"
261+
serverAPIURL := "http://localhost/api/executions/add"
262262

263263
if a.Mode == server.ProductionMode {
264264
serverAPIURL = "https://benchmark.vitess.io/api/executions/add"

go/admin/templates/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>Arewefastyet Admin</title>
7-
<link rel="icon" type="image/png" href="/assets/favicon.ico" />
7+
<link rel="icon" type="image/png" href="/admin/assets/favicon.ico" />
88
<link
99
href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"
1010
rel="stylesheet"

go/admin/templates/header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
>
44
<a href="/admin/dashboard" class="cursor-pointer flex flex-1 gap-x-2 items-center">
55
<img
6-
src="/assets/logo.png"
6+
src="/admin/assets/logo.png"
77
alt="Logo"
88
class="w-8"
99
/>

go/admin/templates/login.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
<body class="flex flex-col items-center justify-center h-screen bg-white">
1414
<div class="flex flex-row">
15-
<img src="/assets/logo.png" class="h-12" alt="logo" />
15+
<img src="/admin/assets/logo.png" class="h-12" alt="logo" />
1616
<h1 class="text-3xl font-bold mb-2">arewefastyet</h1>
1717
</div>
1818
<h2 class="text-5xl font-semibold text-orange-500 mb-8">Admin Login</h2>
19-
<img src="/assets/github-icon.png" alt="GitHub Icon" class="w-32 h-32" />
19+
<img src="/admin/assets/github-icon.png" alt="GitHub Icon" class="w-32 h-32" />
2020
<button
2121
class="bg-black text-white flex items-center justify-center gap-2 px-4 py-2 rounded-md hover:bg-gray-800 transition mx-auto"
2222
>

0 commit comments

Comments
 (0)