diff --git a/DistroInfo.cs b/DistroInfo.cs index 26c5224..3d46c3c 100644 --- a/DistroInfo.cs +++ b/DistroInfo.cs @@ -10,7 +10,9 @@ 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() { @@ -18,15 +20,9 @@ public class DistroInfo 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() { @@ -34,7 +30,9 @@ public class DistroInfo 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() { @@ -42,15 +40,29 @@ public class DistroInfo 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() { @@ -58,15 +70,19 @@ public class DistroInfo Family = "Arch", ImageName = "Arch-Linux-x86_64-cloudimg.qcow2", Url = "https://geo.mirror.pkgbuild.com/images/latest/", - Aliases = Array.Empty() + Aliases = Array.Empty(), + 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() + Url = "https://download.fedoraproject.org/pub/fedora/linux/releases/36/Cloud/x86_64/images/", + Aliases = Array.Empty(), + ChecksumFile = "Fedora-Cloud-36-1.5-x86_64-CHECKSUM", + ChecksumType = "sha256" }, new() { @@ -74,7 +90,9 @@ public class DistroInfo 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() + Aliases = Array.Empty(), + ChecksumFile = "Fedora-Cloud-37-1.7-x86_64-CHECKSUM", + ChecksumType = "sha256" }, new() { @@ -82,7 +100,29 @@ public class DistroInfo Family = "RHEL", ImageName = "CentOS-7-x86_64-GenericCloud.qcow2", Url = "https://cloud.centos.org/centos/7/images/", - Aliases = Array.Empty() + Aliases = Array.Empty(), + 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(), + 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(), + ChecksumFile = "CHECKSUM", + ChecksumType = "sha256" }, new() { @@ -90,7 +130,9 @@ public class DistroInfo Family = "RHEL", ImageName = "AlmaLinux-8-GenericCloud-latest.x86_64.qcow2", Url = "https://repo.almalinux.org/almalinux/8/cloud/x86_64/images/", - Aliases = Array.Empty() + Aliases = Array.Empty(), + ChecksumFile = "CHECKSUM", + ChecksumType = "sha256" }, new() { @@ -98,7 +140,9 @@ public class DistroInfo Family = "RHEL", ImageName = "AlmaLinux-9-GenericCloud-latest.x86_64.qcow2", Url = "https://repo.almalinux.org/almalinux/9/cloud/x86_64/images/", - Aliases = Array.Empty() + Aliases = Array.Empty(), + ChecksumFile = "CHECKSUM", + ChecksumType = "sha256" } }; @@ -114,10 +158,12 @@ public class DistroInfo return new DistroInfo() { Name = "local", - Aliases = Array.Empty(), Family = "local", + ImageName = localImage.Name, Url = "file://" + localImageDirectory?.FullName, - ImageName = localImage.Name + Aliases = Array.Empty(), + ChecksumFile = "", + ChecksumType = "" }; } @@ -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; } -} \ No newline at end of file + public required string ChecksumFile { get; set; } + public required string ChecksumType { get; set; } +} diff --git a/Dockerfile b/Dockerfile index 6f94841..921e730 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/Downloader.cs b/Downloader.cs index 211a656..bf71beb 100644 --- a/Downloader.cs +++ b/Downloader.cs @@ -22,7 +22,7 @@ public async Task 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}"); @@ -43,4 +43,4 @@ await AnsiConsole.Progress() return targetFile; } -} \ No newline at end of file +} diff --git a/README.md b/README.md index 549ad49..8355cdc 100644 --- a/README.md +++ b/README.md @@ -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 +``` + +For example: + +```bash +./build.sh 1.2.3 ~/build/ +``` + +Output dir defaults to `./build/`. diff --git a/build.sh b/build.sh index ce18e94..a7f8a1c 100755 --- a/build.sh +++ b/build.sh @@ -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"