Compare commits
4 commits
b18d481f03
...
59547ebe38
Author | SHA1 | Date | |
---|---|---|---|
59547ebe38 | |||
6083faf427 | |||
ccb417ad6a | |||
7b1150c00b |
3 changed files with 131 additions and 28 deletions
88
.woodpecker.yml
Normal file
88
.woodpecker.yml
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
---
|
||||||
|
# Test building the code and docker image
|
||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: test-build
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: go-test
|
||||||
|
image: golang
|
||||||
|
commands:
|
||||||
|
- make -C polyculeconnect test
|
||||||
|
depends_on:
|
||||||
|
|
||||||
|
- name: go-build
|
||||||
|
image: golang
|
||||||
|
commands:
|
||||||
|
- make -C polyculeconnect build
|
||||||
|
depends_on:
|
||||||
|
|
||||||
|
- name: docker-build-only
|
||||||
|
image: thegeeklab/drone-docker-buildx
|
||||||
|
privileged: true
|
||||||
|
settings:
|
||||||
|
repo: git.faercol.me/polyculeconnect/polyculeconnect
|
||||||
|
tags: latest
|
||||||
|
dry_run: true
|
||||||
|
platforms:
|
||||||
|
- linux/amd64
|
||||||
|
# - linux/arm64
|
||||||
|
depends_on:
|
||||||
|
when:
|
||||||
|
branch:
|
||||||
|
exclude:
|
||||||
|
- main
|
||||||
|
|
||||||
|
- name: docker-build-push
|
||||||
|
image: thegeeklab/drone-docker-buildx
|
||||||
|
privileged: true
|
||||||
|
settings:
|
||||||
|
repo: git.faercol.me/polyculeconnect/polyculeconnect
|
||||||
|
registry: git.faercol.me
|
||||||
|
tags: latest
|
||||||
|
username:
|
||||||
|
from_secret: GIT_USERNAME
|
||||||
|
password:
|
||||||
|
from_secret: GIT_PASSWORD
|
||||||
|
platforms:
|
||||||
|
- linux/amd64
|
||||||
|
# - linux/arm64
|
||||||
|
depends_on:
|
||||||
|
- go-test
|
||||||
|
- go-build
|
||||||
|
when:
|
||||||
|
branch:
|
||||||
|
- main
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
event:
|
||||||
|
- push
|
||||||
|
- tag
|
||||||
|
|
||||||
|
---
|
||||||
|
# On a tag, only build the related docker image
|
||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: tag-release
|
||||||
|
depends_on:
|
||||||
|
- test-build
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: docker-push-tag
|
||||||
|
image: thegeeklab/drone-docker-buildx
|
||||||
|
privileged: true
|
||||||
|
settings:
|
||||||
|
registry: git.faercol.me
|
||||||
|
repo: git.faercol.me/polyculeconnect/polyculeconnect
|
||||||
|
auto_tag: true
|
||||||
|
platforms:
|
||||||
|
- linux/amd64
|
||||||
|
# - linux/arm64
|
||||||
|
username:
|
||||||
|
from_secret: GIT_USERNAME
|
||||||
|
password:
|
||||||
|
from_secret: GIT_PASSWORD
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
event:
|
||||||
|
- tag
|
|
@ -40,12 +40,19 @@ const (
|
||||||
ModeNet
|
ModeNet
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type BackendConfigType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
Memory BackendConfigType = "memory"
|
||||||
|
SQLite BackendConfigType = "sqlite"
|
||||||
|
)
|
||||||
|
|
||||||
type BackendConfig struct {
|
type BackendConfig struct {
|
||||||
Config *oidc.Config `json:"config"`
|
Config *oidc.Config `json:"config"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
ID string `json:"ID"`
|
ID string `json:"ID"`
|
||||||
Type string `json:"type"`
|
Type BackendConfigType `json:"type"`
|
||||||
Local bool `json:"local"`
|
Local bool `json:"local"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OpenConnectConfig struct {
|
type OpenConnectConfig struct {
|
||||||
|
@ -54,7 +61,7 @@ type OpenConnectConfig struct {
|
||||||
Issuer string `json:"issuer"`
|
Issuer string `json:"issuer"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type StorageConfigConfig struct {
|
type StorageConfig struct {
|
||||||
File string `json:"file"`
|
File string `json:"file"`
|
||||||
Host string `json:"host"`
|
Host string `json:"host"`
|
||||||
Port int `json:"port"`
|
Port int `json:"port"`
|
||||||
|
@ -78,8 +85,8 @@ type jsonConf struct {
|
||||||
SockPath string `json:"sock"`
|
SockPath string `json:"sock"`
|
||||||
} `json:"server"`
|
} `json:"server"`
|
||||||
Storage struct {
|
Storage struct {
|
||||||
StorageType string `json:"type"`
|
StorageType string `json:"type"`
|
||||||
StorageConfig *StorageConfigConfig `json:"config"`
|
Config *StorageConfig `json:"config"`
|
||||||
} `json:"storage"`
|
} `json:"storage"`
|
||||||
OpenConnectConfig *OpenConnectConfig `json:"openconnect"`
|
OpenConnectConfig *OpenConnectConfig `json:"openconnect"`
|
||||||
}
|
}
|
||||||
|
@ -91,7 +98,7 @@ type AppConfig struct {
|
||||||
Port int
|
Port int
|
||||||
SockPath string
|
SockPath string
|
||||||
StorageType string
|
StorageType string
|
||||||
StorageConfig *StorageConfigConfig
|
StorageConfig *StorageConfig
|
||||||
OpenConnectConfig *OpenConnectConfig
|
OpenConnectConfig *OpenConnectConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +129,7 @@ func (ac *AppConfig) UnmarshalJSON(data []byte) error {
|
||||||
ac.Port = jsonConf.Server.Port
|
ac.Port = jsonConf.Server.Port
|
||||||
ac.OpenConnectConfig = jsonConf.OpenConnectConfig
|
ac.OpenConnectConfig = jsonConf.OpenConnectConfig
|
||||||
ac.StorageType = jsonConf.Storage.StorageType
|
ac.StorageType = jsonConf.Storage.StorageType
|
||||||
ac.StorageConfig = jsonConf.Storage.StorageConfig
|
ac.StorageConfig = jsonConf.Storage.Config
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"time"
|
"time"
|
||||||
|
@ -35,6 +36,26 @@ func parseArgs() *cliArgs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initStorage(conf *config.AppConfig) (storage.Storage, error) {
|
||||||
|
var storageType storage.Storage
|
||||||
|
var err error
|
||||||
|
switch conf.StorageType {
|
||||||
|
case "memory":
|
||||||
|
storageType = memory.New(logger.L)
|
||||||
|
case "sqlite":
|
||||||
|
sqlconfig := sql.SQLite3{
|
||||||
|
File: conf.StorageConfig.File,
|
||||||
|
}
|
||||||
|
storageType, err = sqlconfig.Open(logger.L)
|
||||||
|
if err != nil {
|
||||||
|
logger.L.Fatalf("Failed to initialize sqlite backend: %s", err.Error())
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return storageType, fmt.Errorf("unsupported storage backend type: %s", conf.StorageType)
|
||||||
|
}
|
||||||
|
return storageType, nil
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
args := parseArgs()
|
args := parseArgs()
|
||||||
|
|
||||||
|
@ -48,24 +69,11 @@ func main() {
|
||||||
logger.Init(conf.LogLevel)
|
logger.Init(conf.LogLevel)
|
||||||
logger.L.Infof("Initialized logger with level %v", conf.LogLevel)
|
logger.L.Infof("Initialized logger with level %v", conf.LogLevel)
|
||||||
|
|
||||||
var storageType storage.Storage
|
storageType, err := initStorage(conf)
|
||||||
switch conf.StorageType {
|
if err != nil {
|
||||||
case "memory":
|
logger.L.Fatalf("Failed to initialize storage backend: %s", err.Error())
|
||||||
storageType = memory.New(logger.L)
|
|
||||||
case "sqlite":
|
|
||||||
sqlconfig := sql.SQLite3{
|
|
||||||
File: conf.StorageConfig.File,
|
|
||||||
}
|
|
||||||
storageType, err = sqlconfig.Open(logger.L)
|
|
||||||
if err != nil {
|
|
||||||
logger.L.Fatalf("Failed to initialize sqlite backend: %s", err.Error())
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
logger.L.Fatalf("Unsupported storage backend type: %s", conf.StorageType)
|
|
||||||
}
|
}
|
||||||
|
logger.L.Infof("Initialized storage backend %q", conf.StorageType)
|
||||||
logger.L.Infof("Initialized storage backend \"%s\"", conf.StorageType)
|
|
||||||
|
|
||||||
dexConf := dex_server.Config{
|
dexConf := dex_server.Config{
|
||||||
Web: dex_server.WebConfig{
|
Web: dex_server.WebConfig{
|
||||||
Dir: "./",
|
Dir: "./",
|
||||||
|
@ -101,7 +109,7 @@ func main() {
|
||||||
if err := dexConf.Storage.CreateConnector(storage.Connector{
|
if err := dexConf.Storage.CreateConnector(storage.Connector{
|
||||||
ID: backend.ID,
|
ID: backend.ID,
|
||||||
Name: backend.Name,
|
Name: backend.Name,
|
||||||
Type: backend.Type,
|
Type: string(backend.Type),
|
||||||
Config: backendConfJson,
|
Config: backendConfJson,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
logger.L.Errorf("Failed to add connector for backend %q to stage: %s", backend.Name, err.Error())
|
logger.L.Errorf("Failed to add connector for backend %q to stage: %s", backend.Name, err.Error())
|
||||||
|
|
Loading…
Reference in a new issue