Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add stack association to buildpack model [#153256959]
- Add "stack" to buildpack model - At migration time, buildpacks will be assigned default stack from stacks.yml file if its path is set in the STACKS_YML env var - hwc_buildpack is assigned the newer of windows2016,windows2012R2 stacks if present in stacks.yml - if STACKS_YML is not set, buildpacks' stacks will be set to nil - Buildpacks are now unique over name AND stack - Sets buildpack stack from manifest.yml in buildpack zip on creation - Validate buildpack model stack against stack in buildpack zip manifest.yml - Validate stack exists upon buildpack bits upload - Include stack name in serialized buildpack filename - Only provide buildpacks for the relevant stack to the staging container - Handle buildpack stacks appropriately in the buildpack installer - Use fork of rubyzip/rubyzip to work around rubyzip/rubyzip#236 NOTE: The API checkshum has changed due to adding stack as an input Signed-off-by: Dave Goddard <dave@goddard.id.au> Signed-off-by: Victoria Henry <vhenry@pivotal.io> Signed-off-by: Jackson Feeny <jacksonfeeny@gmail.com> Signed-off-by: Tyler Phelan <tphelan@pivotal.io> Signed-off-by: Andrew Meyer <ameyer@pivotal.io> Signed-off-by: Leah Hanson <lhanson@pivotal.io>
- Loading branch information
Showing
37 changed files
with
863 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
db/migrations/20180102183100_add_stack_to_buildpack_table.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Sequel.migration do | ||
up do | ||
alter_table(:buildpacks) do | ||
add_column :stack, String, size: 255, null: true | ||
drop_index :name, unique: true | ||
add_index [:name, :stack], unique: true, name: :unique_name_and_stack | ||
end | ||
end | ||
|
||
down do | ||
alter_table(:buildpacks) do | ||
drop_index [:name, :stack], unique: true, name: :unique_name_and_stack | ||
drop_column :stack | ||
add_index :name, unique: true, name: :buildpacks_name_index | ||
end | ||
end | ||
end |
30 changes: 30 additions & 0 deletions
30
db/migrations/20180404165800_assign_stacks_to_buildpacks.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'yaml' | ||
|
||
def stacks_yml | ||
stacks_yml_path = ENV.fetch('STACKS_YML', nil) | ||
YAML.safe_load(File.read(stacks_yml_path)) if stacks_yml_path && File.exist?(stacks_yml_path) | ||
end | ||
|
||
def default_stack | ||
stacks_yml['default'] if stacks_yml | ||
end | ||
|
||
def latest_windows_stack | ||
return unless stacks_yml | ||
stack_names = stacks_yml['stacks'].map { |stack| stack['name'] } | ||
if stack_names.include?('windows2016') | ||
return 'windows2016' | ||
end | ||
if stack_names.include?('windows2012R2') | ||
return 'windows2012R2' | ||
end | ||
end | ||
|
||
Sequel.migration do | ||
up do | ||
self[:buildpacks].where(Sequel.negate(name: 'hwc_buildpack')).update(stack: default_stack) if default_stack | ||
self[:buildpacks].where(name: 'hwc_buildpack').update(stack: latest_windows_stack) if latest_windows_stack | ||
end | ||
|
||
down {} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module VCAP::CloudController | ||
module Buildpacks | ||
class StackNameExtractor | ||
ONE_MEGABYTE = 1024 * 1024 | ||
|
||
def self.extract_from_file(bits_file_path) | ||
bits_file_path = bits_file_path.path if bits_file_path.respond_to?(:path) | ||
Zip::File.open(bits_file_path) do |zip_file| | ||
zip_file.each do |entry| | ||
if entry.name == 'manifest.yml' | ||
raise CloudController::Errors::BuildpackError.new('buildpack manifest is too large') if entry.size > ONE_MEGABYTE | ||
return YAML.safe_load(entry.get_input_stream.read).dig('stack') | ||
end | ||
end | ||
end | ||
nil | ||
rescue Psych::Exception | ||
raise CloudController::Errors::BuildpackError.new('buildpack manifest is not valid') | ||
rescue Zip::Error | ||
raise CloudController::Errors::BuildpackError.new('buildpack zipfile is not valid') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module CloudController | ||
module Errors | ||
class BuildpackError < StandardError; end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
default: "default-stack-name" | ||
|
||
stacks: | ||
- name: "cflinuxfs2" | ||
description: "cflinuxfs2" | ||
- name: "default-stack-name" | ||
description: "default-stack-description" | ||
- name: "cider" | ||
description: "cider-description" | ||
- name: "windows2012R2" | ||
description: "windows2012R2-description" |
Oops, something went wrong.