Sha256: cde8d386959e442a4eec4ec14356fb74260b6d4b442b527e32cc180d406de68b

Contents?: true

Size: 1.79 KB

Versions: 2

Compression:

Stored size: 1.79 KB

Contents

module Phase
  module Deploy

    class Build
      include ::Phase::Util::Shell

      attr_reader :version_tag, :build_dir

      def initialize(version_tag, options = {})
        @version_tag = version_tag
        @build_dir = ::Pathname.new( options.fetch(:build_dir, "build") )
      end

      def execute!
        build_image
        # tag_image
        push
      end

      private

        def build_image
          prepare_build

          shell("docker build -t #{repo_name}:#{version_tag} #{build_dir}") do |status|
            fail "couldn't build Docker image"
          end
        end

        def clone_local_git_repo
          current_branch = `git rev-parse --abbrev-ref HEAD`.strip
          shell("git clone --reference $(pwd) --branch #{current_branch} --depth 1 -- file://$(pwd) #{build_dir}") do |status|
            fail "couldn't clone local copy of git repository"
          end
        end

        def prepare_build
          remove_stale_build_dir!
          clone_local_git_repo
          set_file_modification_timestamps
        end

        # def tag_image
        #   shell("docker tag #{repo_name}:#{version_tag} #{repo_name}:latest") do |status|
        #     fail "couldn't tag Docker image"
        #   end
        # end

        def push
          shell("docker push #{repo_name}:#{version_tag}") do |status|
            fail "couldn't push #{repo_name}:#{version_tag}"
          end

          # shell("docker push #{repo_name}:latest") do |status|
          #   fail "couldn't push #{repo_name}:latest"
          # end
        end

        def remove_stale_build_dir!
          ::FileUtils.rm_rf(build_dir)
        end

        def repo_name
          ::Phase.config.deploy.docker_repository
        end

        def set_file_modification_timestamps
          
        end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
phase-0.0.16.1 lib/phase/kit/deploy/build.rb
phase-0.0.16 lib/phase/kit/deploy/build.rb