diff --git a/README.md b/README.md index 2da8aaa..46d671d 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,10 @@ via traefik. ## How it Works It works by acting as the fallback-route for the containers. For instance, if you have -`example.com` as a container you want to lazy-load, you would add the container, as well -as this lazyloader that would act as a lower-priority router for the same domain. If the +`example.com` as a container you want to lazy-load, you add the container, as well +as this lazyloader that would act as a lower-priority router for the same route. If the host is accessed, the lazyloader will work to boot up the container and redirect the user -as soon as it's up. +as soon as it's responsive. It then monitors the container's network interface. If the network is idle for X minutes, it will stop the container. @@ -21,7 +21,7 @@ will stop the container. version: '3.5' services: - # Example traefik proxy + # Example traefik proxy (Don't need if you already have something set up!) reverse-proxy: image: traefik:v2.4 command: @@ -73,7 +73,7 @@ You can run `docker-compose up` on the above for a quick-start. You will need to ## Config -Configuration uses [viper]() and can be specified by either overwriting the `config.yaml` file or +Configuration uses [viper](https://github.com/spf13/viper) and can be specified by either overwriting the `config.yaml` file or via environment variables with the `TLL_` prefix (Traefik lazy loader) ```yaml @@ -103,6 +103,8 @@ labelprefix: lazyloader ## Labels +Use these on containers you want to be lazy-loaded. + * `lazyloader=true` -- (Required) Add to containers that should be managed * `lazyloader.stopdelay=5m` -- Amount of time to wait for idle network traffick before stopping a container * `lazyloader.waitforcode=200` -- Waits for this HTTP result from downstream before redirecting user. Can be comma-separated list @@ -118,4 +120,17 @@ labelprefix: lazyloader # License -GPLv3 +Copyright (C) 2023 Christopher LaPointe + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . diff --git a/go.mod b/go.mod index 60f89b8..1ca042b 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( require ( github.com/Microsoft/go-winio v0.6.1 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/docker/distribution v2.8.2+incompatible // indirect github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.5.0 // indirect @@ -24,10 +25,12 @@ require ( github.com/opencontainers/image-spec v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.0.6 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/spf13/afero v1.9.3 // indirect github.com/spf13/cast v1.5.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect + github.com/stretchr/testify v1.8.4 // indirect github.com/subosito/gotenv v1.4.2 // indirect golang.org/x/mod v0.8.0 // indirect golang.org/x/net v0.6.0 // indirect diff --git a/go.sum b/go.sum index 2c177a9..7aefbf6 100644 --- a/go.sum +++ b/go.sum @@ -191,6 +191,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/main.go b/main.go index 220afc0..ae317a0 100644 --- a/main.go +++ b/main.go @@ -33,6 +33,8 @@ func mustCreateDockerClient() *client.Client { } func main() { + config.Load() + if config.Model.Verbose { logrus.SetLevel(logrus.DebugLevel) logrus.Debug("Verbose is on") diff --git a/pkg/config/config.go b/pkg/config/config.go index 679ac8c..7efa676 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -28,7 +28,7 @@ type ConfigModel struct { var Model *ConfigModel = new(ConfigModel) -func init() { +func Load() { viper.AddConfigPath(".") viper.SetConfigName("config") viper.SetConfigType("yaml") diff --git a/pkg/containers/util_test.go b/pkg/containers/util_test.go new file mode 100644 index 0000000..2a4fc73 --- /dev/null +++ b/pkg/containers/util_test.go @@ -0,0 +1,12 @@ +package containers + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestSliceContainers(t *testing.T) { + assert.True(t, strSliceContains([]string{"hello", "thar"}, "thar")) + assert.False(t, strSliceContains([]string{"hello", "thar"}, "th")) +}