Skip to content

Commit

Permalink
add support for installing QEMU (#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
gdams authored Oct 15, 2024
1 parent 655c495 commit 09fa01e
Show file tree
Hide file tree
Showing 18 changed files with 86 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def myCloud = new AzureVMCloudBuilder()
.withInstallGit(true)
.withInstallMaven(true)
.withInstallDocker(true)
.withInstallQemu(true)
.endBuiltInImage()
.withAdminCredential("<your admin credential ID>")
.endTemplate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ public int hashCode() {

private boolean installDocker;

private boolean installQemu;

private boolean trustedLaunch;

private final String osType;
Expand Down Expand Up @@ -386,6 +388,7 @@ public int hashCode() {
private transient boolean isInstallDocker;
private transient boolean isInstallMaven;
private transient boolean isInstallGit;
private transient boolean isInstallQemu;

private transient String image;
private transient String imageId;
Expand Down Expand Up @@ -760,6 +763,12 @@ public static String getBasicInitScript(AzureVMAgentTemplate template) {
AzureVMManagementServiceDelegate.PRE_INSTALLED_TOOLS_SCRIPT
.get(builtInImage).get(Constants.INSTALL_MAVEN));
}
if (template.isInstallQemu()) {
stringBuilder.append(getSeparator(template.getOsType()));
stringBuilder.append(
AzureVMManagementServiceDelegate.PRE_INSTALLED_TOOLS_SCRIPT
.get(builtInImage).get(Constants.INSTALL_QEMU));

Check warning on line 770 in src/main/java/com/microsoft/azure/vmagent/AzureVMAgentTemplate.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 766-770 are not covered by tests
}
if (template.isInstallGit()) {
stringBuilder.append(getSeparator(template.getOsType()));
stringBuilder.append(
Expand Down Expand Up @@ -864,6 +873,10 @@ private Object readResolve() {
installMaven = true;
}

if (isInstallQemu) {

Check warning on line 876 in src/main/java/com/microsoft/azure/vmagent/AzureVMAgentTemplate.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 876 is only partially covered, one branch is missing
installQemu = true;

Check warning on line 877 in src/main/java/com/microsoft/azure/vmagent/AzureVMAgentTemplate.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 877 is not covered by tests
}

if (imageReference == null) {
imageReference = new ImageReferenceTypeClass();
}
Expand Down Expand Up @@ -1083,6 +1096,11 @@ public void setInstallMaven(boolean installMaven) {
this.installMaven = installMaven;
}

@DataBoundSetter
public void setInstallQemu(boolean installQemu) {
this.installQemu = installQemu;
}

@DataBoundSetter
public void setInstallDocker(boolean installDocker) {
this.installDocker = installDocker;
Expand All @@ -1100,6 +1118,10 @@ public boolean isInstallDocker() {
return installDocker;
}

public boolean isInstallQemu() {
return installQemu;
}

public String getOsType() {
return osType;
}
Expand Down Expand Up @@ -1347,6 +1369,7 @@ public BuiltInImage getBuiltInImageInside() {
.withInstallGit(isInstallGit())
.withInstallDocker(isInstallDocker())
.withInstallMaven(isInstallMaven())
.withInstallQemu(isInstallQemu())

Check warning on line 1372 in src/main/java/com/microsoft/azure/vmagent/AzureVMAgentTemplate.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 1372 is not covered by tests
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ public final class AzureVMManagementServiceDelegate {

private static final String INSTALL_MAVEN_WINDOWS_FILENAME = "windowsInstallMavenScript.ps1";

private static final String INSTALL_QEMU_WINDOWS_FILENAME = "windowsInstallQemuScript.ps1";

private static final String INSTALL_GIT_UBUNTU_FILENAME = "ubuntuInstallGitScript.sh";

private static final String INSTALL_JAVA_UBUNTU_FILENAME = "ubuntuInstallJavaScript.sh";
Expand All @@ -175,6 +177,8 @@ public final class AzureVMManagementServiceDelegate {

private static final String INSTALL_DOCKER_UBUNTU_FILENAME = "ubuntuInstallDockerScript.sh";

private static final String INSTALL_QEMU_UBUNTU_FILENAME = "ubuntuInstallQemuScript.sh";

private static final String PRE_INSTALL_SSH_FILENAME = "sshInit.ps1";

private final AzureResourceManager azureClient;
Expand Down Expand Up @@ -1626,6 +1630,9 @@ private static void ubuntu(String imageName, Map<String, Map<String, String>> to
tools.get(imageName).put(
Constants.INSTALL_MAVEN,
loadScript(INSTALL_MAVEN_UBUNTU_FILENAME));
tools.get(imageName).put(
Constants.INSTALL_QEMU,
loadScript(INSTALL_QEMU_UBUNTU_FILENAME));
tools.get(imageName).put(
Constants.INSTALL_GIT,
loadScript(INSTALL_GIT_UBUNTU_FILENAME));
Expand All @@ -1641,6 +1648,9 @@ private static void windows(String imageName, Map<String, Map<String, String>> t
tools.get(imageName).put(
Constants.INSTALL_MAVEN,
loadScript(INSTALL_MAVEN_WINDOWS_FILENAME));
tools.get(imageName).put(
Constants.INSTALL_QEMU,
loadScript(INSTALL_QEMU_WINDOWS_FILENAME));
tools.get(imageName).put(

Check warning on line 1654 in src/main/java/com/microsoft/azure/vmagent/AzureVMManagementServiceDelegate.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 1635-1654 are not covered by tests
Constants.INSTALL_GIT,
loadScript(INSTALL_GIT_WINDOWS_FILENAME));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public AzureVMAgentTemplate build() {
azureVMAgentTemplate.setInstallGit(fluent.getBuiltInImage().isInstallGit());
azureVMAgentTemplate.setInstallMaven(fluent.getBuiltInImage().isInstallMaven());
azureVMAgentTemplate.setInstallDocker(fluent.getBuiltInImage().isInstallDocker());
azureVMAgentTemplate.setInstallQemu(fluent.getBuiltInImage().isInstallQemu());

Check warning on line 145 in src/main/java/com/microsoft/azure/vmagent/builders/AzureVMTemplateBuilder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 145 is not covered by tests
azureVMAgentTemplate.setUsePrivateIP(fluent.getAdvancedImage().isUsePrivateIP());
azureVMAgentTemplate.setEnableMSI(fluent.getAdvancedImage().isEnableMSI());
azureVMAgentTemplate.setEnableUAMI(fluent.getAdvancedImage().isEnableUAMI());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ public class BuiltInImage {

private boolean isInstallDocker;

private boolean isInstallQemu;

public BuiltInImage(String builtInImage,
boolean isInstallGit,
boolean isInstallMaven,
boolean isInstallDocker) {
boolean isInstallDocker,
boolean isInstallQemu) {
this.builtInImage = builtInImage;
this.isInstallGit = isInstallGit;
this.isInstallMaven = isInstallMaven;
this.isInstallDocker = isInstallDocker;
this.isInstallQemu = isInstallQemu;
}

public String getBuiltInImage() {
Expand All @@ -35,4 +39,8 @@ public boolean isInstallMaven() {
public boolean isInstallDocker() {
return isInstallDocker;
}

public boolean isInstallQemu() {
return isInstallQemu;

Check warning on line 44 in src/main/java/com/microsoft/azure/vmagent/builders/BuiltInImage.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 19-44 are not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public BuiltInImageBuilder(BuiltInImage image) {
fluent.withInstallDocker(image.isInstallDocker());
fluent.withInstallGit(image.isInstallGit());
fluent.withInstallMaven(image.isInstallMaven());
fluent.withInstallQemu(image.isInstallQemu());
}

public BuiltInImageBuilder(BuiltInImageFluent<?> fluent) {
Expand All @@ -27,12 +28,14 @@ public BuiltInImageBuilder(BuiltInImageFluent<?> fluent, BuiltInImage image) {
fluent.withInstallDocker(image.isInstallDocker());
fluent.withInstallGit(image.isInstallGit());
fluent.withInstallMaven(image.isInstallMaven());
fluent.withInstallQemu(image.isInstallQemu());
}

public BuiltInImage build() {
return new BuiltInImage(fluent.getBuiltInImage(),
fluent.isInstallGit(),
fluent.isInstallMaven(),
fluent.isInstallDocker());
fluent.isInstallDocker(),
fluent.isInstallQemu());

Check warning on line 39 in src/main/java/com/microsoft/azure/vmagent/builders/BuiltInImageBuilder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 18-39 are not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ public class BuiltInImageFluent<T extends BuiltInImageFluent<T>> {

private boolean isInstallDocker;

private boolean isInstallQemu;

public BuiltInImageFluent() {
builtInImage = Constants.WINDOWS_SERVER_2016;
isInstallDocker = false;
isInstallMaven = false;
isInstallGit = false;
isInstallQemu = false;
}

//CHECKSTYLE:OFF
Expand All @@ -38,6 +41,11 @@ public T withInstallDocker(boolean installDocker) {
this.isInstallDocker = installDocker;
return (T) this;
}

public T withInstallQemu(boolean installQemu) {
this.isInstallQemu = installQemu;
return (T) this;
}
//CHECKSTYLE:ON

public String getBuiltInImage() {
Expand All @@ -55,4 +63,8 @@ public boolean isInstallMaven() {
public boolean isInstallDocker() {
return isInstallDocker;
}

public boolean isInstallQemu() {
return isInstallQemu;

Check warning on line 68 in src/main/java/com/microsoft/azure/vmagent/builders/BuiltInImageFluent.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 21-68 are not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public final class Constants {
*/
public static final String INSTALL_JAVA = "Java";
public static final String INSTALL_MAVEN = "Maven";
public static final String INSTALL_QEMU = "QEMU";
public static final String INSTALL_GIT = "Git";
public static final String INSTALL_DOCKER = "Docker";
public static final String INSTALL_JNLP = "Jnlp";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static boolean checkSame(AzureVMAgentTemplate a, AzureVMAgentTemplate b)
&& a.isInstallDocker() == b.isInstallDocker()
&& a.isInstallGit() == b.isInstallGit()
&& a.isInstallMaven() == b.isInstallMaven()
&& a.isInstallQemu() == b.isInstallQemu()

Check warning on line 30 in src/main/java/com/microsoft/azure/vmagent/util/TemplateUtil.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 30 is not covered by tests
&& a.getImageReference().getType() == b.getImageReference().getType()
&& StringUtils.equals(a.getImageReference().getUri(), b.getImageReference().getUri())
&& StringUtils.equals(a.getOsType(), b.getOsType())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@
<f:entry title="Install Docker" field="installDocker">
<f:checkbox/>
</f:entry>

<f:entry title="Install QEMU" field="installQemu">
<f:checkbox/>
</f:entry>
</f:section>
</f:radioBlock>

Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/scripts/ubuntuInstallQemuScript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

# Install QEMU

set -ex

sudo DEBIAN_FRONTEND=noninteractive apt-get install -y qemu-user-static

"qemu-$(uname -m)-static" --version
5 changes: 5 additions & 0 deletions src/main/resources/scripts/windowsInstallQemuScript.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
choco install -y qemu

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

qemu-system-x86_64 --version
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public void importAdvancedConfiguration() {
assertThat(template.isInstallDocker(), is(false));
assertThat(template.isInstallGit(), is(false));
assertThat(template.isInstallMaven(), is(false));
assertThat(template.isInstallQemu(), is(false));

assertThat(template.getLabels(), is("linux"));
assertThat(template.getLocation(), is("UK South"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void importBasicConfiguration() {
assertThat(template.isInstallDocker(), is(true));
assertThat(template.isInstallGit(), is(true));
assertThat(template.isInstallMaven(), is(true));
assertThat(template.isInstallQemu(), is(true));

assertThat(template.getLabels(), is("ubuntu"));
assertThat(template.getLocation(), is("East US"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<isInstallGit>false</isInstallGit>
<isInstallMaven>false</isInstallMaven>
<isInstallDocker>false</isInstallDocker>
<isInstallQemu>false</isInstallQemu>
<osType>Linux</osType>
<imagePublisher>Canonical</imagePublisher>
<imageOffer>UbuntuServer</imageOffer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jenkins:
installDocker: false
installGit: false
installMaven: false
installQemu: false
jvmOptions: "-xmx"
labels: "linux"
location: "UK South"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jenkins:
installDocker: true
installGit: true
installMaven: true
installQemu: true
labels: "ubuntu"
location: "East US"
newStorageAccountName: "agent-storage"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
installDocker: true
installGit: true
installMaven: true
installQemu: true
labels: "ubuntu"
launcher: "ssh"
location: "East US"
Expand Down

0 comments on commit 09fa01e

Please sign in to comment.