Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/go_modules/google.golang.org/pr…
Browse files Browse the repository at this point in the history
…otobuf-1.33.0
  • Loading branch information
CommanderStorm authored Apr 9, 2024
2 parents d1b7b72 + a655e15 commit 0ef0fd7
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 6 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21.5-alpine3.17 as builder
FROM golang:1.22-alpine3.19 as builder

# Ca-certificates are required to call HTTPS endpoints.
RUN apk update && apk add --no-cache ca-certificates tzdata alpine-sdk bash && update-ca-certificates
Expand All @@ -18,12 +18,15 @@ COPY internal internal
ARG version=dev
# Compile statically
RUN CGO_ENABLED=0 go build -ldflags "-w -extldflags '-static' -X internal/app.Version=${version}" -o /proxy cmd/proxy/proxy.go
RUN CGO_ENABLED=0 go build -ldflags "-w -extldflags '-static'" -o /healthcheck cmd/healthcheck/healthcheck.go

FROM scratch

COPY --from=builder /proxy /proxy
COPY --from=builder /healthcheck /healthcheck
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

EXPOSE 4321
HEALTHCHECK --interval=1s --timeout=1s --start-period=2s --retries=3 CMD [ "/healthcheck" ]

CMD ["/proxy"]
15 changes: 15 additions & 0 deletions cmd/healthcheck/healthcheck.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import (
"log"
"net/http"
"os"
)

func main() {
_, err := http.Get("http://127.0.0.1:4321/health")
if err != nil {
log.Printf("Healthcheck failed: %s\n", err)
os.Exit(1)
}
}
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ version: "3.8"
services:
calendarproxy:
image: ghcr.io/tum-dev/calendarproxy/server:latest
restart: unless-stopped
labels:
- "traefik.enable=true"
- "traefik.http.routers.calendarproxy.entrypoints=web"
Expand Down
15 changes: 14 additions & 1 deletion internal/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,20 @@ func (a *App) Run() error {
gin.SetMode("release")
a.engine = gin.New()
a.engine.Use(sentrygin.New(sentrygin.Options{}))
a.engine.Use(gin.Logger(), gin.Recovery())
logger := gin.LoggerWithConfig(gin.LoggerConfig{SkipPaths: []string{"/health"}})
a.engine.Use(logger, gin.Recovery())
a.configRoutes()

// Start the engines
return a.engine.Run(":4321")
}

func (a *App) configRoutes() {
a.engine.GET("/health", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"status": "ok",
})
})
a.engine.Any("/", a.handleIcal)
f := http.FS(static)
a.engine.StaticFS("/files/", f)
Expand Down Expand Up @@ -218,6 +224,9 @@ var unneeded = []string{

var reRoom = regexp.MustCompile("^(.*?),.*(\\d{4})\\.(?:\\d\\d|EG|UG|DG|Z\\d|U\\d)\\.\\d+")

// matches strings like: (5612.03.017), (5612.EG.017), (5612.EG.010B)
var reNavigaTUM = regexp.MustCompile("\\(\\d{4}\\.[a-zA-Z0-9]{2}\\.\\d{3}[A-Z]?\\)")

func (a *App) cleanEvent(event *ics.VEvent) {
summary := ""
if s := event.GetProperty(ics.ComponentPropertySummary); s != nil {
Expand Down Expand Up @@ -254,6 +263,10 @@ func (a *App) cleanEvent(event *ics.VEvent) {
description = location + "\n" + description
event.SetLocation(building)
}
if roomID := reNavigaTUM.FindString(location); roomID != "" {
roomID = strings.Trim(roomID, "()")
description = fmt.Sprintf("https://nav.tum.de/room/%s\n%s", roomID, description)
}
}
event.SetDescription(description)

Expand Down
10 changes: 6 additions & 4 deletions internal/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,15 @@ func TestLocationReplacement(t *testing.T) {
return
}
location := calendar.Components[0].(*ics.VEvent).GetProperty(ics.ComponentPropertyLocation).Value
if location != "Boltzmannstr. 15\\, 85748 Garching b. München" {
t.Errorf("MW 1801\\, Ernst-Schmidt-Hörsaal (5508.02.801) should be shortened to Boltzmannstr. 15\\, 85748 Garching b. München but is %s", location)
expectedLocation := "Boltzmannstr. 15\\, 85748 Garching b. München"
if location != expectedLocation {
t.Errorf("Location should be shortened to %s but is %s", expectedLocation, location)
return
}
desc := calendar.Components[0].(*ics.VEvent).GetProperty(ics.ComponentPropertyDescription).Value
if desc != "MW 1801\\, Ernst-Schmidt-Hörsaal (5508.02.801)\\nEinführung in die Rechnerarchitektur\\nfix\\; Abhaltung\\;" {
t.Errorf("Description should be MW 1801\\, Ernst-Schmidt-Hörsaal (5508.02.801)\\nEinführung in die Rechnerarchitektur\\nfix\\; Abhaltung\\; but is %s", desc)
expectedDescription := "https://nav.tum.de/room/5508.02.801\\nMW 1801\\, Ernst-Schmidt-Hörsaal (5508.02.801)\\nEinführung in die Rechnerarchitektur\\nfix\\; Abhaltung\\;"
if desc != expectedDescription {
t.Errorf("Description should be %s but is %s", expectedDescription, desc)
return
}
}
5 changes: 5 additions & 0 deletions internal/courses.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@
"Einführung in die Werkstoffe und Fertigungstechnologien von Carbon Composites": "CC",
"Wärmetransportphänomene": "WTP",
"Maschinenzeichnen": "MZ",
"Informatikanwendungen in der Medizin": "CAMP",
"Computer Vision": "CV",
"Natural Language Processing": "NLP",
"Augmented Reality": "AR",
"Erweiterte Realität": "AR",
"- Regeln des technischen Zeichnens (CAMPP)": "",
" der modernen Informationstechnik I ": "dmIT 1",
" der modernen Informationstechnik": "dmIT",
Expand Down

0 comments on commit 0ef0fd7

Please sign in to comment.