diff --git a/TODO.md b/TODO.md index 8552100..79abbe2 100644 --- a/TODO.md +++ b/TODO.md @@ -2,13 +2,17 @@ ## DeploymentConfig +- Content is not rendering correctly (need to read file instead of passing filename) +- Directory is there twice - Don't upload configs if they already exist - Use `service` instead of `deployment` for config generation - Make `config` part of a `deployment` +- Tests should go through the whole flow and actually upload something ## Bugs - If the container count changes, it is mixing up stopping with replacing +- Changing order of role/service definitions should not change the version ## Naming diff --git a/lib/cove/configuration/service.rb b/lib/cove/configuration/service.rb index eed89c4..e775792 100644 --- a/lib/cove/configuration/service.rb +++ b/lib/cove/configuration/service.rb @@ -26,6 +26,7 @@ def roles ports: role_config["ingress"], mounts: role_config["mounts"], environment_variables: role_environment, + configs: role_config["configs"], hosts: role_config["hosts"].map { |host_id| @host_registry[host_id] } ) end diff --git a/lib/cove/deployment.rb b/lib/cove/deployment.rb index 287bd67..8692ace 100644 --- a/lib/cove/deployment.rb +++ b/lib/cove/deployment.rb @@ -55,7 +55,7 @@ def labels private def build_version - Digest::SHA2.hexdigest([role.id, role.image, role.command, role.environment_variables, role.ports].to_json)[0..12] + Digest::SHA2.hexdigest([role.id, role.image, role.command, role.environment_variables, role.ports, role.configs].to_json)[0..12] end end end diff --git a/lib/cove/deployment_config.rb b/lib/cove/deployment_config.rb index 3ce2380..bbec9dd 100644 --- a/lib/cove/deployment_config.rb +++ b/lib/cove/deployment_config.rb @@ -2,6 +2,8 @@ module Cove class DeploymentConfig def self.prepare(registry, deployment) entries = deployment.configs.map do |name, definition| + # TODO: Make sure we always symbolize keys when parsing the config + definition = definition.with_indifferent_access Entry.new( registry: registry, deployment: deployment, name: name, source: definition[:source], diff --git a/lib/cove/deployment_config/config_file.rb b/lib/cove/deployment_config/config_file.rb index 70099a0..20f37f3 100644 --- a/lib/cove/deployment_config/config_file.rb +++ b/lib/cove/deployment_config/config_file.rb @@ -7,6 +7,11 @@ def initialize(path:, content:) @path = path @content = content end + + def directory + dir = File.dirname(path) + dir unless dir == "." + end end end end diff --git a/lib/cove/deployment_config/entry.rb b/lib/cove/deployment_config/entry.rb index e4a9259..74a6d3c 100644 --- a/lib/cove/deployment_config/entry.rb +++ b/lib/cove/deployment_config/entry.rb @@ -18,7 +18,7 @@ def digestables end def directories - files.map(&:directory).uniq + files.map(&:directory).compact.uniq end def files diff --git a/lib/cove/invocation/service_up.rb b/lib/cove/invocation/service_up.rb index 86e943c..ac6a733 100644 --- a/lib/cove/invocation/service_up.rb +++ b/lib/cove/invocation/service_up.rb @@ -48,8 +48,10 @@ def initialize(connection, registry, service, roles) def run roles.each do |role| deployment = Deployment.new(role) + config = DeploymentConfig.prepare(registry, deployment) Steps::EnsureEnvironmentFileExists.call(connection, deployment) + Steps::EnsureConfigsExist.call(connection, config) Steps::PullImage.call(connection, deployment) Steps::CreateMissingContainers.call(connection, deployment) Steps::RollContainers.call(connection, deployment) diff --git a/lib/cove/role.rb b/lib/cove/role.rb index dbc555c..251249d 100644 --- a/lib/cove/role.rb +++ b/lib/cove/role.rb @@ -23,7 +23,7 @@ class Role # @return [String] The name of the service this role belongs to delegate :name, to: :service, prefix: true - def initialize(name:, service:, hosts:, container_count: 1, command: [], environment_variables: {}, ports: [], mounts: [], configs: []) + def initialize(name:, service:, hosts:, container_count: 1, command: [], environment_variables: {}, ports: [], mounts: [], configs: {}) @name = name @service = service @hosts = hosts diff --git a/lib/cove/steps/ensure_configs_exist.rb b/lib/cove/steps/ensure_configs_exist.rb index 869fe48..887e661 100644 --- a/lib/cove/steps/ensure_configs_exist.rb +++ b/lib/cove/steps/ensure_configs_exist.rb @@ -1,6 +1,8 @@ module Cove module Steps class EnsureConfigsExist + include Callable + attr_reader :connection, :deployment_config def initialize(connection, deployment_config)