Skip to content

Commit 2087adf

Browse files
committed
refactor: redefine configuration structure for all Database Lab products (#278)
To standardize configuration file names and store metadata: * redefine configuration structure for all Database Lab products * adjust Docker images of Database Lab Engine and CI Checker * remove old Docker images
1 parent 874e6d5 commit 2087adf

38 files changed

+279
-192
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@
88
/deploy/
99

1010
/configs/config.yml
11+
/configs/server.yml
1112
/configs/run_ci.yaml
13+
/configs/ci_checker.yml
1214
/packer/example.com.key

Dockerfile.ci-checker

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ RUN apk update && apk add --no-cache bash
66
WORKDIR /home/dblab
77

88
COPY ./bin/run-ci ./bin/run-ci
9-
COPY ./configs ./configs
109

1110
CMD ./bin/run-ci

Dockerfile.dblab-server

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,4 @@
1-
# Run with server.yml mount:
2-
# sudo docker run \
3-
# --name dblab_server \
4-
# --label dblab_control \
5-
# --privileged \
6-
# --publish 2345:2345 \
7-
# --restart on-failure \
8-
# --volume /var/run/docker.sock:/var/run/docker.sock \
9-
# --volume /var/lib/dblab:/var/lib/dblab:rshared \
10-
# --volume ~/.dblab/server.yml:/home/dblab/configs/config.yml \
11-
# --env VERIFICATION_TOKEN=secret_token \
12-
# --detach \
13-
# postgresai/dblab-server:latest
14-
#
15-
# or run with envs options:
16-
# sudo docker run \
17-
# --name dblab_server \
18-
# --label dblab_control \
19-
# --privileged \
20-
# --publish 2345:2345 \
21-
# --restart on-failure \
22-
# --volume /var/run/docker.sock:/var/run/docker.sock \
23-
# --volume /var/lib/dblab:/var/lib/dblab:rshared \
24-
# --volume ~/.dblab/server.yml:/home/dblab/configs/config.yml \
25-
# --env VERIFICATION_TOKEN=token \
26-
# --env MOUNT_DIR=/var/lib/dblab/clones \
27-
# --env UNIX_SOCKET_DIR=/var/lib/dblab/sockets \
28-
# --env DOCKER_IMAGE=postgres:13-alpine \
29-
# --detach \
30-
# postgresai/dblab-server:latest
1+
# See Guides to learn how to start a container: https://postgres.ai/docs/how-to-guides/administration/engine-manage
312

323
FROM docker:19.03.14
334

@@ -46,7 +17,7 @@ WORKDIR /home/dblab
4617
COPY ./bin/dblab-server ./bin/dblab-server
4718
COPY ./api ./api
4819
COPY ./web ./web
49-
COPY ./configs ./configs
20+
COPY ./configs/standard ./standard
5021
COPY ./scripts ./scripts
5122

5223
CMD ./bin/dblab-server

Dockerfile.runci

Lines changed: 0 additions & 9 deletions
This file was deleted.

Dockerfile.sync-instance

Lines changed: 0 additions & 29 deletions
This file was deleted.

cmd/cli/commands/config/file.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import (
1313
)
1414

1515
const (
16-
configPath = ".dblab"
16+
dblabDir = ".dblab"
17+
configPath = "cli"
1718
configFilename = "cli.yml"
1819
)
1920

@@ -24,7 +25,7 @@ func GetDirname() (string, error) {
2425
return "", err
2526
}
2627

27-
dirname := path.Join(currentUser.HomeDir, configPath)
28+
dirname := path.Join(currentUser.HomeDir, dblabDir, configPath)
2829

2930
return dirname, nil
3031
}

