mirror of
https://github.com/skidoodle/spotify-ws
synced 2026-04-28 19:27:39 +02:00
fix the fucky wucky
This commit is contained in:
+4
-2
@@ -1,15 +1,17 @@
|
|||||||
FROM golang:1.22.4 AS builder
|
FROM golang:1.24 AS builder
|
||||||
ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64
|
ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN go build -ldflags="-s -w" -o spotify-ws .
|
RUN go build -ldflags="-s -w" -o spotify-ws .
|
||||||
|
RUN go build -ldflags="-s -w" -o healthcheck healthcheck.go
|
||||||
|
|
||||||
FROM gcr.io/distroless/static:nonroot
|
FROM gcr.io/distroless/static:nonroot
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=builder --chown=nonroot:nonroot /app/spotify-ws .
|
COPY --from=builder --chown=nonroot:nonroot /app/spotify-ws .
|
||||||
|
COPY --from=builder --chown=nonroot:nonroot /app/healthcheck .
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s CMD curl --fail http://localhost:3000/health || exit 1
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s CMD ["./healthcheck"]
|
||||||
USER nonroot:nonroot
|
USER nonroot:nonroot
|
||||||
CMD ["./spotify-ws"]
|
CMD ["./spotify-ws"]
|
||||||
|
|||||||
@@ -12,9 +12,3 @@ services:
|
|||||||
#- LOG_LEVEL=DEBUG
|
#- LOG_LEVEL=DEBUG
|
||||||
# ALLOWED_ORIGINS=http://localhost:3000
|
# ALLOWED_ORIGINS=http://localhost:3000
|
||||||
# SERVER_PORT=3000
|
# SERVER_PORT=3000
|
||||||
healthcheck:
|
|
||||||
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
|
|
||||||
interval: 30s
|
|
||||||
timeout: 5s
|
|
||||||
retries: 3
|
|
||||||
start_period: 5s
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
module spotify-ws
|
module skidoodle/spotify-ws
|
||||||
|
|
||||||
go 1.22.4
|
go 1.24.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gorilla/websocket v1.5.3
|
github.com/gorilla/websocket v1.5.3
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module healthcheck
|
||||||
|
|
||||||
|
go 1.24.0
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
resp, err := http.Get("http://localhost:3000/health")
|
||||||
|
if err != nil || resp.StatusCode != 200 {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
@@ -159,6 +159,8 @@ func initializeSpotifyClient() {
|
|||||||
|
|
||||||
tokenSource = oauthConfig.TokenSource(context.Background(), token)
|
tokenSource = oauthConfig.TokenSource(context.Background(), token)
|
||||||
spotifyClient = spotify.NewClient(oauth2.NewClient(context.Background(), tokenSource))
|
spotifyClient = spotify.NewClient(oauth2.NewClient(context.Background(), tokenSource))
|
||||||
|
|
||||||
|
logrus.Info("Spotify client initialized successfully")
|
||||||
}
|
}
|
||||||
|
|
||||||
func startServer(server *http.Server, _ context.Context) {
|
func startServer(server *http.Server, _ context.Context) {
|
||||||
@@ -269,11 +271,14 @@ func sendInitialState(client *websocket.Conn) {
|
|||||||
lastState.RLock()
|
lastState.RLock()
|
||||||
defer lastState.RUnlock()
|
defer lastState.RUnlock()
|
||||||
|
|
||||||
if lastState.track != nil {
|
if lastState.track == nil {
|
||||||
if err := client.WriteJSON(lastState.track); err != nil {
|
logrus.Debug("No initial state available to send")
|
||||||
logrus.Errorf("Failed to send initial state: %v", err)
|
return
|
||||||
client.Close()
|
}
|
||||||
}
|
|
||||||
|
if err := client.WriteJSON(lastState.track); err != nil {
|
||||||
|
logrus.Errorf("Failed to send initial state: %v", err)
|
||||||
|
client.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,6 +328,8 @@ func fetchAndBroadcastState() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logrus.Debugf("Fetched playback state: %+v", current)
|
||||||
|
|
||||||
updateState(current)
|
updateState(current)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,10 +338,16 @@ func updateState(current *spotify.CurrentlyPlaying) {
|
|||||||
defer lastState.Unlock()
|
defer lastState.Unlock()
|
||||||
|
|
||||||
if current == nil {
|
if current == nil {
|
||||||
|
logrus.Warn("Received nil playback state from Spotify")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
stateChanged := lastState.track == nil ||
|
if lastState.track == nil {
|
||||||
|
lastState.track = &spotify.CurrentlyPlaying{}
|
||||||
|
}
|
||||||
|
|
||||||
|
stateChanged := lastState.track.Item == nil ||
|
||||||
|
current.Item == nil ||
|
||||||
lastState.track.Item.ID != current.Item.ID ||
|
lastState.track.Item.ID != current.Item.ID ||
|
||||||
lastState.playing != current.Playing
|
lastState.playing != current.Playing
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ services:
|
|||||||
- REFRESH_TOKEN=${REFRESH_TOKEN}
|
- REFRESH_TOKEN=${REFRESH_TOKEN}
|
||||||
- CLIENT_SECRET=${CLIENT_SECRET}
|
- CLIENT_SECRET=${CLIENT_SECRET}
|
||||||
- CLIENT_ID=${CLIENT_ID}
|
- CLIENT_ID=${CLIENT_ID}
|
||||||
#- LOG_LEVEL=DEBUG
|
#- LOG_LEVEL=DEBUG|WARN|ERROR
|
||||||
#- ALLOWED_ORIGINS=http://localhost:3000
|
#- ALLOWED_ORIGINS=http://localhost:3000
|
||||||
#- SERVER_PORT=3000
|
#- SERVER_PORT=3000
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user