Sha256: 94957ea66b16e6e28f2d10fc3dd2748b9834b43c05f81672db6db8c6ca668888

Contents?: true

Size: 1.52 KB

Versions: 7

Compression:

Stored size: 1.52 KB

Contents

module AppRb::Util::Build
  def self.build(user, host, repo, ssh_key, target, registry, image_name, pre_build_cmds = [])
    AppRb::Util.do_it "ssh #{user}@#{host} bash <<EOF
      set -e
      tmpfile=\\$(mktemp /tmp/git-ssh-#{repo_cache(repo)}.XXXXXX)
      echo '#!/bin/sh' > \\$tmpfile
      echo 'exec /usr/bin/ssh -o StrictHostKeyChecking=no -i #{ssh_key} \"\\$@\"' >> \\$tmpfile
      chmod +x \\$tmpfile
      export GIT_SSH=\\$tmpfile
      if [ -d #{repo_cache(repo)} ]; then
        echo update cache...
        cd #{repo_cache(repo)}
        git checkout . && git clean -dfx && git checkout master && git pull
        git branch | grep -v master | xargs -r git branch -D
      else
        echo clone...
        git clone git@github.com:#{repo} #{repo_cache(repo)} && cd #{repo_cache(repo)}
      fi
      git checkout #{target}
      rm \\$tmpfile\nEOF"

    hash = AppRb::Util.just_cmd("ssh #{user}@#{host} 'cd #{repo_cache(repo)} && git rev-parse HEAD'")
    tags = AppRb::Util::Registry.tags_list(registry, image_name)
    puts "hash: #{hash}"
    puts "tags: #{tags.inspect}"

    unless tags.index(hash)
      puts AppRb::Util.blue("+++ BUILD image")
      AppRb::Util.do_it "ssh #{user}@#{host} bash <<EOF
        set -e
        cd #{repo_cache(repo)}
        #{pre_build_cmds.join("\n")}
        docker build -t #{registry}/#{image_name}:#{hash} .
        docker push #{registry}/#{image_name}:#{hash}
        echo Done.\nEOF"
    end

    return hash
  end

private

  def self.repo_cache(repo)
    repo.gsub("/", "-") + "-cache"
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
app-rb-0.8.0 lib/app-rb/util/build.rb
app-rb-0.7.0 lib/app-rb/util/build.rb
app-rb-0.6.0 lib/app-rb/util/build.rb
app-rb-0.5.0 lib/app-rb/util/build.rb
app-rb-0.4.0 lib/app-rb/util/build.rb
app-rb-0.3.0 lib/app-rb/util/build.rb
app-rb-0.2.0 lib/app-rb/util/build.rb