Skip to content

Commit

Permalink
Merge branch 'maxfeature'
Browse files Browse the repository at this point in the history
  • Loading branch information
wubbl0rz committed Apr 7, 2023
2 parents 75436c4 + 1c3ea7d commit 3f9b7a8
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 32 deletions.
96 changes: 72 additions & 24 deletions DistroInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,95 +10,139 @@ public class DistroInfo
Family = "Debian",
ImageName = "debian-11-genericcloud-amd64.qcow2",
Url = "https://cloud.debian.org/images/cloud/bullseye/latest/",
Aliases = new[] { "Bullseye" }
Aliases = new[] { "Bullseye" },
ChecksumFile = "SHA512SUMS",
ChecksumType = "sha512"
},
new()
{
Name = "Debian10",
Family = "Debian",
ImageName = "debian-10-genericcloud-amd64.qcow2",
Url = "https://cloud.debian.org/images/cloud/buster/latest/",
Aliases = new[] { "Buster" }
},
new()
{
Name = "Debian9",
Family = "Debian",
ImageName = "debian-9-genericcloud-amd64.qcow2",
Url = "https://cloud.debian.org/images/cloud/stretch/latest/",
Aliases = new[] { "Stretch" }
Aliases = new[] { "Buster" },
ChecksumFile = "SHA512SUMS",
ChecksumType = "sha512"
},
new()
{
Name = "Ubuntu1804",
Family = "Ubuntu",
ImageName = "bionic-server-cloudimg-amd64.img",
Url = "https://cloud-images.ubuntu.com/bionic/current/",
Aliases = new[] { "Bionic Beaver", "Bionic" }
Aliases = new[] { "Bionic Beaver", "Bionic" },
ChecksumFile = "SHA256SUMS",
ChecksumType = "sha256"
},
new()
{
Name = "Ubuntu2004",
Family = "Ubuntu",
ImageName = "focal-server-cloudimg-amd64.img",
Url = "https://cloud-images.ubuntu.com/focal/current/",
Aliases = new[] { "Focal Fossal", "Focal" }
Aliases = new[] { "Focal Fossal", "Focal" },
ChecksumFile = "SHA256SUMS",
ChecksumType = "sha256"
},
new()
{
Name = "Ubuntu2204",
Family = "Ubuntu",
ImageName = "focal-server-cloudimg-amd64.img",
ImageName = "jammy-server-cloudimg-amd64.img",
Url = "https://cloud-images.ubuntu.com/jammy/current/",
Aliases = new[] { "Jammy Jellyfish", "Jammy" }
Aliases = new[] { "Jammy Jellyfish", "Jammy" },
ChecksumFile = "SHA256SUMS",
ChecksumType = "sha256"
},
new()
{
Name = "Ubuntu2304",
Family = "Ubuntu",
ImageName = "lunar-server-cloudimg-amd64.img",
Url = "https://cloud-images.ubuntu.com/lunar/current/",
Aliases = new[] { "Lunar Lobster", "Lunar" },
ChecksumFile = "SHA256SUMS",
ChecksumType = "sha256"
},
new()
{
Name = "Arch",
Family = "Arch",
ImageName = "Arch-Linux-x86_64-cloudimg.qcow2",
Url = "https://geo.mirror.pkgbuild.com/images/latest/",
Aliases = Array.Empty<string>()
Aliases = Array.Empty<string>(),
ChecksumFile = "Arch-Linux-x86_64-cloudimg.qcow2.SHA256",
ChecksumType = "sha256"
},
new()
{
Name = "Fedora36",
Family = "Fedora",
ImageName = "Fedora-Cloud-Base-36-1.5.x86_64.qcow2",
Url = "https://download.fedoraproject.org/pub/fedora/linux/releases/37/Cloud/x86_64/images/",
Aliases = Array.Empty<string>()
Url = "https://download.fedoraproject.org/pub/fedora/linux/releases/36/Cloud/x86_64/images/",
Aliases = Array.Empty<string>(),
ChecksumFile = "Fedora-Cloud-36-1.5-x86_64-CHECKSUM",
ChecksumType = "sha256"
},
new()
{
Name = "Fedora37",
Family = "Fedora",
ImageName = "Fedora-Cloud-Base-37-1.7.x86_64.qcow2",
Url = "https://download.fedoraproject.org/pub/fedora/linux/releases/37/Cloud/x86_64/images/",
Aliases = Array.Empty<string>()
Aliases = Array.Empty<string>(),
ChecksumFile = "Fedora-Cloud-37-1.7-x86_64-CHECKSUM",
ChecksumType = "sha256"
},
new()
{
Name = "CentOS7",
Family = "RHEL",
ImageName = "CentOS-7-x86_64-GenericCloud.qcow2",
Url = "https://cloud.centos.org/centos/7/images/",
Aliases = Array.Empty<string>()
Aliases = Array.Empty<string>(),
ChecksumFile = "sha256sum.txt",
ChecksumType = "sha256"
},
new()
{
Name = "Rocky8",
Family = "RHEL",
ImageName = "Rocky-8-GenericCloud.latest.x86_64.qcow2",
Url = "https://download.rockylinux.org/pub/rocky/8/images/x86_64/",
Aliases = Array.Empty<string>(),
ChecksumFile = "CHECKSUM",
ChecksumType = "sha256"
},
new()
{
Name = "Rocky9",
Family = "RHEL",
ImageName = "Rocky-9-GenericCloud.latest.x86_64.qcow2",
Url = "https://download.rockylinux.org/pub/rocky/9/images/x86_64/",
Aliases = Array.Empty<string>(),
ChecksumFile = "CHECKSUM",
ChecksumType = "sha256"
},
new()
{
Name = "Alma8",
Family = "RHEL",
ImageName = "AlmaLinux-8-GenericCloud-latest.x86_64.qcow2",
Url = "https://repo.almalinux.org/almalinux/8/cloud/x86_64/images/",
Aliases = Array.Empty<string>()
Aliases = Array.Empty<string>(),
ChecksumFile = "CHECKSUM",
ChecksumType = "sha256"
},
new()
{
Name = "Alma9",
Family = "RHEL",
ImageName = "AlmaLinux-9-GenericCloud-latest.x86_64.qcow2",
Url = "https://repo.almalinux.org/almalinux/9/cloud/x86_64/images/",
Aliases = Array.Empty<string>()
Aliases = Array.Empty<string>(),
ChecksumFile = "CHECKSUM",
ChecksumType = "sha256"
}
};

