Skip to content

Commit

Permalink
Merge pull request #545 from duncaan/add-corretto
Browse files Browse the repository at this point in the history
Add Amazon Corretto
  • Loading branch information
damacus authored May 8, 2019
2 parents 03afa97 + 1cc54d0 commit aa17ed1
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,25 @@ suites:
- test/integration/remove-adoptopenjdk
attrs:
- test/integration/adoptopenjdk/attributes/adoptopenjdk-11-openj9.yml
- name: corretto-8
includes:
- amazon-linux
- centos-6
- centos-7
- debian-8
- debian-9
- ubuntu-16.04
- ubuntu-18.04
run_list:
- recipe[test::corretto8]
- name: corretto-11
includes:
- amazon-linux
- centos-6
- centos-7
- debian-8
- debian-9
- ubuntu-16.04
- ubuntu-18.04
run_list:
- recipe[test::corretto11]
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This file is used to list changes made in each version of the Java cookbook.

## Unreleased

- Added new install flavor "corretto" for Amazon's Corretto distribution of OpenJDK

## 4.0.0 - 2019-04-19

- Added new install flavor "adoptopenjdk" for AdoptOpenJDK's distribution of Java
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ While public YUM repos for Oracle Java 7 and prior are available, you need to do

This recipe installs the `AdoptOpenJDK` flavor of Java from [https://adoptopenjdk.net/.](https://adoptopenjdk.net/.) It also uses the `alternatives` system on the RHEL/Debian families to set the default Java.

### Amazon Corretto
This recipe installs the `Amazon Corretto` flavor of OpenJDK from https://aws.amazon.com/corretto/. It also uses the `alternatives` system on RHEL/Debian families to set the default Java.

### windows

Because as of 26 March 2012 you can no longer directly download the JDK msi from Oracle's website without using a special cookie. This recipe requires you to set `node['java']['oracle']['accept_oracle_download_terms']` to true or host it internally on your own http repo or s3 bucket.
Expand Down
9 changes: 9 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,12 @@
default['java']['adoptopenjdk']['12']['x86_64']['openj9-large-heap']['checksum'] = nil
# TODO: Update list when released
default['java']['adoptopenjdk']['12']['bin_cmds']['default'] = %w(jar jarsigner java javac javadoc javap jcmd jconsole jdb jdeprscan jdeps jhsdb jimage jinfo jjs jlink jmap jmod jps jrunscript jshell jstack jstat jstatd keytool pack200 rmic rmid rmiregistry serialver unpack200)

# Amazon Corretto
default['java']['corretto']['8']['x86_64']['url'] = 'https://d3pxv6yz143wms.cloudfront.net/8.212.04.2/amazon-corretto-8.212.04.2-linux-x64.tar.gz'
default['java']['corretto']['8']['x86_64']['checksum'] = '782d5452cd7395340d791dbdd0f418a8'
default['java']['corretto']['8']['bin_cmds'] = %w(appletviewer clhsdb extcheck hsdb idlj jar jarsigner java java-rmi.cgi javac javadoc javafxpackager javah javap javapackager jcmd jconsole jdb jdeps jhat jinfo jjs jmap jps jrunscript jsadebugd jstack jstat jstatd keytool native2ascii orbd pack200 policytool rmic rmid rmiregistry schemagen serialver servertool tnameserv unpack200 wsgen wsimport xjc)

default['java']['corretto']['11']['x86_64']['url'] = 'https://d3pxv6yz143wms.cloudfront.net/11.0.3.7.1/amazon-corretto-11.0.3.7.1-linux-x64.tar.gz'
default['java']['corretto']['11']['x86_64']['checksum'] = '08a0cea184824c5477a62ce6a6a0fb0b'
default['java']['corretto']['11']['bin_cmds'] = %w(jaotc jar jarsigner java javac javadoc javap jcmd jconsole jdb jdeprscan jdeps jhsdb jimage jinfo jjs jlink jmap jmod jps jrunscript jshell jstack jstat jstatd keytool pack200 rmic rmid rmiregistry serialver unpack200)
46 changes: 46 additions & 0 deletions recipes/corretto.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Cookbook:: java
# Recipe:: corretto
# This recipe installs and configures Amazon's Corretto package
# https://aws.amazon.com/corretto/

include_recipe 'java::notify'

unless node.recipe?('java::default')
Chef::Log.warn('Using java::default instead is recommended.')

# Even if this recipe is included by itself, a safety check is nice...
if node['java']['java_home'].nil? || node['java']['java_home'].empty?
include_recipe 'java::set_attributes_from_version'
end
end

java_home = node['java']['java_home']
arch = node['java']['arch']
version = node['java']['jdk_version'].to_s
tarball_url = node['java']['corretto'][version][arch]['url']
tarball_checksum = node['java']['corretto'][version][arch]['checksum']
bin_cmds = node['java']['corretto'][version]['bin_cmds']

include_recipe 'java::set_java_home'

java_oracle_install 'jdk' do
url tarball_url
default node['java']['set_default']
md5 tarball_checksum
app_home java_home
bin_cmds bin_cmds
alternatives_priority node['java']['alternatives_priority']
retries node['java']['ark_retries']
retry_delay node['java']['ark_retry_delay']
connect_timeout node['java']['ark_timeout']
use_alt_suffix node['java']['use_alt_suffix']
reset_alternatives node['java']['reset_alternatives']
download_timeout node['java']['ark_download_timeout']
proxy node['java']['ark_proxy']
action :install
notifies :write, 'log[jdk-version-changed]', :immediately
end

if node['java']['set_default'] && platform_family?('debian')
include_recipe 'java::default_java_symlink'
end
57 changes: 57 additions & 0 deletions spec/corretto_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
require 'spec_helper'

describe 'java::corretto' do
let(:chef_run) do
runner = ChefSpec::SoloRunner.new
runner.node.override['java']['jdk_version'] = '11'
runner.node.override['java']['install_flavor'] = 'corretto'
runner.converge('java::default')
end

it 'should include the notify recipe' do
expect(chef_run).to include_recipe('java::notify')
end

it 'should include the set_java_home recipe' do
expect(chef_run).to include_recipe('java::set_java_home')
end

it 'should configure an java_oracle_install[jdk] resource' do
pending 'Testing LWRP use is not required at this time, this is tested post-converge.'
this_should_not_get_executed
end

it 'should notify jdk-version-change' do
expect(chef_run.java_oracle_install('jdk')).to notify('log[jdk-version-changed]')\
.to(:write).immediately
end

describe 'default-java' do
context 'ubuntu' do
let(:chef_run) do
runner = ChefSpec::SoloRunner.new(platform: 'ubuntu',
version: '18.04')
runner.node.override['java']['jdk_version'] = '11'
runner.node.override['java']['install_flavor'] = 'corretto'
runner.converge('java::default')
end

it 'includes default_java_symlink' do
expect(chef_run).to include_recipe('java::default_java_symlink')
end
end

context 'centos' do
let(:chef_run) do
runner = ChefSpec::SoloRunner.new(platform: 'centos', version: '7.5')
runner.node.override['java']['jdk_version'] = '11'
runner.node.override['java']['install_flavor'] = 'corretto'
runner.converge('java::default')
end

it 'does not include default_java_symlink' do
expect(chef_run).to_not include_recipe('java::default_java_symlink')
end
end
end
end
6 changes: 6 additions & 0 deletions test/fixtures/cookbooks/test/recipes/corretto11.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node.default['java']['jdk_version'] = '11'
node.default['java']['install_flavor'] = 'corretto'

include_recipe 'test::base'
include_recipe 'java::default'
include_recipe 'test::java_cert'
6 changes: 6 additions & 0 deletions test/fixtures/cookbooks/test/recipes/corretto8.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node.default['java']['jdk_version'] = '8'
node.default['java']['install_flavor'] = 'corretto'

include_recipe 'test::base'
include_recipe 'java::default'
include_recipe 'test::java_cert'
17 changes: 17 additions & 0 deletions test/integration/corretto-11/verify_corretto-11.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# the right version of java is installed
describe command('java -version 2>&1') do
its('stdout') { should match /11\.0\.3/ }
end

# alternatives were properly set
# disable this until we come up with a cross platform test
# describe command('update-alternatives --display jar') do
# its('stdout') { should match /\/usr\/lib\/jvm\/java-8-oracle-amd64\/bin\/jar/ }
# end

unless os.bsd?
# alternatives were properly set
describe command('update-alternatives --display jar') do
its('stdout') { should match %r{\/usr\/lib\/jvm\/java-11} } # https://rubular.com/r/H7J6J3q9GhJJ5A
end
end
16 changes: 16 additions & 0 deletions test/integration/corretto-8/verify_corretto-8.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# the right version of java is installed
describe command('java -version 2>&1') do
its('stdout') { should match /1\.8/ }
end

# alternatives were properly set
# disable this until we come up with a cross platform test
# describe command('update-alternatives --display jar') do
# its('stdout') { should match /\/usr\/lib\/jvm\/java-8-oracle-amd64\/bin\/jar/ }
# end

# jce is setup properly
describe command('java -jar /tmp/UnlimitedSupportJCETest.jar') do
its('stdout') { should match /isUnlimitedSupported=TRUE/ }
its('stdout') { should match /strength: 2147483647/ }
end

0 comments on commit aa17ed1

Please sign in to comment.