This repository contains my own implementation of a coding exercise inspired by a public assignment. Canonical is not affiliated with this repository.
Ubuntu Fetcher is a cross-platform C++17 CLI utility that queries Canonical's Simplestreams JSON feed to retrieve Ubuntu cloud image information.
It extracts and displays:
- All available Ubuntu releases
- The current Ubuntu LTS version
- The SHA256 hash of the
disk1.imgfor a given release
- Written in C++17
- Uses libcurl for HTTP downloads
- Uses nlohmann::json for JSON parsing (header-only)
- Implements local caching (via
cache.json) valid for 1 hour - Download is performed asynchronously in the background using
std::async - Fully portable: builds on Linux, macOS, and Windows (via CMake)
- C++17 compiler (e.g.
g++ >= 9,clang >= 10, or MSVC >= 2019) - CMake ≥ 3.14
- libcurl development package
-
Note:
nlohmann::jsonis already vendored inlibs/json/json.hpp.
No additional installations are required for the JSON library.
sudo apt update
sudo apt install build-essential cmake libcurl4-openssl-dev-
Use Visual Studio 2019 (or later) which supports C++17.
-
CMake can be downloaded and installed.
-
libcurl can be installed via vcpkg or downloaded precompiled.
For example, with vcpkg:
vcpkg install curl
Clone the repository (or use your local copy) and then:
git clone https://github.com/kenhero/ubuntu-fetcher.git
cd ubuntu-fetcher
mkdir build && cd build
cmake ..
makeThe binary will be located in ./build/bin/ubuntu_fetcher.
Run the executable from the terminal with one of the following options:
./ubuntu_fetcher --list # List all supported Ubuntu releases
./ubuntu_fetcher --lts # Display the current Ubuntu LTS version
./ubuntu_fetcher --sha256 22.04 # Get the SHA256 of disk1.img for a given release
**Examples**
```bash
$ ./ubuntu_fetcher --lts
22.04 LTS (Jammy Jellyfish)
$ ./ubuntu_fetcher --sha256 22.04
SHA256(disk1.img) = 4f3a...9bd2
- The first run downloads metadata from:
https://cloud-images.ubuntu.com/releases/streams/v1/com.ubuntu.cloud:released:download.json - The metadata is cached to
./cache.jsonfor 1 hour. - A background task updates the cache after startup.
.
├── include/
│ ├── UbuntuImageFetcher.h # Abstract interface
│ └── SimplestreamsUbuntuFetcher.h # Main implementation
├── src/
│ ├── main.cpp # CLI entry point
│ └── SimplestreamsUbuntuFetcher.cpp # Implementation with async download and caching
├── libs/
│ └── json/
│ └── json.hpp # nlohmann::json (header-only)
├── CMakeLists.txt
├── README.md
├── LICENSE
└── cache.json # (generated; ignored via .gitignore)
This project includes convenience scripts for building, running, and testing:
Builds the entire project from scratch:
./build.shRuns the executable with custom CLI arguments:
./run.sh --list
./run.sh --sha256 22.04Executes a basic smoke test suite:
./test.shEach script performs checks to ensure the executable exists and prints relevant output to the console.
The three scripts are optional and require that libcurl be installed on your system.
- Only the amd64 architecture is supported in this implementation, according to the assignment requirements.
- The CLI is minimal, using
argc/argvfor option parsing. - The program uses asynchronous background updating and local caching to provide a responsive UX.
- This project is intended for submission as part of the Multipass C++ Engineer Technical Assessment at Canonical.
- If the download fails, the tool automatically uses the local cache if present and not expired (≤ 1 hour).
This project is licensed under the MIT License. See the LICENSE file for details.
- Windows: Ensure that CMake generates a Visual Studio solution. You may need to configure vcpkg integration to link against libcurl.