gbuild 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e498c940ad38cc29dac08303b331074185ec47e21dbaeae836f92a816597b3f9
4
+ data.tar.gz: d2f537841c4fd0519dc2146b2450830fdef6dcf885affbdcf04392d555047d1b
5
+ SHA512:
6
+ metadata.gz: e27cdcf651b0e5f58a79e1019cdc15776306ca78f70ea2d4daefe9765585835d0dac58f2d4f3d6940874daebb9beb52af50477e0da857c000e9988ae66dbf54b
7
+ data.tar.gz: 795daa5c80523080151551d9b2d2e2de5c45b42f2c3f2f8d0bc340f0e0480619c924de9a2f9521970330e999bbed8b204f406b208ef4c51ea99801986968c73c
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1 @@
1
+ gbuild
@@ -0,0 +1 @@
1
+ 2.6.0
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 1.16.6
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in gbuild.gemspec
6
+ gemspec
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gbuild (0.2.0)
5
+ clamp
6
+ kommando
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ clamp (1.3.0)
12
+ diff-lcs (1.3)
13
+ kommando (0.1.2)
14
+ rake (10.5.0)
15
+ rspec (3.8.0)
16
+ rspec-core (~> 3.8.0)
17
+ rspec-expectations (~> 3.8.0)
18
+ rspec-mocks (~> 3.8.0)
19
+ rspec-core (3.8.0)
20
+ rspec-support (~> 3.8.0)
21
+ rspec-expectations (3.8.2)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-mocks (3.8.0)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.8.0)
27
+ rspec-support (3.8.0)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ bundler (~> 1.16)
34
+ gbuild!
35
+ rake (~> 10.0)
36
+ rspec (~> 3.0)
37
+
38
+ BUNDLED WITH
39
+ 1.17.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Matti Paksula
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,50 @@
1
+ # gbuild
2
+
3
+ Fast Google Cloud Build builds without YAMLs or Git triggers.
4
+
5
+ - Uses Kaniko and caching
6
+ - Also removes the build source and logs (Google doesn't do this automatically)
7
+ - Requires `gcloud` and `gsutil`
8
+
9
+
10
+ ## Usage
11
+
12
+ Basic usage:
13
+
14
+ gbuild gcr.io/project/name
15
+
16
+ Advanced usage:
17
+
18
+ gbuild eu.gcr.io/project/name:latest \
19
+ --build-arg first=1 --build-arg second=2 \
20
+ --no-cache \
21
+ --clean-source \
22
+ --timeout 30
23
+
24
+ Clean all logs and sources:
25
+
26
+ gbuild clean project
27
+
28
+ Delete an image:
29
+
30
+ gbuild delete gcr.io/project/name
31
+
32
+ Full usage:
33
+
34
+ Usage:
35
+ gbuild [OPTIONS] IMAGE
36
+
37
+ Parameters:
38
+ IMAGE GCR URL (gcr.io/project/image)
39
+
40
+ Options:
41
+ --context CONTEXT build context, defaults to current working directory
42
+ --build-arg BUILD_ARG docker build argument, can be given multiple times
43
+ --[no-]cache cache layers (default: true)
44
+ --[no-]clean-source clean source (default: true)
45
+ --[no-]clean-log clean log (default: true)
46
+ --debug debug (default: false)
47
+ --dockerfile DOCKERFILE path to Dockerfile (default: nil)
48
+ --project PROJECT gcloud project, defaults to project part in GCR URL
49
+ --timeout TIMEOUT build timeout
50
+ -h, --help print help
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gbuild"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ FROM busybox
2
+ ARG first
3
+ ARG second
4
+
5
+ RUN echo $first && echo $second
@@ -0,0 +1 @@
1
+ FROM busybox
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env sh
2
+ set -e
3
+ set -x
4
+
5
+ cd e2e/simple
6
+ ../../exe/gbuild --debug gcr.io/$GCLOUD_PROJECT/simple
7
+ cd ../..
8
+
9
+ exe/gbuild --debug gcr.io/$GCLOUD_PROJECT/build_args --context e2e/simple --timeout 1
10
+
11
+ exe/gbuild --debug gcr.io/$GCLOUD_PROJECT/build_args --context e2e/build_args
12
+
13
+ exe/gbuild --debug gcr.io/$GCLOUD_PROJECT/custom_dockerfile --context e2e/custom_dockerfile --dockerfile Dockerfile.custom
14
+ exe/gbuild --debug gcr.io/$GCLOUD_PROJECT/nested_dockerfile --context e2e/nested_dockerfile --dockerfile subdir/Dockerfile
15
+
16
+ exe/gbuild delete gcr.io/$GCLOUD_PROJECT/simple
17
+ exe/gbuild delete gcr.io/$GCLOUD_PROJECT/build_args
18
+ exe/gbuild delete gcr.io/$GCLOUD_PROJECT/custom_dockerfile
19
+ exe/gbuild delete gcr.io/$GCLOUD_PROJECT/nested_dockerfile
20
+
21
+ exe/gbuild clean $GCLOUD_PROJECT
@@ -0,0 +1 @@
1
+ FROM busybox
@@ -0,0 +1 @@
1
+ FROM busybox
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # add lib to libpath (only needed when running from the sources)
5
+ require 'pathname'
6
+ lib_path = File.expand_path('../../lib', Pathname.new(__FILE__).realpath)
7
+ $LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
8
+
9
+ STDOUT.sync = true
10
+
11
+ require 'gbuild'
12
+ Gbuild::RootCommand.run
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "gbuild/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gbuild"
8
+ spec.version = Gbuild::VERSION
9
+ spec.authors = ["Matti Paksula"]
10
+ spec.email = ["matti.paksula@iki.fi"]
11
+
12
+ spec.summary = "gbuild"
13
+ spec.homepage = "https://github.com/matti/gbuild"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "clamp"
26
+ spec.add_dependency "kommando"
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.16"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ end
@@ -0,0 +1,26 @@
1
+ require "clamp"
2
+ if Clamp.respond_to? :allow_options_after_parameters
3
+ Clamp.allow_options_after_parameters = true
4
+ end
5
+
6
+ require "kommando"
7
+ require "erb"
8
+
9
+ module Gbuild
10
+ def self.source_bucket(project_name)
11
+ "gs://#{project_name}_cloudbuild/gbuild-sources"
12
+ end
13
+
14
+ def self.logs_bucket(project_name)
15
+ "gs://#{project_name}_cloudbuild/gbuild-logs"
16
+ end
17
+ end
18
+
19
+ require_relative "gbuild/version"
20
+ require_relative "gbuild/template"
21
+
22
+ require_relative "gbuild/clean_command"
23
+ require_relative "gbuild/build_command"
24
+ require_relative "gbuild/delete_command"
25
+
26
+ require_relative "gbuild/root_command"
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+ require "tempfile"
3
+
4
+ module Gbuild
5
+ class BuildCommand < Clamp::Command
6
+ parameter "IMAGE", "GCR URL (gcr.io/project/image)"
7
+ option "--context", "CONTEXT", "build context, defaults to current working directory"
8
+ option "--build-arg", "BUILD_ARG", "docker build argument, can be given multiple times", multivalued: true
9
+
10
+ option "--[no-]cache", :flag, "cache layers", default: true
11
+ option "--[no-]clean-source", :flag, "clean source", default: true
12
+ option "--[no-]clean-log", :flag, "clean log", default: true
13
+
14
+ option "--debug", :flag, "debug", default: false
15
+
16
+ option "--dockerfile", "DOCKERFILE", "path to Dockerfile", default: nil
17
+ option "--project", "PROJECT", "gcloud project, defaults to project part in GCR URL"
18
+ option "--timeout", "TIMEOUT", "build timeout"
19
+
20
+ def execute
21
+ project_name = unless project
22
+ _, project_from_image, _ = image.split("/")
23
+ project_from_image
24
+ else
25
+ project
26
+ end
27
+
28
+ build_source = "#{Gbuild.source_bucket(project_name)}/#{SecureRandom.uuid}"
29
+ build_log = "#{Gbuild.logs_bucket(project_name)}/#{SecureRandom.uuid}"
30
+
31
+ t = Template.new "build.yaml"
32
+ t.set :image, image
33
+ t.set :dockerfile, dockerfile if dockerfile
34
+ t.set :build_args, build_arg_list
35
+ t.set :cache, (cache? ? "true" : "false")
36
+ t.set :debug, debug?
37
+
38
+ gcloud_config = Tempfile.new
39
+ File.write gcloud_config.path, t.result
40
+
41
+ puts t.result if debug?
42
+
43
+ cmd = ["gcloud","builds","submit"]
44
+ cmd << context unless context == {}
45
+
46
+ cmd += ["--gcs-log-dir", build_source]
47
+ cmd += ["--gcs-source-staging-dir", build_log]
48
+
49
+ cmd += ["--config", gcloud_config.path]
50
+ cmd += ["--timeout", timeout] if timeout
51
+ cmd += ["--project", project_name]
52
+
53
+ build_cmd = cmd.join " "
54
+ puts build_cmd if debug?
55
+ build_k = Kommando.new build_cmd, output: true
56
+ build_k.run
57
+
58
+ waits = []
59
+ if clean_source?
60
+ puts "removing source from #{build_source}"
61
+ waits << (Kommando.run_async "gsutil rm -r #{build_source}")
62
+ end
63
+ if clean_log?
64
+ puts "removing log from #{build_log}"
65
+ waits << (Kommando.run_async "gsutil rm -r #{build_log}")
66
+ end
67
+ waits.each { |k| k.wait }
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gbuild
4
+ class CleanCommand < Clamp::Command
5
+ parameter "PROJECT", "project"
6
+
7
+ def execute
8
+ Kommando.run "gsutil -m rm -r #{Gbuild.source_bucket(project)}", output: true
9
+ Kommando.run "gsutil -m rm -r #{Gbuild.source_bucket(project)}", output: true
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gbuild
4
+ class DeleteCommand < Clamp::Command
5
+ parameter "IMAGE", "image to delete"
6
+
7
+ def execute
8
+ Kommando.run "gcloud container images delete #{image} --quiet --force-delete-tags", output: true
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+ require "tempfile"
3
+ require "securerandom"
4
+
5
+ module Gbuild
6
+ class RootCommand < Clamp::Command
7
+ banner "💥 gbuild #{Gbuild::VERSION}"
8
+
9
+ option ['-v', '--version'], :flag, "Show version information" do
10
+ puts Gbuild::VERSION
11
+ exit 0
12
+ end
13
+
14
+ subcommand ["build"], "build", BuildCommand
15
+ subcommand ["clean"], "clean", CleanCommand
16
+ subcommand ["delete"], "delete", DeleteCommand
17
+
18
+ def self.run
19
+ case ARGV.first
20
+ when nil
21
+ super
22
+ when "clean"
23
+ ARGV.shift
24
+ CleanCommand.run
25
+ when "delete"
26
+ ARGV.shift
27
+ DeleteCommand.run
28
+ else
29
+ BuildCommand.run
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,19 @@
1
+ module Gbuild
2
+ class Template
3
+ def initialize(name)
4
+ path = File.expand_path(
5
+ File.join(__dir__, "..","..", "templates", name)
6
+ )
7
+
8
+ @__erb = ERB.new File.read(path), trim_mode: "<>"
9
+ end
10
+
11
+ def set(key, value)
12
+ instance_variable_set "@#{key}", value
13
+ end
14
+
15
+ def result
16
+ @__erb.result binding
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module Gbuild
2
+ VERSION = "0.2.0"
3
+ end
@@ -0,0 +1,18 @@
1
+ steps:
2
+ <% if @debug %>
3
+ - name: busybox
4
+ entrypoint: sh
5
+ args:
6
+ - -c
7
+ - "ls -l"
8
+ <% end %>
9
+ - name: gcr.io/kaniko-project/executor:latest
10
+ args:
11
+ <% if @dockerfile %>
12
+ - --dockerfile=<%= @dockerfile %>
13
+ <% end %>
14
+ - --cache=<%= @cache %>
15
+ - --destination=<%= @image %>
16
+ <% @build_args.each do |build_arg| %>
17
+ - --build-arg=<%= build_arg %>
18
+ <% end %>
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gbuild
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Matti Paksula
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-02-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: clamp
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: kommando
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description:
84
+ email:
85
+ - matti.paksula@iki.fi
86
+ executables:
87
+ - gbuild
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".ruby-gemset"
94
+ - ".ruby-version"
95
+ - ".travis.yml"
96
+ - Gemfile
97
+ - Gemfile.lock
98
+ - LICENSE.txt
99
+ - README.md
100
+ - Rakefile
101
+ - bin/console
102
+ - bin/setup
103
+ - e2e/build_args/Dockerfile
104
+ - e2e/custom_dockerfile/Dockerfile.custom
105
+ - e2e/e2e.sh
106
+ - e2e/nested_dockerfile/subdir/Dockerfile
107
+ - e2e/simple/Dockerfile
108
+ - exe/gbuild
109
+ - gbuild.gemspec
110
+ - lib/gbuild.rb
111
+ - lib/gbuild/build_command.rb
112
+ - lib/gbuild/clean_command.rb
113
+ - lib/gbuild/delete_command.rb
114
+ - lib/gbuild/root_command.rb
115
+ - lib/gbuild/template.rb
116
+ - lib/gbuild/version.rb
117
+ - templates/build.yaml
118
+ homepage: https://github.com/matti/gbuild
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubygems_version: 3.0.1
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: gbuild
141
+ test_files: []