Expand All @@ -114,10 +158,12 @@ public class DistroInfo
return new DistroInfo()
{
Name = "local",
Aliases = Array.Empty<string>(),
Family = "local",
ImageName = localImage.Name,
Url = "file://" + localImageDirectory?.FullName,
ImageName = localImage.Name
Aliases = Array.Empty<string>(),
ChecksumFile = "",
ChecksumType = ""
};
}

Expand All @@ -126,4 +172,6 @@ public class DistroInfo
public required string ImageName { get; set; }
public required string Url { get; set; }
public required string[] Aliases { get; set; }
}
public required string ChecksumFile { get; set; }
public required string ChecksumType { get; set; }
}
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ FROM scratch as output
COPY --from=build /App/build/VmChamp /VmChamp

FROM build as release
COPY --from=build /App/build/VmChamp /VmChamp

4 changes: 2 additions & 2 deletions Downloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task<FileInfo> DownloadAsync(DistroInfo distroInfo, bool force = fa
return targetFile;
}

var uri = new Uri($"{distroInfo.Url}/{distroInfo.ImageName}");
var uri = new Uri(new Uri(distroInfo.Url), distroInfo.ImageName);

AnsiConsole.WriteLine($"Download: {uri}");

Expand All @@ -43,4 +43,4 @@ await AnsiConsole.Progress()

return targetFile;
}
}
}
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,19 @@ Commands:
list, ls, ps list all existing vms
images, os get a list of all available os images
```

## 🏗️ Build

Simply use the included bash script as follows:

```bash
./build.sh <version> <output dir>
```

For example:

```bash
./build.sh 1.2.3 ~/build/
```

Output dir defaults to `./build/`.
53 changes: 47 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,52 @@
#!/bin/bash

# exit on fail
set -e

# set colors
RED="\033[0;31m"
GREEN="\033[0;32m"
BLUE="\033[0;34m"
BOLD_BLUE='\033[1;34m'
NC='\033[0m'

# check shell args
TARGET_VERSION="${1:-1.0.0}"
OUTPUT_DIR="${2:-'/tmp'}"
if [[ ! "$TARGET_VERSION" =~ ^([0-9].){2}[0-9] ]]; then
echo -e "${RED}${TARGET_VERSION} is not a valid version. Please use semantic versioning (e.g. \"1.2.3\")${NC}"
exit 1
fi
OUTPUT_DIR="${2:-build}"
if [ ! -d "$OUTPUT_DIR" ]; then
mkdir -p "$OUTPUT_DIR"
fi

OUTPUT_DIR_REALPATH=$(realpath "$OUTPUT_DIR")

echo -ne "${BLUE}🏗️ Docker remove old container...${NC}"
docker rm -f vmchamp > /dev/null
echo -e "${GREEN} done${NC}"

# build image
echo -e "${BOLD_BLUE}ℹ️ Build version: ${TARGET_VERSION}${NC}"
echo -e "${BOLD_BLUE}ℹ️ Output dir: ${OUTPUT_DIR_REALPATH}/${NC}"
echo ""

echo -ne "${BLUE}🏗️ Docker build image...${NC}"
docker build --build-arg TARGET_VERSION="$TARGET_VERSION" -t vmchamp:latest .
echo -e "${GREEN} done${NC}"

echo -ne "${BLUE}🏗️ Docker create container...${NC}"
docker create --name vmchamp -q vmchamp:latest exit 0 > /dev/null
echo -e "${GREEN} done${NC}"

echo -ne "${BLUE}🏗️ Docker copy binary...${NC}"
docker cp -q vmchamp:/VmChamp "$OUTPUT_DIR/VmChamp" > /dev/null
echo -e "${GREEN} done${NC}"

echo "BUILD VERSION $TARGET_VERSION"
echo -ne "${BLUE}🏗️ Docker remove container...${NC}"
docker rm -f vmchamp > /dev/null
echo -e "${GREEN} done${NC}"

ID=$(docker build --build-arg TARGET_VERSION="$TARGET_VERSION" . -q | cut -d ":" -f 2)
docker run --name tmpbuild "$ID"
docker cp tmpbuild:/App/build/VmChamp "$OUTPUT_DIR"
docker rm tmpbuild
echo ""
echo -e "${GREEN}✅ Build successful${NC} - Binary available at $OUTPUT_DIR_REALPATH/VmChamp"

0 comments on commit 3f9b7a8

Please sign in to comment.