Skip to content

Commit

Permalink
Update builtin images, add Ubuntu 20.04, Windows Server 2019 (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
timja committed Mar 31, 2021
1 parent 61bcd57 commit edbebdf
Show file tree
Hide file tree
Showing 17 changed files with 284 additions and 182 deletions.
60 changes: 60 additions & 0 deletions docs/init-scripts/windows-inbound-agent.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

choco install -y adoptopenjdk11

$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")

java -version

# Install Maven

choco install -y maven

$env:M2_HOME = [System.Environment]::GetEnvironmentVariable("M2_HOME","Machine")
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")

mvn --version

# Install Git

choco install -y git

$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")

#Disable git credential manager, get more details in https://support.cloudbees.com/hc/en-us/articles/221046888-Build-Hang-or-Fail-with-Git-for-Windows
git config --system --unset credential.helper

git --version

# Setup inbound agent

$jenkinsserverurl = $args[0]
$vmname = $args[1]
$secret = $args[2]

# Downloading jenkins agent jar
Write-Output "Downloading jenkins agent jar "
$slaveSource = $jenkinsserverurl + "jnlpJars/agent.jar"
$destSource = "C:\agent.jar"
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($slaveSource, $destSource)

# execute agent
Write-Output "Executing agent process "
$java="java"
$jar="-jar"
$jnlpUrl="-jnlpUrl"
$secretFlag="-secret"
$serverURL=$jenkinsserverurl+"computer/" + $vmname + '/jenkins-agent.jnlp'

# TODO look at porting the run as service part of the old script from https://raw.githubusercontent.com/Azure/jenkins/master/agents_scripts/Jenkins-Windows-Init-Script-Jnlp.ps1
while ($true) {
try {
# Launch
& $java -jar $destSource $secretFlag $secret $jnlpUrl $serverURL -noReconnect
}
catch [System.Exception] {
Write-Output $_.Exception.ToString()
}
Start-Sleep 10
}
27 changes: 27 additions & 0 deletions docs/init-scripts/windows-ssh.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

choco install -y adoptopenjdk11

$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")

java -version

# Install Maven

choco install -y maven

$env:M2_HOME = [System.Environment]::GetEnvironmentVariable("M2_HOME","Machine")
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")

mvn --version

# Install Git

choco install -y git

$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")

#Disable git credential manager, get more details in https://support.cloudbees.com/hc/en-us/articles/221046888-Build-Hang-or-Fail-with-Git-for-Windows
git config --system --unset credential.helper

git --version
Original file line number Diff line number Diff line change
Expand Up @@ -653,26 +653,28 @@ public static Map<String, Object> getTemplateProperties(AzureVMAgentTemplate tem
public static String getBasicInitScript(AzureVMAgentTemplate template) {
StringBuilder stringBuilder = new StringBuilder();
try {
String builtInImage = template.getBuiltInImage();
stringBuilder.append(
AzureVMManagementServiceDelegate.PRE_INSTALLED_TOOLS_SCRIPT
.get(template.getBuiltInImage()).get(Constants.INSTALL_JAVA));
.get(builtInImage).get(Constants.INSTALL_JAVA));
if (template.isInstallMaven()) {
stringBuilder.append(getSeparator(template.getOsType()));
stringBuilder.append(
AzureVMManagementServiceDelegate.PRE_INSTALLED_TOOLS_SCRIPT
.get(template.getBuiltInImage()).get(Constants.INSTALL_MAVEN));
.get(builtInImage).get(Constants.INSTALL_MAVEN));
}
if (template.isInstallGit()) {
stringBuilder.append(getSeparator(template.getOsType()));
stringBuilder.append(
AzureVMManagementServiceDelegate.PRE_INSTALLED_TOOLS_SCRIPT
.get(template.getBuiltInImage()).get(Constants.INSTALL_GIT));
.get(builtInImage).get(Constants.INSTALL_GIT));
}
if (template.getBuiltInImage().equals(Constants.UBUNTU_1604_LTS) && template.isInstallDocker()) {
if ((builtInImage.equals(Constants.UBUNTU_1604_LTS) || builtInImage.equals(Constants.UBUNTU_2004_LTS))
&& template.isInstallDocker()) {
stringBuilder.append(getSeparator(template.getOsType()));
stringBuilder.append(
AzureVMManagementServiceDelegate.PRE_INSTALLED_TOOLS_SCRIPT
.get(template.getBuiltInImage()).get(Constants.INSTALL_DOCKER)
.get(builtInImage).get(Constants.INSTALL_DOCKER)
.replace("${ADMIN}",
template.getVMCredentials().getUsername()));
}
Expand Down Expand Up @@ -1423,8 +1425,10 @@ public ListBoxModel doFillExistingStorageAccountNameItems(

public ListBoxModel doFillBuiltInImageItems() {
ListBoxModel model = new ListBoxModel();
model.add(Constants.WINDOWS_SERVER_2016);
model.add(Constants.UBUNTU_2004_LTS);
model.add(Constants.UBUNTU_1604_LTS);
model.add(Constants.WINDOWS_SERVER_2019);
model.add(Constants.WINDOWS_SERVER_2016);
return model;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1346,67 +1346,47 @@ private static Map<String, List<String>> getAvailableRoleSizes() {

private static Map<String, Map<String, String>> getDefaultImageProperties() {
final Map<String, Map<String, String>> imageProperties = new HashMap<>();
imageProperties.put(Constants.WINDOWS_SERVER_2016, new HashMap<String, String>());
imageProperties.put(Constants.UBUNTU_1604_LTS, new HashMap<String, String>());

imageProperties.get(Constants.WINDOWS_SERVER_2016).put(
Constants.DEFAULT_IMAGE_PUBLISHER, "MicrosoftWindowsServer");
imageProperties.get(Constants.WINDOWS_SERVER_2016).put(Constants.DEFAULT_IMAGE_OFFER, "WindowsServer");
imageProperties.get(Constants.WINDOWS_SERVER_2016).put(Constants.DEFAULT_IMAGE_SKU, "2016-Datacenter");
imageProperties.get(Constants.WINDOWS_SERVER_2016).put(Constants.DEFAULT_DOCKER_IMAGE_SKU, "2016-Datacenter-with-Containers");
imageProperties.get(Constants.WINDOWS_SERVER_2016).put(Constants.DEFAULT_IMAGE_VERSION, "latest");
imageProperties.get(Constants.WINDOWS_SERVER_2016).put(Constants.DEFAULT_OS_TYPE, Constants.OS_TYPE_WINDOWS);
imageProperties.get(Constants.WINDOWS_SERVER_2016).put(
Constants.DEFAULT_LAUNCH_METHOD, Constants.LAUNCH_METHOD_SSH);

imageProperties.get(Constants.UBUNTU_1604_LTS).put(Constants.DEFAULT_IMAGE_PUBLISHER, "Canonical");
imageProperties.get(Constants.UBUNTU_1604_LTS).put(Constants.DEFAULT_IMAGE_OFFER, "UbuntuServer");
imageProperties.get(Constants.UBUNTU_1604_LTS).put(Constants.DEFAULT_IMAGE_SKU, "16.04-LTS");
imageProperties.get(Constants.UBUNTU_1604_LTS).put(Constants.DEFAULT_DOCKER_IMAGE_SKU, "16.04-LTS");
imageProperties.get(Constants.UBUNTU_1604_LTS).put(Constants.DEFAULT_IMAGE_VERSION, "latest");
imageProperties.get(Constants.UBUNTU_1604_LTS).put(Constants.DEFAULT_OS_TYPE, Constants.OS_TYPE_LINUX);
imageProperties.get(Constants.UBUNTU_1604_LTS).put(
Constants.DEFAULT_LAUNCH_METHOD, Constants.LAUNCH_METHOD_SSH);
imageProperties.put(Constants.WINDOWS_SERVER_2016, new HashMap<>());
imageProperties.put(Constants.WINDOWS_SERVER_2019, new HashMap<>());
imageProperties.put(Constants.UBUNTU_1604_LTS, new HashMap<>());
imageProperties.put(Constants.UBUNTU_2004_LTS, new HashMap<>());

imageProperties(imageProperties, Constants.WINDOWS_SERVER_2016, "MicrosoftWindowsServer", "WindowsServer", "2016-Datacenter", "2016-Datacenter-with-Containers", Constants.OS_TYPE_WINDOWS);
imageProperties(imageProperties, Constants.WINDOWS_SERVER_2019, "MicrosoftWindowsServer", "WindowsServer", "2019-Datacenter", "2019-Datacenter-with-Containers", Constants.OS_TYPE_WINDOWS);
imageProperties(imageProperties, Constants.UBUNTU_1604_LTS, "Canonical", "UbuntuServer", "16.04-LTS", "16.04-LTS", Constants.OS_TYPE_LINUX);
imageProperties(imageProperties, Constants.UBUNTU_2004_LTS, "canonical", "0001-com-ubuntu-server-focal", "20_04-lts-gen2", "20_04-lts-gen2", Constants.OS_TYPE_LINUX);
return imageProperties;
}

private static void imageProperties(
Map<String, Map<String, String>> imageProperties,
String imageName,
String defaultImagePublisher,
String offer,
String sku,
String dockerImageSku,
String osType
) {
imageProperties.get(imageName).put(Constants.DEFAULT_IMAGE_PUBLISHER, defaultImagePublisher);
imageProperties.get(imageName).put(Constants.DEFAULT_IMAGE_OFFER, offer);
imageProperties.get(imageName).put(Constants.DEFAULT_IMAGE_SKU, sku);
imageProperties.get(imageName).put(Constants.DEFAULT_DOCKER_IMAGE_SKU, dockerImageSku);
imageProperties.get(imageName).put(Constants.DEFAULT_IMAGE_VERSION, "latest");
imageProperties.get(imageName).put(Constants.DEFAULT_OS_TYPE, osType);
imageProperties.get(imageName).put(Constants.DEFAULT_LAUNCH_METHOD, Constants.LAUNCH_METHOD_SSH);
}

private static Map<String, Map<String, String>> getPreInstalledToolsScript() {
final Map<String, Map<String, String>> tools = new HashMap<>();
tools.put(Constants.WINDOWS_SERVER_2016, new HashMap<String, String>());
tools.put(Constants.UBUNTU_1604_LTS, new HashMap<String, String>());
tools.put(Constants.WINDOWS_SERVER_2016, new HashMap<>());
tools.put(Constants.WINDOWS_SERVER_2019, new HashMap<>());
tools.put(Constants.UBUNTU_1604_LTS, new HashMap<>());
tools.put(Constants.UBUNTU_2004_LTS, new HashMap<>());
try {
tools.get(Constants.WINDOWS_SERVER_2016).put(
Constants.INSTALL_JAVA,
IOUtils.toString(AzureVMManagementServiceDelegate.class.getResourceAsStream(
INSTALL_JAVA_WINDOWS_FILENAME), "UTF-8"));
tools.get(Constants.WINDOWS_SERVER_2016).put(
Constants.INSTALL_MAVEN,
IOUtils.toString(AzureVMManagementServiceDelegate.class.getResourceAsStream(
INSTALL_MAVEN_WINDOWS_FILENAME), "UTF-8"));
tools.get(Constants.WINDOWS_SERVER_2016).put(
Constants.INSTALL_GIT,
IOUtils.toString(AzureVMManagementServiceDelegate.class.getResourceAsStream(
INSTALL_GIT_WINDOWS_FILENAME), "UTF-8"));
tools.get(Constants.WINDOWS_SERVER_2016).put(
Constants.INSTALL_JNLP,
IOUtils.toString(AzureVMManagementServiceDelegate.class.getResourceAsStream(
INSTALL_JNLP_WINDOWS_FILENAME), "UTF-8"));
tools.get(Constants.UBUNTU_1604_LTS).put(
Constants.INSTALL_JAVA,
IOUtils.toString(AzureVMManagementServiceDelegate.class.getResourceAsStream(
INSTALL_JAVA_UBUNTU_FILENAME), "UTF-8"));
tools.get(Constants.UBUNTU_1604_LTS).put(
Constants.INSTALL_MAVEN,
IOUtils.toString(AzureVMManagementServiceDelegate.class.getResourceAsStream(
INSTALL_MAVEN_UBUNTU_FILENAME), "UTF-8"));
tools.get(Constants.UBUNTU_1604_LTS).put(
Constants.INSTALL_GIT,
IOUtils.toString(AzureVMManagementServiceDelegate.class.getResourceAsStream(
INSTALL_GIT_UBUNTU_FILENAME), "UTF-8"));
tools.get(Constants.UBUNTU_1604_LTS).put(
Constants.INSTALL_DOCKER,
IOUtils.toString(AzureVMManagementServiceDelegate.class.getResourceAsStream(
INSTALL_DOCKER_UBUNTU_FILENAME), "UTF-8"));
windows(Constants.WINDOWS_SERVER_2016, tools);
windows(Constants.WINDOWS_SERVER_2019, tools);
ubuntu(Constants.UBUNTU_1604_LTS, tools);
ubuntu(Constants.UBUNTU_2004_LTS, tools);

return tools;
} catch (IOException e) {
Expand All @@ -1418,6 +1398,44 @@ private static Map<String, Map<String, String>> getPreInstalledToolsScript() {
}
}

private static void ubuntu(String imageName, Map<String, Map<String, String>> tools) throws IOException {
tools.get(imageName).put(
Constants.INSTALL_JAVA,
IOUtils.toString(AzureVMManagementServiceDelegate.class.getResourceAsStream(
INSTALL_JAVA_UBUNTU_FILENAME), StandardCharsets.UTF_8));
tools.get(imageName).put(
Constants.INSTALL_MAVEN,
IOUtils.toString(AzureVMManagementServiceDelegate.class.getResourceAsStream(
INSTALL_MAVEN_UBUNTU_FILENAME), StandardCharsets.UTF_8));
tools.get(imageName).put(
Constants.INSTALL_GIT,
IOUtils.toString(AzureVMManagementServiceDelegate.class.getResourceAsStream(
INSTALL_GIT_UBUNTU_FILENAME), StandardCharsets.UTF_8));
tools.get(imageName).put(
Constants.INSTALL_DOCKER,
IOUtils.toString(AzureVMManagementServiceDelegate.class.getResourceAsStream(
INSTALL_DOCKER_UBUNTU_FILENAME), StandardCharsets.UTF_8));
}

private static void windows(String imageName, Map<String, Map<String, String>> tools) throws IOException {
tools.get(imageName).put(
Constants.INSTALL_JAVA,
IOUtils.toString(AzureVMManagementServiceDelegate.class.getResourceAsStream(
INSTALL_JAVA_WINDOWS_FILENAME), StandardCharsets.UTF_8));
tools.get(imageName).put(
Constants.INSTALL_MAVEN,
IOUtils.toString(AzureVMManagementServiceDelegate.class.getResourceAsStream(
INSTALL_MAVEN_WINDOWS_FILENAME), StandardCharsets.UTF_8));
tools.get(imageName).put(
Constants.INSTALL_GIT,
IOUtils.toString(AzureVMManagementServiceDelegate.class.getResourceAsStream(
INSTALL_GIT_WINDOWS_FILENAME), StandardCharsets.UTF_8));
tools.get(imageName).put(
Constants.INSTALL_JNLP,
IOUtils.toString(AzureVMManagementServiceDelegate.class.getResourceAsStream(
INSTALL_JNLP_WINDOWS_FILENAME), StandardCharsets.UTF_8));
}

/**
* Gets map of Azure datacenter locations which supports Persistent VM role.
* If it can't fetch the data then it will return a default hardcoded set
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/microsoft/azure/vmagent/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ public final class Constants {
/**
* Built In Image.
*/
public static final String WINDOWS_SERVER_2019 = "Windows Server 2019";
public static final String WINDOWS_SERVER_2016 = "Windows Server 2016";
public static final String UBUNTU_1604_LTS = "Ubuntu 16.04 LTS";
public static final String UBUNTU_2004_LTS = "Ubuntu 20.04 LTS";

/**
* ResourceGroup reference type.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,25 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">

<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<f:section title="${%Azure_Agent_Configuration}">
<f:block>
<b>${%FQDN}</b>: ${instance.getPublicDNSName()}
</f:block>
<f:block>
<div>
<p><strong>${%FQDN}</strong>: ${instance.getPublicDNSName()}</p>
<p><strong>${%Public_IP}</strong>: </p>
<j:choose>
<j:when test="${!empty(instance.getPublicIP())}">
${instance.getPublicIP()}
</j:when>
<j:when test="${empty(instance.getPublicIP())}">
<input type="hidden" value="${instance.getNodeName()}" name="vmAgentName" />

<div style="float:left">
<b>${%Public_IP}</b>:
<input type="button" value="${%Attach_Public_IP}" class="yui-button validate-button" onclick="validateButton('${descriptor.descriptorFullUrl}/attachPublicIP','vmAgentName',this)" />
</div>
<div style="display:none;float:left">
<img src="${imagesURL}/spinner.gif" /> ${%Attaching_Public_IP}
</div>
<j:choose>
<j:when test="${!empty(instance.getPublicIP())}">
<div style="float:left">${instance.getPublicIP()}</div>
</j:when>
<j:when test="${empty(instance.getPublicIP())}">
<input type="hidden" value="${instance.getNodeName()}" name="vmAgentName" />

<div style="float:left">
<input type="button" value="${%Attach_Public_IP}" class="yui-button validate-button" onclick="validateButton('${descriptor.descriptorFullUrl}/attachPublicIP','vmAgentName',this)" />
</div>
<div style="display:none;float:left">
<img src="${imagesURL}/spinner.gif" /> ${%Attaching_Public_IP}
</div>
<div style="float:left"><!-- this is where the error message goes --></div>
</j:when>
</j:choose>
</div>
</f:block>
<f:block>
<b>${%Private_IP}</b>: ${instance.getPrivateIP()}
</f:block>
<div><!-- this is where the error message goes --></div>
</j:when>
</j:choose>
<p><strong>${%Private_IP}</strong>: ${instance.getPrivateIP()}</p>
</f:section>

</j:jelly>
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<f:checkbox/>
</f:entry>

<f:entry title="Install Maven (V3.5.2)" field="installMaven">
<f:entry title="Install Maven (v3.6.3)" field="installMaven">
<f:checkbox/>
</f:entry>

Expand Down
Loading

0 comments on commit edbebdf

Please sign in to comment.