From ae96ede949056705d217f59a9c589f2ee2b0f703 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Thu, 10 Oct 2019 23:42:49 +0700 Subject: [PATCH] Custom image --- README.md | 4 +++- lib/devkitkat/config.rb | 12 +++++++++-- lib/devkitkat/executor/docker.rb | 5 +++-- lib/devkitkat/image.rb | 37 ++++++++++++++++++++++++++++++++ lib/devkitkat/installs/ruby.rb | 7 ++++++ 5 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 lib/devkitkat/image.rb create mode 100644 lib/devkitkat/installs/ruby.rb diff --git a/README.md b/README.md index ec393cc..ccf9689 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,9 @@ download/prepare services. These are available keys. |`services:` |Hash |Yes |-|The service name e.g. `rails`, `db`, `redis`| |`services::repo: ` |String |No |-|The git URL of the repository| |`services::: ` |Hash |No |-|The key and value of the environment variable. e.g. `POSTGRES_PASSWORD: abcdef`. | -|`image:` |String |No |-|The docker image. Only effective when `type` is `docker` or `cloud`| +|`image:` |Hash or String |No |-|The docker image| +|`image:base:` |String |No |-|The base image name| +|`image:install:` |Array |No |-|The installed application on the image| |`groups:` |Hash |No |-|The groups of the services| |`groups:: ` |Hash |No |-|The name of the group and the service names| |`application:` |String |No |-|The name of the application that consists of the services| diff --git a/lib/devkitkat/config.rb b/lib/devkitkat/config.rb index 4e329e4..ea47d06 100644 --- a/lib/devkitkat/config.rb +++ b/lib/devkitkat/config.rb @@ -42,8 +42,16 @@ def environment_type end end - def image - devkitkat_yml.fetch('image', DEFAULT_IMAGE) + def image_base + if devkitkat_yml['image'].is_a?(String) + devkitkat_yml['image'] + elsif devkitkat_yml['image'].is_a?(Hash) + devkitkat_yml.dig('image', 'base') + end || DEFAULT_IMAGE + end + + def image_install + devkitkat_yml.dig('image', 'install') || [] end def application diff --git a/lib/devkitkat/executor/docker.rb b/lib/devkitkat/executor/docker.rb index 01abda0..5b86b01 100644 --- a/lib/devkitkat/executor/docker.rb +++ b/lib/devkitkat/executor/docker.rb @@ -4,12 +4,13 @@ module Devkitkat class Executor class Docker - attr_reader :service, :script_file + attr_reader :service, :script_file, :image delegate :config, :command, to: :service def initialize(service) @service = service + @image = Image.new(config.image_base, config.image_install) end def prepare @@ -49,7 +50,7 @@ def log_path_in_container end def docker_image - config.image + image.name end def container diff --git a/lib/devkitkat/image.rb b/lib/devkitkat/image.rb new file mode 100644 index 0000000..d952df4 --- /dev/null +++ b/lib/devkitkat/image.rb @@ -0,0 +1,37 @@ +module Devkitkat + class Image + IMAGE_PREFIX = 'devkitkat' + + attr_reader :base, :install + + def initialize(base, install) + @base, @install = base, install + end + + def name + # "#{IMAGE_PREFIX}-#{base_image}:#{install_checksum}" + base + end + + def regstry_url + 'dockerhub' + end + + def build + # TODO: + end + + def push + # TODO: + end + + private + + def install_checksum + end + + def base_image + config.image + end + end +end diff --git a/lib/devkitkat/installs/ruby.rb b/lib/devkitkat/installs/ruby.rb new file mode 100644 index 0000000..215ed33 --- /dev/null +++ b/lib/devkitkat/installs/ruby.rb @@ -0,0 +1,7 @@ +module Devkitkat + module Installs + class Ruby + + end + end +end