cmd/database-lab/main.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func main() {
4949

5050
log.Msg("Database Lab Instance ID:", instanceID)
5151

52-
cfg, err := loadConfiguration(instanceID)
52+
cfg, err := config.LoadConfiguration(instanceID)
5353
if err != nil {
5454
log.Fatal(errors.WithMessage(err, "failed to parse config"))
5555
}
@@ -161,23 +161,9 @@ func main() {
161161
shutdownDatabaseLabEngine(shutdownCtx, dockerCLI, cfg.Global, pm.Active().Pool())
162162
}
163163

164-
func loadConfiguration(instanceID string) (*config.Config, error) {
165-
cfg, err := config.LoadConfig("config.yml")
166-
if err != nil {
167-
return nil, errors.Wrap(err, "failed to parse config")
168-
}
169-
170-
log.SetDebug(cfg.Global.Debug)
171-
log.Dbg("Config loaded", cfg)
172-
173-
cfg.Global.InstanceID = instanceID
174-
175-
return cfg, nil
176-
}
177-
178164
func reloadConfig(ctx context.Context, instanceID string, provisionSvc *provision.Provisioner, retrievalSvc *retrieval.Retrieval,
179165
pm *pool.Manager, cloningSvc cloning.Cloning, platformSvc *platform.Service, est *estimator.Estimator, server *srv.Server) error {
180-
cfg, err := loadConfiguration(instanceID)
166+
cfg, err := config.LoadConfiguration(instanceID)
181167
if err != nil {
182168
return err
183169
}

cmd/runci/main.go

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ import (
1010
"github.com/docker/docker/api/types/network"
1111
"github.com/docker/docker/client"
1212
"github.com/pkg/errors"
13-
"gopkg.in/yaml.v2"
1413

1514
"gitlab.com/postgres-ai/database-lab/v2/pkg/client/dblabapi"
1615
"gitlab.com/postgres-ai/database-lab/v2/pkg/log"
1716
"gitlab.com/postgres-ai/database-lab/v2/pkg/retrieval/engine/postgres/tools"
1817
"gitlab.com/postgres-ai/database-lab/v2/pkg/runci"
1918
"gitlab.com/postgres-ai/database-lab/v2/pkg/runci/source"
2019
"gitlab.com/postgres-ai/database-lab/v2/pkg/services/platform"
21-
"gitlab.com/postgres-ai/database-lab/v2/pkg/util"
2220
"gitlab.com/postgres-ai/database-lab/v2/pkg/util/networks"
2321
)
2422

@@ -31,12 +29,15 @@ func main() {
3129
ctx, cancel := context.WithCancel(context.Background())
3230
defer cancel()
3331

34-
cfg, err := loadConfiguration()
32+
cfg, err := runci.LoadConfiguration()
3533
if err != nil {
3634
log.Errf("Failed to load config: %v", err)
3735
return
3836
}
3937

38+
log.SetDebug(cfg.App.Debug)
39+
log.Dbg("Config loaded: ", cfg)
40+
4041
networkID := discoverNetwork(ctx, cfg, dockerCLI)
4142
if networkID != "" {
4243
hostname := os.Getenv("HOSTNAME")
@@ -129,25 +130,3 @@ func discoverNetwork(ctx context.Context, cfg *runci.Config, dockerCLI *client.C
129130

130131
return networkID
131132
}
132-
133-
func loadConfiguration() (*runci.Config, error) {
134-
configPath, err := util.GetConfigPath("run_ci.yaml")
135-
if err != nil {
136-
return nil, errors.Wrap(err, "failed to get config path")
137-
}
138-
139-
b, err := os.ReadFile(configPath)
140-
if err != nil {
141-
return nil, errors.Errorf("error loading %s config file", configPath)
142-
}
143-
144-
cfg := &runci.Config{}
145-
if err := yaml.Unmarshal(b, cfg); err != nil {
146-
return nil, errors.WithMessagef(err, "error parsing %s config", configPath)
147-
}
148-
149-
log.SetDebug(cfg.App.Debug)
150-
log.Dbg("Config loaded: ", cfg)
151-
152-
return cfg, nil
153-
}

configs/config.example.logical_generic.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copy the following to: ~/.dblab/server.yml
1+
# Copy the following to: ~/.dblab/engine/configs/server.yml
22

33
# Database Lab API server. This API is used to work with clones
44
# (list them, create, delete, see how to connect to a clone).

0 commit comments

Comments
 (0)