mirror of
https://github.com/m1k1o/neko-rooms.git
synced 2026-11-02 22:51:34 -06:00
@@ -21,11 +21,13 @@ on_exit() {
|
||||
docker run --rm -it \
|
||||
--name="neko_rooms_traefik" \
|
||||
-p "${1:-80}:80" \
|
||||
-p "8080:8080" \
|
||||
-v "${PWD}/../:/app" \
|
||||
-e "TZ=${TZ}" \
|
||||
-v "/var/run/docker.sock:/var/run/docker.sock" \
|
||||
--net="${NEKO_ROOMS_TRAEFIK_NETWORK}" \
|
||||
traefik:2.4 \
|
||||
--api.insecure=true \
|
||||
--providers.docker=true \
|
||||
--providers.docker.watch=true \
|
||||
--providers.docker.exposedbydefault=false \
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
# custom labels
|
||||
|
||||
You can add custom lables for every room.
|
||||
|
||||
Example: Expose port 3000 from every room under `3000-(room-name)`:
|
||||
|
||||
```bash
|
||||
-e "NEKO_ROOMS_INSTANCE_LABELS=
|
||||
traefik.http.services.{containerName}-3000-tcp.loadbalancer.server.port=3000
|
||||
traefik.http.routers.{containerName}-3000-tcp.entrypoints={traefikEntrypoint}
|
||||
traefik.http.routers.{containerName}-3000-tcp.rule=PathPrefix(\`/3000-{roomName}\`)
|
||||
traefik.http.middlewares.{containerName}-3000-tcp-prf.stripprefix.prefixes=/3000-{roomName}/
|
||||
traefik.http.routers.{containerName}-3000-tcp.middlewares={containerName}-3000-tcp-prf
|
||||
traefik.http.routers.{containerName}-3000-tcp.service={containerName}-3000-tcp
|
||||
"
|
||||
```
|
||||
@@ -18,6 +18,7 @@ type Room struct {
|
||||
NAT1To1IPs []string
|
||||
NekoImages []string
|
||||
PathPrefix string
|
||||
Labels []string
|
||||
|
||||
StorageEnabled bool
|
||||
StorageInternal string
|
||||
@@ -67,6 +68,11 @@ func (Room) Init(cmd *cobra.Command) error {
|
||||
return err
|
||||
}
|
||||
|
||||
cmd.PersistentFlags().StringSlice("labels", []string{}, "additional labels appended to every room")
|
||||
if err := viper.BindPFlag("labels", cmd.PersistentFlags().Lookup("labels")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Data
|
||||
|
||||
cmd.PersistentFlags().Bool("storage.enabled", true, "whether storage is enabled, where peristent containers data will be stored")
|
||||
@@ -159,6 +165,7 @@ func (s *Room) Set() {
|
||||
s.NAT1To1IPs = viper.GetStringSlice("nat1to1")
|
||||
s.NekoImages = viper.GetStringSlice("neko_images")
|
||||
s.PathPrefix = viper.GetString("path_prefix")
|
||||
s.Labels = viper.GetStringSlice("labels")
|
||||
|
||||
s.StorageEnabled = viper.GetBool("storage.enabled")
|
||||
s.StorageInternal = viper.GetString("storage.internal")
|
||||
|
||||
@@ -177,6 +177,7 @@ func (manager *RoomManagerCtx) Create(settings types.RoomSettings) (string, erro
|
||||
"traefik.http.middlewares." + containerName + "-rdr.redirectregex.replacement": pathPrefix + "/",
|
||||
"traefik.http.middlewares." + containerName + "-prf.stripprefix.prefixes": pathPrefix + "/",
|
||||
"traefik.http.routers." + containerName + ".middlewares": containerName + "-rdr," + containerName + "-prf",
|
||||
"traefik.http.routers." + containerName + ".service": containerName + "-frontend",
|
||||
}
|
||||
|
||||
// optional HTTPS
|
||||
@@ -240,6 +241,24 @@ func (manager *RoomManagerCtx) Create(settings types.RoomSettings) (string, erro
|
||||
labels[k] = v
|
||||
}
|
||||
|
||||
// add custom labels
|
||||
for _, label := range manager.config.Labels {
|
||||
// replace dynamic values in labels
|
||||
label = strings.Replace(label, "{containerName}", containerName, -1)
|
||||
label = strings.Replace(label, "{roomName}", roomName, -1)
|
||||
label = strings.Replace(label, "{traefikEntrypoint}", manager.config.TraefikEntrypoint, -1)
|
||||
label = strings.Replace(label, "{traefikCertresolver}", manager.config.TraefikCertresolver, -1)
|
||||
|
||||
v := strings.SplitN(label, "=", 2)
|
||||
if len(v) != 2 {
|
||||
manager.logger.Warn().Str("label", label).Msg("invalid custom label")
|
||||
continue
|
||||
}
|
||||
|
||||
key, val := v[0], v[1]
|
||||
labels[key] = val
|
||||
}
|
||||
|
||||
//
|
||||
// Set environment variables
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user