Skip to content

Commit

Permalink
[dev] s6 dependency stuff works
Browse files Browse the repository at this point in the history
  • Loading branch information
spezifisch committed Aug 11, 2023
1 parent f499811 commit fcfd777
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 4 deletions.
22 changes: 20 additions & 2 deletions backend/cmd/api/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"os"

"github.com/apex/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -20,10 +22,26 @@ func main() {
Short: "HTTP API",
Long: `Rueder HTTP API.`,
Run: func(cmd *cobra.Command, args []string) {
isDevelopmentMode := viper.GetBool("dev")

// s6 readiness notification in dev mode
// see: https://skarnet.org/software/s6/notifywhenup.html
if isDevelopmentMode {
file := os.NewFile(3, "s6ready") // hardcoded fd 3, arbitrary name
_, err := file.Write([]byte("\n"))
if err != nil {
log.WithError(err).Info("s6ready not writable (ok on reloads)")
} else {
err = file.Close()
if err != nil {
log.WithError(err).Info("s6ready not closable")
}
}
}

db := common.RequireString("db")
log.Infof("using pop db \"%s\"", db)
log.Infof("api: using pop db \"%s\"", db)

isDevelopmentMode := viper.GetBool("dev")
jwtSecretKey := common.RequireString("jwt")
if !isDevelopmentMode {
if jwtSecretKey == "secret" || len(jwtSecretKey) < 32 {
Expand Down
6 changes: 6 additions & 0 deletions backend/cmd/worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ func main() {
panic(err)
}

cmd.PersistentFlags().Bool("dev", false, "development mode")
err = viper.BindPFlag("dev", cmd.PersistentFlags().Lookup("dev"))
if err != nil {
panic(err)
}

err = cmd.Execute()
if err != nil {
log.WithError(err).Error("command failed")
Expand Down
2 changes: 2 additions & 0 deletions backend/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ services:
- "127.0.0.1:8083:8080" # events
volumes:
- ./:/app/
- rueder_dev_cache:/cache
depends_on:
- db

Expand Down Expand Up @@ -52,3 +53,4 @@ services:
volumes:
rueder_dev_db:
rueder_dev_rabbitmq_data:
rueder_dev_cache:
12 changes: 10 additions & 2 deletions backend/docker/dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
FROM golang:1.19.12-alpine3.18
FROM golang:1.21.0-alpine3.18
ARG S6_OVERLAY_VERSION=3.1.5.0

# set default timezone
ARG TZ=Europe/Berlin
ENV DEFAULT_TZ ${TZ}
# go config
ENV CGO_ENABLED=1
# s6-overlay config
ENV GOMODCACHE=/cache
## s6-overlay config
# GOPATH etc must be kept
ENV S6_KEEP_ENV=1
# api cmd reports its own readiness
ENV S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0

WORKDIR /app

Expand Down Expand Up @@ -37,5 +41,9 @@ RUN go mod download
# s6 daemon configs
COPY ./docker/dev/s6-rc.d /etc/s6-overlay/s6-rc.d

# gomodcache
VOLUME /cache

# app code
VOLUME /app
EXPOSE 8080
Empty file.
1 change: 1 addition & 0 deletions backend/docker/dev/s6-rc.d/api/notification-fd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
Empty file.
Empty file.
Empty file.
Empty file.

0 comments on commit fcfd777

Please sign in to comment.