description⌗

In order to speed up my workflow, I want to serve .qcow2 images from within my lan.

Note: This is not a step by step guide, just my notes of how I put things together.

tasks⌗

  1. get the code from google and build it
  2. set it up
  3. test it

1. get the code from google and build it⌗

Code taken from:

// https://gist.github.com/paulmach/7271283
// https://gist.github.com/paulmach/7271283?permalink_comment_id=4130099#gistcomment-4130099
package main

import (
	"flag"
	"log"
	"net/http"
	"path/filepath"
)

var (
	path = flag.String("path", "/mnt/_cloud", "path to the folder to serve. Defaults to the current folder")
	port = flag.String("port", "80", "port to serve on. Defaults to 80")
)

func main() {
	flag.Parse()

	dirname, err := filepath.Abs(*path)
	if err != nil {
		log.Fatalf("Could not get absolute path to directory: %s: %s", dirname, err.Error())
	}

	log.Printf("Serving %s on port %s", dirname, *port)

	err = Serve(dirname, *port)
	if err != nil {
		log.Fatalf("Could not serve directory: %s: %s", dirname, err.Error())
	}

}

func Serve(dirname string, port string) error {
	fs := http.FileServer(http.Dir(dirname))
	http.Handle("/", fs)

	return http.ListenAndServe(":"+port, nil)
}

2. set it up⌗

Once you get the executable, next step is to create systemd unit, like simple_http.service:

[Unit]
Description=simple http
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=1
ExecStart=/usr/bin/serve

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start simple_http
systemctl status simple_http

3. test it⌗

if everything is correct, you could try curl $(hostname). After that, just place your .qcow2 for local consumption.