A convenient CLI tool to quickly spin up DragonflyBSD virtual machines using QEMU with sensible defaults.

Merge pull request #7 from tsirysndr/feat/docker-io-default-registry

feat: add default registry to image repository and enhance flag merging logic

authored by tsiry-sandratraina.com and committed by

GitHub bd09a77b 212a9efd

+26 -8
+19 -5
src/oras.ts
··· 149 }), 150 }); 151 152 const pushToRegistry = ( 153 img: { repository: string; tag: string; path: string }, 154 ) => 155 Effect.tryPromise({ 156 try: async () => { 157 - console.log(`Pushing image ${img.repository}...`); 158 const process = new Deno.Command("oras", { 159 args: [ 160 "push", 161 - `${img.repository}:${img.tag}-amd64`, 162 "--artifact-type", 163 "application/vnd.oci.image.layer.v1.tar", 164 "--annotation", ··· 218 Effect.tryPromise({ 219 try: async () => { 220 console.log(`Pulling image ${image}`); 221 const process = new Deno.Command("oras", { 222 args: [ 223 "pull", 224 - `${image}-amd64`, 225 ], 226 stdin: "inherit", 227 stdout: "inherit", ··· 244 export const getImageArchivePath = (image: string) => 245 Effect.tryPromise({ 246 try: async () => { 247 const process = new Deno.Command("oras", { 248 args: [ 249 "manifest", 250 "fetch", 251 - `${image}-amd64`, 252 ], 253 stdout: "piped", 254 stderr: "inherit", ··· 293 const getImageDigest = (image: string) => 294 Effect.tryPromise({ 295 try: async () => { 296 const process = new Deno.Command("oras", { 297 args: [ 298 "manifest", 299 "fetch", 300 - `${image}-amd64`, 301 ], 302 stdout: "piped", 303 stderr: "inherit",
··· 149 }), 150 }); 151 152 + // add docker.io/ if no registry is specified 153 + const formatRepository = (repository: string) => 154 + repository.match(/^[^\/]+\.[^\/]+\/.*/i) 155 + ? repository 156 + : `docker.io/${repository}`; 157 + 158 const pushToRegistry = ( 159 img: { repository: string; tag: string; path: string }, 160 ) => 161 Effect.tryPromise({ 162 try: async () => { 163 + console.log(`Pushing image ${formatRepository(img.repository)}...`); 164 const process = new Deno.Command("oras", { 165 args: [ 166 "push", 167 + `${formatRepository(img.repository)}:${img.tag}-amd64`, 168 "--artifact-type", 169 "application/vnd.oci.image.layer.v1.tar", 170 "--annotation", ··· 224 Effect.tryPromise({ 225 try: async () => { 226 console.log(`Pulling image ${image}`); 227 + const repository = image.split(":")[0]; 228 + const tag = image.split(":")[1] || "latest"; 229 + console.log("pull", `${formatRepository(repository)}:${tag}-amd64`); 230 + 231 const process = new Deno.Command("oras", { 232 args: [ 233 "pull", 234 + `${formatRepository(repository)}:${tag}-amd64`, 235 ], 236 stdin: "inherit", 237 stdout: "inherit", ··· 254 export const getImageArchivePath = (image: string) => 255 Effect.tryPromise({ 256 try: async () => { 257 + const repository = image.split(":")[0]; 258 + const tag = image.split(":")[1] || "latest"; 259 const process = new Deno.Command("oras", { 260 args: [ 261 "manifest", 262 "fetch", 263 + `${formatRepository(repository)}:${tag}-amd64`, 264 ], 265 stdout: "piped", 266 stderr: "inherit", ··· 305 const getImageDigest = (image: string) => 306 Effect.tryPromise({ 307 try: async () => { 308 + const repository = image.split(":")[0]; 309 + const tag = image.split(":")[1] || "latest"; 310 const process = new Deno.Command("oras", { 311 args: [ 312 "manifest", 313 "fetch", 314 + `${formatRepository(repository)}:${tag}-amd64`, 315 ], 316 stdout: "piped", 317 stderr: "inherit",
+7 -3
src/subcommands/run.ts
··· 84 function mergeFlags(image: Image): Options { 85 const { flags } = parseFlags(Deno.args); 86 return { 87 - cpu: (flags.cpu || flags.c) ? (flags.cpu || flags.c) : "host", 88 - cpus: (flags.cpus || flags.C) ? (flags.cpus || flags.C) : 2, 89 memory: (flags.memory || flags.m) ? (flags.memory || flags.m) : "2G", 90 image: image.path, 91 bridge: flags.bridge || flags.b, ··· 94 install: false, 95 diskFormat: image.format, 96 volume: flags.volume || flags.v, 97 - size: flags.size || flags.s, 98 }; 99 }
··· 84 function mergeFlags(image: Image): Options { 85 const { flags } = parseFlags(Deno.args); 86 return { 87 + cpu: (flags.cpu || flags.c) 88 + ? (flags.cpu || flags.c) 89 + : Deno.build.arch === "aarch64" 90 + ? "max" 91 + : "host", 92 + cpus: (flags.cpus || flags.C) ? (flags.cpus || flags.C) : 4, 93 memory: (flags.memory || flags.m) ? (flags.memory || flags.m) : "2G", 94 image: image.path, 95 bridge: flags.bridge || flags.b, ··· 98 install: false, 99 diskFormat: image.format, 100 volume: flags.volume || flags.v, 101 + size: flags.size || flags.s || "20G", 102 }; 103 }