Start changing structure

This commit is contained in:
Glenn Y. Rolland 2020-04-10 23:41:50 +02:00
parent 10222738a8
commit a6aaed1fcd
8 changed files with 98 additions and 72 deletions

View file

@ -1,9 +1,14 @@
require "yaml"
require "./config/config"
require "./config/local"
require "./config/remote"
require "./config/deployment"
class Config
YAML.mapping(
version: String,
locals: Array(LocalConfig),
remotes: Array(RemoteConfig),
deployments: Array(DeploymentConfig)
)
end

View file

@ -1,14 +0,0 @@
require "yaml"
require "./local"
require "./remote"
require "./deployment"
class Config
YAML.mapping(
version: String,
locals: Array(LocalConfig),
remotes: Array(RemoteConfig),
deployments: Array(DeploymentConfig)
)
end

View file

@ -1,37 +1,37 @@
require "yaml"
class DokkuMariadbConfig
class DokkuMariadbDeploymentConfigSettings
YAML.mapping(
name: String,
options: YAML::Any | Nil
)
end
class DokkuAppConfig
class DokkuAppDeploymentConfigSettings
YAML.mapping(
name: String,
options: YAML::Any | Nil
)
end
class DeploymentMariadbConfig
class DokkuMariadbDeploymentConfig
YAML.mapping(
local: String,
remote: String,
dokku_mariadb: DokkuMariadbConfig,
dokku_mariadb: DokkuMariadbDeploymentConfigSettings,
)
end
class DeploymentAppConfig
class DokkuAppDeploymentConfig
YAML.mapping(
local: String,
remote: String,
dokku_app: DokkuAppConfig,
dokku_app: DokkuAppDeploymentConfigSettings,
)
end
alias DeploymentConfig =
DeploymentMariadbConfig |
DeploymentAppConfig
DokkuMariadbDeploymentConfig |
DokkuAppDeploymentConfig

View file

@ -1,32 +1,47 @@
require "yaml"
enum LocalType
DOCKER_IMAGE = 1
MYSQL_DUMP = 2
def to_yaml(io)
to_s(io)
end
end
class LocalFileConfig
class ScriptLocalConfigSettings
YAML.mapping(
name: String,
type: LocalType, # enum ?
path: String
)
end
class LocalDockerConfig
class MysqlDumpLocalConfigSettings
YAML.mapping(
path: String
)
end
class DockerImageLocalConfigSettings
YAML.mapping(
name: String
)
end
class ScriptLocalConfig
YAML.mapping(
name: String,
type: LocalType, # enum ?
docker_image: String
script: ScriptLocalConfigSettings
)
end
class MysqlDumpLocalConfig
YAML.mapping(
name: String,
mysql_dump: MysqlDumpLocalConfigSettings
)
end
class DockerImageLocalConfig
YAML.mapping(
name: String,
docker_image: DockerImageLocalConfigSettings
)
end
alias LocalConfig =
LocalFileConfig |
LocalDockerConfig
DockerImageLocalConfig |
MysqlDumpLocalConfig |
ScriptLocalConfig

View file

@ -1,11 +1,19 @@
require "yaml"
class RemoteConfig
class DokkuRemoteConfigSettings
YAML.mapping(
name: String,
user: String,
host: String
)
end
class DokkuRemoteConfig
YAML.mapping(
name: String,
dokku: DokkuRemoteConfigSettings
)
end
alias RemoteConfig =
DokkuRemoteConfig

View file

@ -1,8 +1,8 @@
require "colorize"
class DeploymentApp
def initialize(@local : LocalDockerConfig, @remote : RemoteConfig, @deployment : DeploymentAppConfig)
class DockerImageToDokkuAppDeployment
def initialize(@local : DockerImageLocalConfig, @remote : RemoteConfig, @deployment : DokkuAppDeploymentConfig)
end
def run

View file

@ -1,5 +1,5 @@
class DeploymentMariadb
class MysqlDumpToDokkuMariadbDeployment
def initialize(@local : LocalFileConfig, @remote : RemoteConfig, @deployment : DeploymentMariadbConfig)
end

View file

@ -75,6 +75,42 @@ module Pushokku
end
def self.handle_deployment(config : Config, deployment_config : DeploymentConfig)
local = config.locals.select { |l| l.name == deployment_config.local }.first
remote = config.remotes.select { |r| r.name == deployment_config.remote }.first
if local.nil?
puts "Unknown local #{deployment_config.local}. Exiting."
exit 2
end
if remote.nil?
puts "Unknown remote #{deployment_config.remote}. Exiting."
exit 2
end
deployment =
case deployment_config
when DokkuAppDeploymentConfig then
DockerImageToDokkuAppDeployment.new(
local.as(DockerImageLocalConfig),
remote,
deployment_config.as(DokkuAppDeploymentConfig)
)
when MysqlDumpToDokkuMariadbDeployment then
DeploymentMariadb.new(
local.as(MysqlDumpLocalConfig),
remote,
deployment_config.as(DokkuMariadbDeploymentConfig)
)
when Nil
nil
end
next if deployment.nil?
deployment.run
end
def self.run(args)
app = Cli.new
opts = app.parse_options(args)
@ -82,31 +118,7 @@ module Pushokku
# env_config = App.get_config(config, opts["environment"])
config.deployments.each do |deployment_config|
local = config.locals.select { |l| l.name == deployment_config.local }.first
remote = config.remotes.select { |r| r.name == deployment_config.remote }.first
if local.nil?
puts "Unknown local #{deployment_config.local}. Exiting."
exit 2
end
if remote.nil?
puts "Unknown remote #{deployment_config.remote}. Exiting."
exit 2
end
deployment =
case deployment_config
when DeploymentAppConfig then
DeploymentApp.new(local.as(LocalDockerConfig), remote, deployment_config.as(DeploymentAppConfig))
when DeploymentMariadbConfig then
DeploymentMariadb.new(local.as(LocalFileConfig), remote, deployment_config.as(DeploymentMariadbConfig))
when Nil
nil
end
next if deployment.nil?
deployment.run
handle_deployment(config, deployment_config)
end
exit 2