Merge branch 'feature/26d3b6d-handle-v3-format-of-configuration' into develop
This commit is contained in:
commit
651bb3c318
16 changed files with 300 additions and 98 deletions
9
TODO.md
Normal file
9
TODO.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
cat database.sql.gz |ssh shiva-ratri.infra.boldcode.io 'docker exec -i customer-sans-a-site.web.1 sh -c "cat > adminer.sql.gz"'
|
||||
|
||||
cat database.sql |ssh shiva-ratri.infra.boldcode.io 'dokku mariadb:import customer-sans-a-wpsandbox'
|
||||
|
||||
# TODO
|
||||
|
||||
* verify target app exist
|
||||
* verify target database exist
|
||||
|
61
doc/pushokku-v3.yml
Normal file
61
doc/pushokku-v3.yml
Normal file
|
@ -0,0 +1,61 @@
|
|||
---
|
||||
version: "3"
|
||||
|
||||
hosts:
|
||||
- name: local
|
||||
localhost: {}
|
||||
|
||||
- name: testing
|
||||
ssh:
|
||||
user: debian
|
||||
host: shiva-ratri.infra.boldcode.io
|
||||
|
||||
|
||||
endpoints:
|
||||
# Local endpoints
|
||||
- name: local-wp-image
|
||||
host: local
|
||||
docker_image:
|
||||
name: sans-a-site-v2-wordpress_wordpress
|
||||
|
||||
- name: local-db-dump
|
||||
host: local
|
||||
mysql_dump:
|
||||
path: database.sql
|
||||
|
||||
- name: local-db-script
|
||||
host: local
|
||||
script:
|
||||
path: .pushokku/post-update.sh
|
||||
|
||||
# Remote endpoints
|
||||
- name: remote-wp-app
|
||||
host: testing
|
||||
dokku_app:
|
||||
name: customer-sans-a-site
|
||||
|
||||
- name: remote-wp-db
|
||||
host: testing
|
||||
dokku_mariadb:
|
||||
name: customer-sans-a-wpsandbox
|
||||
|
||||
|
||||
filters:
|
||||
- name: compress
|
||||
dual:
|
||||
cmd_in: gzip -
|
||||
cmd_out: gunzip -
|
||||
|
||||
|
||||
deployments:
|
||||
- transfer:
|
||||
src: local-wp-image
|
||||
dest: remote-wp-app
|
||||
|
||||
- transfer:
|
||||
src: local-db-dump
|
||||
dest: remote-wp-db
|
||||
|
||||
- run:
|
||||
src: local-db-script
|
||||
dest: remote-wp-app
|
|
@ -1,9 +1,13 @@
|
|||
|
||||
require "yaml"
|
||||
require "./config/config"
|
||||
require "./config/local"
|
||||
require "./config/remote"
|
||||
require "./config/deployment"
|
||||
|
||||
|
||||
require "./config/*"
|
||||
|
||||
class Config
|
||||
YAML.mapping(
|
||||
version: String,
|
||||
hosts: Array(HostConfig),
|
||||
endpoints: Array(EndpointConfig),
|
||||
filters: Array(FilterConfig),
|
||||
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,21 @@
|
|||
|
||||
require "yaml"
|
||||
require "./deployment_settings"
|
||||
|
||||
class DokkuMariadbConfig
|
||||
class RunDeploymentConfig
|
||||
YAML.mapping(
|
||||
name: String,
|
||||
options: YAML::Any | Nil
|
||||
name: String?,
|
||||
run: RunDeploymentConfigSettings
|
||||
)
|
||||
end
|
||||
|
||||
class DokkuAppConfig
|
||||
class TransferDeploymentConfig
|
||||
YAML.mapping(
|
||||
name: String,
|
||||
options: YAML::Any | Nil
|
||||
)
|
||||
end
|
||||
|
||||
class DeploymentMariadbConfig
|
||||
YAML.mapping(
|
||||
local: String,
|
||||
remote: String,
|
||||
dokku_mariadb: DokkuMariadbConfig,
|
||||
)
|
||||
end
|
||||
|
||||
class DeploymentAppConfig
|
||||
YAML.mapping(
|
||||
local: String,
|
||||
remote: String,
|
||||
dokku_app: DokkuAppConfig,
|
||||
name: String?,
|
||||
transfer: TransferDeploymentConfigSettings
|
||||
)
|
||||
end
|
||||
|
||||
alias DeploymentConfig =
|
||||
DeploymentMariadbConfig |
|
||||
DeploymentAppConfig
|
||||
|
||||
TransferDeploymentConfig |
|
||||
RunDeploymentConfig
|
||||
|
|
17
src/config/deployment_settings.cr
Normal file
17
src/config/deployment_settings.cr
Normal file
|
@ -0,0 +1,17 @@
|
|||
|
||||
require "yaml"
|
||||
|
||||
class TransferDeploymentConfigSettings
|
||||
YAML.mapping(
|
||||
src: String,
|
||||
dest: String,
|
||||
filters: Array(String)?
|
||||
)
|
||||
end
|
||||
|
||||
class RunDeploymentConfigSettings
|
||||
YAML.mapping(
|
||||
src: String,
|
||||
dest: String,
|
||||
)
|
||||
end
|
52
src/config/endpoint.cr
Normal file
52
src/config/endpoint.cr
Normal file
|
@ -0,0 +1,52 @@
|
|||
|
||||
require "yaml"
|
||||
require "./endpoint_settings"
|
||||
|
||||
|
||||
class DokkuMariadbEndpointConfig
|
||||
YAML.mapping(
|
||||
name: String,
|
||||
host: String,
|
||||
dokku_mariadb: DokkuMariadbEndpointConfigSettings
|
||||
)
|
||||
end
|
||||
|
||||
class DokkuAppEndpointConfig
|
||||
YAML.mapping(
|
||||
name: String,
|
||||
host: String,
|
||||
dokku_app: DokkuAppEndpointConfigSettings
|
||||
)
|
||||
end
|
||||
|
||||
class ScriptEndpointConfig
|
||||
YAML.mapping(
|
||||
name: String,
|
||||
host: String,
|
||||
script: ScriptEndpointConfigSettings
|
||||
)
|
||||
end
|
||||
|
||||
class MysqlDumpEndpointConfig
|
||||
YAML.mapping(
|
||||
name: String,
|
||||
host: String,
|
||||
mysql_dump: MysqlDumpEndpointConfigSettings
|
||||
)
|
||||
end
|
||||
|
||||
class DockerImageEndpointConfig
|
||||
YAML.mapping(
|
||||
name: String,
|
||||
host: String,
|
||||
docker_image: DockerImageEndpointConfigSettings
|
||||
)
|
||||
end
|
||||
|
||||
alias EndpointConfig =
|
||||
DockerImageEndpointConfig |
|
||||
MysqlDumpEndpointConfig |
|
||||
ScriptEndpointConfig |
|
||||
DokkuAppEndpointConfig |
|
||||
DokkuMariadbEndpointConfig
|
||||
|
37
src/config/endpoint_settings.cr
Normal file
37
src/config/endpoint_settings.cr
Normal file
|
@ -0,0 +1,37 @@
|
|||
|
||||
require "yaml"
|
||||
|
||||
class DokkuMariadbEndpointConfigSettings
|
||||
YAML.mapping(
|
||||
name: String
|
||||
)
|
||||
end
|
||||
|
||||
class DokkuAppEndpointConfigSettings
|
||||
YAML.mapping(
|
||||
name: String
|
||||
)
|
||||
end
|
||||
|
||||
class DockerImageEndpointConfigSettings
|
||||
YAML.mapping(
|
||||
tag: {
|
||||
type: String,
|
||||
nilable: false,
|
||||
default: "latest"
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
class MysqlDumpEndpointConfigSettings
|
||||
YAML.mapping(
|
||||
path: String
|
||||
)
|
||||
end
|
||||
|
||||
class ScriptEndpointConfigSettings
|
||||
YAML.mapping(
|
||||
path: String
|
||||
)
|
||||
end
|
||||
|
22
src/config/filter.cr
Normal file
22
src/config/filter.cr
Normal file
|
@ -0,0 +1,22 @@
|
|||
|
||||
require "yaml"
|
||||
require "./filter_settings"
|
||||
|
||||
|
||||
class DualFilterConfig
|
||||
YAML.mapping(
|
||||
name: String,
|
||||
dual: DualFilterConfigSettings
|
||||
)
|
||||
end
|
||||
|
||||
class MonoFilterConfig
|
||||
YAML.mapping(
|
||||
name: String,
|
||||
cmd: String
|
||||
)
|
||||
end
|
||||
|
||||
alias FilterConfig =
|
||||
MonoFilterConfig |
|
||||
DualFilterConfig
|
9
src/config/filter_settings.cr
Normal file
9
src/config/filter_settings.cr
Normal file
|
@ -0,0 +1,9 @@
|
|||
|
||||
require "yaml"
|
||||
|
||||
class DualFilterConfigSettings
|
||||
YAML.mapping(
|
||||
cmd_in: String,
|
||||
cmd_out: String,
|
||||
)
|
||||
end
|
22
src/config/host.cr
Normal file
22
src/config/host.cr
Normal file
|
@ -0,0 +1,22 @@
|
|||
|
||||
require "yaml"
|
||||
require "./host_settings"
|
||||
|
||||
class LocalHostConfig
|
||||
YAML.mapping(
|
||||
name: String,
|
||||
localhost: Hash(String, YAML::Any)
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
class SshHostConfig
|
||||
YAML.mapping(
|
||||
name: String,
|
||||
ssh: SshHostConfigSettings
|
||||
)
|
||||
end
|
||||
|
||||
alias HostConfig =
|
||||
LocalHostConfig |
|
||||
SshHostConfig
|
|
@ -1,11 +1,9 @@
|
|||
|
||||
require "yaml"
|
||||
|
||||
class RemoteConfig
|
||||
class SshHostConfigSettings
|
||||
YAML.mapping(
|
||||
name: String,
|
||||
user: String,
|
||||
host: String
|
||||
)
|
||||
end
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
|
||||
require "yaml"
|
||||
|
||||
enum LocalType
|
||||
DOCKER_IMAGE = 1
|
||||
MYSQL_DUMP = 2
|
||||
|
||||
def to_yaml(io)
|
||||
to_s(io)
|
||||
end
|
||||
end
|
||||
|
||||
class LocalFileConfig
|
||||
YAML.mapping(
|
||||
name: String,
|
||||
type: LocalType, # enum ?
|
||||
path: String
|
||||
)
|
||||
end
|
||||
|
||||
class LocalDockerConfig
|
||||
YAML.mapping(
|
||||
name: String,
|
||||
type: LocalType, # enum ?
|
||||
docker_image: String
|
||||
)
|
||||
end
|
||||
|
||||
alias LocalConfig =
|
||||
LocalFileConfig |
|
||||
LocalDockerConfig
|
||||
|
|
@ -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
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
class DeploymentMariadb
|
||||
class MysqlDumpToDokkuMariadbDeployment
|
||||
def initialize(@local : LocalFileConfig, @remote : RemoteConfig, @deployment : DeploymentMariadbConfig)
|
||||
end
|
||||
|
||||
|
|
|
@ -75,32 +75,34 @@ module Pushokku
|
|||
end
|
||||
|
||||
|
||||
def self.run(args)
|
||||
app = Cli.new
|
||||
opts = app.parse_options(args)
|
||||
config = app.load_config(opts["config_file"])
|
||||
# env_config = App.get_config(config, opts["environment"])
|
||||
|
||||
config.deployments.each do |deployment_config|
|
||||
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 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 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
|
||||
|
@ -109,7 +111,38 @@ module Pushokku
|
|||
deployment.run
|
||||
end
|
||||
|
||||
exit 2
|
||||
|
||||
def self.find_filter(config, name)
|
||||
matches = config.filters.select { |filter| filter.name == name }
|
||||
if matches.size > 1
|
||||
raise "Multiple filters have the same name (unicity)"
|
||||
end
|
||||
return matches.first
|
||||
end
|
||||
|
||||
def self.validate_config!(config)
|
||||
pp config
|
||||
#config.deployments.each do |deployment_config|
|
||||
# handle_deployment(config, deployment_config)
|
||||
#end
|
||||
end
|
||||
|
||||
def self.apply_config!(config)
|
||||
config.deployments.each do |deployment_config|
|
||||
# handle_deployment(config, deployment_config)
|
||||
end
|
||||
end
|
||||
|
||||
def self.run(args)
|
||||
app = Cli.new
|
||||
opts = app.parse_options(args)
|
||||
config = app.load_config(opts["config_file"])
|
||||
# env_config = App.get_config(config, opts["environment"])
|
||||
|
||||
validate_config!(config)
|
||||
apply_config!(config)
|
||||
|
||||
exit 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue