Skip to content
13 changes: 13 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@ platforms:
cpus: 2
memory: 4096


suites:
- name: alibaba_automate
run_list: "marketplace_image::default"
attributes:
marketplace_image:
alibaba:
automate:
enabled: true
packman:
version: 1.0.4
checksums:
"1.0.4": 646da085cbcb8c666474d500a44d933df533cf4f1ff286193d67b51372c3c59e
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I think it's good that we're upgrading packer, I'd prefer to see the default version updated to 1.0.4 and breaking changes in other packer definitions fixed. We're tracking that work on: CLOUD-261 and CLOUD-262

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed - did not want to assume upgrading the default version whilst I was getting the initial Alibaba work going


- name: azure_compliance
run_list: "marketplace_image::default"
attributes:
Expand Down
56 changes: 56 additions & 0 deletions attributes/alibaba.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# frozen_string_literal: true
cred_dir = ::File.expand_path(::File.join('~', '.alibaba'))
credential_file = ::File.join(cred_dir, 'credentials')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should probably move the alibaba credentials into the same data_bag that has the Azure, GCP, and AWS creds.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have used the same format as the data bag so it should just be a case of copying and paste from what I have. I do not know where the data bag for those is to update.

To get this working I used a local version of the data bag that kitchen could read.


TIMESTAMP = Time.now.strftime('%Y_%m_%d_%H_%M_%S').freeze
INVALID_AMI_NAME_CHARACTERS = /[^\w\(\)\.\-\/]/

def normalize_name(name)
# Append timestamp
# Remove invalid characters
# Ensure it's 128 characters or less
"#{name}_#{TIMESTAMP}".gsub(INVALID_AMI_NAME_CHARACTERS, '').strip[0..127]
end

default['marketplace_image']['alibaba']['cred_dir'] = cred_dir
default['marketplace_image']['alibaba']['credential_file'] = credential_file

default['marketplace_image']['alibaba']['public']['compliance']['enabled'] = false
default['marketplace_image']['alibaba']['public']['automate']['enabled'] = false

default['marketplace_image']['alibaba']['product_urls'] = {
'marketplace' => 'http://chef-software.oss-cn-beijing.aliyuncs.com/chef-marketplace_0.2.5%2B20171003114422.git.4.cce18c9-1_amd64.deb',
'automate' => 'http://chef-software.oss-cn-beijing.aliyuncs.com/automate_1.6.179-1_amd64.deb',
'chef_server' => 'http://chef-software.oss-cn-beijing.aliyuncs.com/chef-server-core_12.16.9-1_amd64.deb',
}

default_marketplace_config = {
'role' => 'automate',
'platform' => 'alibaba',
'user' => 'ubuntu',
'support_email' => '[email protected]',
'sales_email' => '[email protected]',
'reporting_cron_enabled' => false,
'doc_url' => 'https://docs.chef.io/alibaba_marketplace.html',
'disable_outbound_traffic' => false,
'license_type' => 'fixed',
'free_node_count' => 5,
}

alibaba_builder_config = {
'type' => 'alicloud-ecs',
'region' => 'cn-beijing',
'image_name' => 'chef_automate_20171020_1',
'source_image' => 'ubuntu_14_0405_64_20G_alibase_20170824.vhd',
'ssh_username' => 'root',
'instance_type' => 'ecs.n4.xlarge',
'io_optimized' => 'true',
'internet_charge_type' => 'PayByTraffic',
'image_force_delete' => 'true',
}

default['marketplace_image']['alibaba']['automate'] = {
'name' => 'alibaba_automate_BYOL',
'builder_options' => alibaba_builder_config,
'marketplace_config_options' => default_marketplace_config,
}
27 changes: 23 additions & 4 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
module MarketplaceImageCookbook
module Helpers
def marketplace_products
aws_products + azure_products + gce_products
aws_products + azure_products + gce_products + alibaba_products
end

def enabled_products
enabled_aws_products + enabled_azure_products + enabled_gce_products
enabled_aws_products + enabled_azure_products + enabled_gce_products + enabled_alibaba_products
end

def enabled_builders
Expand Down Expand Up @@ -122,13 +122,32 @@ def enabled_gce_builders
enabled_gce_products.map { |p| p['name'] }
end

def alibaba_products
products = []
products << node['marketplace_image']['alibaba']['automate']
products
end

def enabled_alibaba_products
products = []
products << node['marketplace_image']['alibaba']['automate'] if
node['marketplace_image']['alibaba']['automate']['enabled']
products
end

def alibaba_builders
alibaba_products.map { |p| p['name'] }
end

def automate_products
[node['marketplace_image']['aws']['public']['automate']]
end

def automate_builders
[node['marketplace_image']['aws']['public']['automate']['name'],
node['marketplace_image']['azure']['automate']['name'],
[
node['marketplace_image']['aws']['public']['automate']['name'],
node['marketplace_image']['azure']['automate']['name'],
node['marketplace_image']['alibaba']['automate']['name'],
]
end

Expand Down
6 changes: 6 additions & 0 deletions recipes/_packer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@
content JSON.pretty_generate(creds['gce']['account'])
end
end

# Set the credentials for Alibaba Cloud as environment variables
if creds['alibaba']
ENV['ALICLOUD_ACCESS_KEY'] = creds['alibaba']['access_key']
ENV['ALICLOUD_SECRET_KEY'] = creds['alibaba']['secret_key']
end
34 changes: 29 additions & 5 deletions recipes/_publish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,47 @@
packer_provisioner 'setup_apt_current' do
type 'shell'
source 'setup_apt_current.sh.erb'
only azure_builders
only azure_builders + alibaba_builders
only_if { use_current_repo? }
end

packer_provisioner 'setup_apt_stable' do
type 'shell'
source 'setup_apt_stable.sh.erb'
only azure_builders
only azure_builders + alibaba_builders
not_if { use_current_repo? }
end

packer_provisioner 'apt_dist_upgrade' do
type 'shell'
source 'apt_dist_upgrade.sh.erb'
only alibaba_builders
end

packer_provisioner 'install_marketplace_apt' do
type 'shell'
source 'install_marketplace_apt.sh.erb'
only azure_builders
end

packer_provisioner 'install_marketplace_oss' do
type 'shell'
source 'install_marketplace_oss.sh.erb'
variables(
url: node['marketplace_image']['alibaba']['product_urls']['marketplace']
)
only alibaba_builders
end

packer_provisioner '/tmp/product_download_urls.json' do
type 'file'
source 'product_download_urls.json.erb'
variables(
urls: node['marketplace_image']['alibaba']['product_urls'].to_json
)
only alibaba_builders
end

packer_provisioner 'enable_ipv6_loopback' do
type 'shell'
source 'enable_ipv6_loopback.sh.erb'
Expand All @@ -47,21 +71,21 @@
packer_provisioner 'setup_yum_current' do
type 'shell'
source 'setup_yum_current.sh.erb'
except azure_builders
except azure_builders + alibaba_builders
only_if { use_current_repo? }
end

packer_provisioner 'setup_yum_stable' do
type 'shell'
source 'setup_yum_stable.sh.erb'
except azure_builders
except azure_builders + alibaba_builders
not_if { use_current_repo? }
end

packer_provisioner 'install_marketplace_yum' do
type 'shell'
source 'install_marketplace_yum.sh.erb'
except azure_builders
except azure_builders + alibaba_builders
end

packer_provisioner 'prepare_automate_for_publishing' do
Expand Down
4 changes: 4 additions & 0 deletions templates/default/apt_dist_upgrade.sh.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# Perform a distribution upgrade
sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade -y
5 changes: 5 additions & 0 deletions templates/default/enable_ipv6_loopback.sh.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@
if ! grep net.ipv6.conf.lo.disable_ipv6 /etc/sysctl.conf; then
echo "net.ipv6.conf.lo.disable_ipv6=0" | sudo tee -a /etc/sysctl.conf
fi

# Alibaba images have the loopback explicitly disabled
if grep "net.ipv6.conf.lo.disable_ipv6 = 1" /etc/sysctl.conf; then
sed -i.bak "s/net\.ipv6\.conf\.lo\.disable_ipv6 = 1/net.ipv6.conf.lo.disable_ipv6 = 0/g" /etc/sysctl.conf
fi
8 changes: 8 additions & 0 deletions templates/default/install_marketplace_oss.sh.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# Download an install Marketplace from the Alibaba Object Storage service

set -ex

wget -q -O chef-marketplace.deb <%= @url %>
sudo dpkg -i chef-marketplace.deb
2 changes: 1 addition & 1 deletion templates/default/marketplace.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ manage.marketplace.sign_up.enabled = true
<% end -%>
<% if @role != 'aio' -%>
analytics.trimmer.enabled = false
<% end -%>
<% end -%>
3 changes: 3 additions & 0 deletions templates/default/product_download_urls.json.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"urls": <%= @urls %>
}