internal/component => internal/dis/component
This commit is contained in:
parent
9443217441
commit
b5b1ce2340
123 changed files with 76 additions and 76 deletions
10
internal/dis/component/control/control.env
Normal file
10
internal/dis/component/control/control.env
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
HOST_RULE=${HOST_RULE}
|
||||
|
||||
CONFIG_PATH=${CONFIG_PATH}
|
||||
DEPLOY_ROOT=${DEPLOY_ROOT}
|
||||
GLOBAL_AUTHORIZED_KEYS_FILE=${GLOBAL_AUTHORIZED_KEYS_FILE}
|
||||
SELF_OVERRIDES_FILE=${SELF_OVERRIDES_FILE}
|
||||
SELF_RESOLVER_BLOCK_FILE=${SELF_RESOLVER_BLOCK_FILE}
|
||||
|
||||
DOCKER_NETWORK_NAME=${DOCKER_NETWORK_NAME}
|
||||
HTTPS_ENABLED=${HTTPS_ENABLED}
|
||||
54
internal/dis/component/control/control.go
Normal file
54
internal/dis/component/control/control.go
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
package control
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/bootstrap"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
||||
)
|
||||
|
||||
// Control represents the running control server.
|
||||
type Control struct {
|
||||
component.Base
|
||||
|
||||
Servables []component.Servable
|
||||
}
|
||||
|
||||
func (control Control) Path() string {
|
||||
return filepath.Join(control.Still.Config.DeployRoot, "core", "dis")
|
||||
}
|
||||
|
||||
//go:embed all:control control.env
|
||||
var resources embed.FS
|
||||
|
||||
func (control *Control) Stack(env environment.Environment) component.StackWithResources {
|
||||
stt := component.MakeStack(control, env, component.StackWithResources{
|
||||
Resources: resources,
|
||||
ContextPath: "control",
|
||||
EnvPath: "control.env",
|
||||
|
||||
EnvContext: map[string]string{
|
||||
"DOCKER_NETWORK_NAME": control.Config.DockerNetworkName,
|
||||
"HOST_RULE": control.Config.DefaultHostRule(),
|
||||
"HTTPS_ENABLED": control.Config.HTTPSEnabledEnv(),
|
||||
|
||||
"CONFIG_PATH": control.Config.ConfigPath,
|
||||
"DEPLOY_ROOT": control.Config.DeployRoot,
|
||||
|
||||
"GLOBAL_AUTHORIZED_KEYS_FILE": control.Config.GlobalAuthorizedKeysFile,
|
||||
"SELF_OVERRIDES_FILE": control.Config.SelfOverridesFile,
|
||||
"SELF_RESOLVER_BLOCK_FILE": control.Config.SelfResolverBlockFile,
|
||||
},
|
||||
|
||||
CopyContextFiles: []string{bootstrap.Executable},
|
||||
})
|
||||
return stt
|
||||
}
|
||||
|
||||
func (control Control) Context(parent component.InstallationContext) component.InstallationContext {
|
||||
return component.InstallationContext{
|
||||
bootstrap.Executable: control.Config.CurrentExecutable(control.Environment), // TODO: Does this make sense?
|
||||
}
|
||||
}
|
||||
5
internal/dis/component/control/control/Dockerfile
Normal file
5
internal/dis/component/control/control/Dockerfile
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
FROM docker.io/library/docker:20.10-cli
|
||||
|
||||
COPY wdcli /wdcli
|
||||
EXPOSE 8888
|
||||
CMD ["/wdcli","--internal-in-docker","server","--bind","0.0.0.0:8888"]
|
||||
35
internal/dis/component/control/control/docker-compose.yml
Normal file
35
internal/dis/component/control/control/docker-compose.yml
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
version: "3.7"
|
||||
|
||||
services:
|
||||
dis:
|
||||
build: .
|
||||
restart: always
|
||||
environment:
|
||||
CONFIG_PATH: ${CONFIG_PATH}
|
||||
labels:
|
||||
|
||||
- "traefik.enable=True"
|
||||
- "eu.wiss-ki.barrel.distillery=${DOCKER_NETWORK_NAME}"
|
||||
- "traefik.http.routers.control.rule=${HOST_RULE}"
|
||||
|
||||
- "traefik.http.routers.fallback.rule=HostRegexp(`{catchall:.*}`)"
|
||||
- "traefik.http.routers.fallback.priority=1"
|
||||
|
||||
- "traefik.http.routers.control.tls=${HTTPS_ENABLED}"
|
||||
- "traefik.http.routers.control.tls.certresolver=distillery"
|
||||
- "traefik.http.services.control.loadbalancer.server.port=8888"
|
||||
|
||||
|
||||
volumes:
|
||||
# TODO: Mount docker socket properly!
|
||||
- "/var/run/docker.sock:/var/run/docker.sock"
|
||||
- "${CONFIG_PATH}:${CONFIG_PATH}:ro"
|
||||
- "${DEPLOY_ROOT}:${DEPLOY_ROOT}:rw"
|
||||
- "${GLOBAL_AUTHORIZED_KEYS_FILE}:${GLOBAL_AUTHORIZED_KEYS_FILE}:ro"
|
||||
- "${SELF_OVERRIDES_FILE}:${SELF_OVERRIDES_FILE}:ro"
|
||||
- "${SELF_RESOLVER_BLOCK_FILE}:${SELF_RESOLVER_BLOCK_FILE}:ro"
|
||||
|
||||
networks:
|
||||
default:
|
||||
name: ${DOCKER_NETWORK_NAME}
|
||||
external: true
|
||||
30
internal/dis/component/control/server.go
Normal file
30
internal/dis/component/control/server.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package control
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
)
|
||||
|
||||
// Server returns an http.Mux that implements the main server instance.
|
||||
// The server may spawn background tasks, but these should be terminated once context closes.
|
||||
//
|
||||
// Logging messages are directed to io.
|
||||
func (control *Control) Server(context context.Context, io stream.IOStream) (*http.ServeMux, error) {
|
||||
// create a new mux
|
||||
mux := http.NewServeMux()
|
||||
|
||||
// add all the servable routes!
|
||||
for _, s := range control.Servables {
|
||||
for _, route := range s.Routes() {
|
||||
io.Printf("mounting %s\n", route)
|
||||
handler, err := s.Handler(route, context, io)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mux.Handle(route, handler)
|
||||
}
|
||||
}
|
||||
return mux, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue