Start changing structure
This commit is contained in:
parent
10222738a8
commit
a6aaed1fcd
8 changed files with 98 additions and 72 deletions
|
@ -1,9 +1,14 @@
|
||||||
|
|
||||||
require "yaml"
|
require "yaml"
|
||||||
require "./config/config"
|
|
||||||
require "./config/local"
|
require "./config/local"
|
||||||
require "./config/remote"
|
require "./config/remote"
|
||||||
require "./config/deployment"
|
require "./config/deployment"
|
||||||
|
|
||||||
|
class Config
|
||||||
|
YAML.mapping(
|
||||||
|
version: String,
|
||||||
|
locals: Array(LocalConfig),
|
||||||
|
remotes: Array(RemoteConfig),
|
||||||
|
deployments: Array(DeploymentConfig)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
|
@ -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
|
|
|
@ -1,37 +1,37 @@
|
||||||
|
|
||||||
require "yaml"
|
require "yaml"
|
||||||
|
|
||||||
class DokkuMariadbConfig
|
class DokkuMariadbDeploymentConfigSettings
|
||||||
YAML.mapping(
|
YAML.mapping(
|
||||||
name: String,
|
name: String,
|
||||||
options: YAML::Any | Nil
|
options: YAML::Any | Nil
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
class DokkuAppConfig
|
class DokkuAppDeploymentConfigSettings
|
||||||
YAML.mapping(
|
YAML.mapping(
|
||||||
name: String,
|
name: String,
|
||||||
options: YAML::Any | Nil
|
options: YAML::Any | Nil
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
class DeploymentMariadbConfig
|
class DokkuMariadbDeploymentConfig
|
||||||
YAML.mapping(
|
YAML.mapping(
|
||||||
local: String,
|
local: String,
|
||||||
remote: String,
|
remote: String,
|
||||||
dokku_mariadb: DokkuMariadbConfig,
|
dokku_mariadb: DokkuMariadbDeploymentConfigSettings,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
class DeploymentAppConfig
|
class DokkuAppDeploymentConfig
|
||||||
YAML.mapping(
|
YAML.mapping(
|
||||||
local: String,
|
local: String,
|
||||||
remote: String,
|
remote: String,
|
||||||
dokku_app: DokkuAppConfig,
|
dokku_app: DokkuAppDeploymentConfigSettings,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
alias DeploymentConfig =
|
alias DeploymentConfig =
|
||||||
DeploymentMariadbConfig |
|
DokkuMariadbDeploymentConfig |
|
||||||
DeploymentAppConfig
|
DokkuAppDeploymentConfig
|
||||||
|
|
||||||
|
|
|
@ -1,32 +1,47 @@
|
||||||
|
|
||||||
require "yaml"
|
require "yaml"
|
||||||
|
|
||||||
enum LocalType
|
class ScriptLocalConfigSettings
|
||||||
DOCKER_IMAGE = 1
|
|
||||||
MYSQL_DUMP = 2
|
|
||||||
|
|
||||||
def to_yaml(io)
|
|
||||||
to_s(io)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class LocalFileConfig
|
|
||||||
YAML.mapping(
|
YAML.mapping(
|
||||||
name: String,
|
|
||||||
type: LocalType, # enum ?
|
|
||||||
path: String
|
path: String
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
class LocalDockerConfig
|
class MysqlDumpLocalConfigSettings
|
||||||
|
YAML.mapping(
|
||||||
|
path: String
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
class DockerImageLocalConfigSettings
|
||||||
|
YAML.mapping(
|
||||||
|
name: String
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
class ScriptLocalConfig
|
||||||
YAML.mapping(
|
YAML.mapping(
|
||||||
name: String,
|
name: String,
|
||||||
type: LocalType, # enum ?
|
script: ScriptLocalConfigSettings
|
||||||
docker_image: String
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
class MysqlDumpLocalConfig
|
||||||
|
YAML.mapping(
|
||||||
|
name: String,
|
||||||
|
mysql_dump: MysqlDumpLocalConfigSettings
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
class DockerImageLocalConfig
|
||||||
|
YAML.mapping(
|
||||||
|
name: String,
|
||||||
|
docker_image: DockerImageLocalConfigSettings
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
alias LocalConfig =
|
alias LocalConfig =
|
||||||
LocalFileConfig |
|
DockerImageLocalConfig |
|
||||||
LocalDockerConfig
|
MysqlDumpLocalConfig |
|
||||||
|
ScriptLocalConfig
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,19 @@
|
||||||
|
|
||||||
require "yaml"
|
require "yaml"
|
||||||
|
|
||||||
class RemoteConfig
|
class DokkuRemoteConfigSettings
|
||||||
YAML.mapping(
|
YAML.mapping(
|
||||||
name: String,
|
|
||||||
user: String,
|
user: String,
|
||||||
host: String
|
host: String
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class DokkuRemoteConfig
|
||||||
|
YAML.mapping(
|
||||||
|
name: String,
|
||||||
|
dokku: DokkuRemoteConfigSettings
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
alias RemoteConfig =
|
||||||
|
DokkuRemoteConfig
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
|
||||||
require "colorize"
|
require "colorize"
|
||||||
|
|
||||||
class DeploymentApp
|
class DockerImageToDokkuAppDeployment
|
||||||
def initialize(@local : LocalDockerConfig, @remote : RemoteConfig, @deployment : DeploymentAppConfig)
|
def initialize(@local : DockerImageLocalConfig, @remote : RemoteConfig, @deployment : DokkuAppDeploymentConfig)
|
||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
class DeploymentMariadb
|
class MysqlDumpToDokkuMariadbDeployment
|
||||||
def initialize(@local : LocalFileConfig, @remote : RemoteConfig, @deployment : DeploymentMariadbConfig)
|
def initialize(@local : LocalFileConfig, @remote : RemoteConfig, @deployment : DeploymentMariadbConfig)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,42 @@ module Pushokku
|
||||||
end
|
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)
|
def self.run(args)
|
||||||
app = Cli.new
|
app = Cli.new
|
||||||
opts = app.parse_options(args)
|
opts = app.parse_options(args)
|
||||||
|
@ -82,31 +118,7 @@ module Pushokku
|
||||||
# env_config = App.get_config(config, opts["environment"])
|
# env_config = App.get_config(config, opts["environment"])
|
||||||
|
|
||||||
config.deployments.each do |deployment_config|
|
config.deployments.each do |deployment_config|
|
||||||
local = config.locals.select { |l| l.name == deployment_config.local }.first
|
handle_deployment(config, deployment_config)
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
exit 2
|
exit 2
|
||||||
|
|
Loading…
Reference in a new issue