Skip to content

Instantly share code, notes, and snippets.

@developer-guy
Created October 26, 2022 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save developer-guy/e0e35d961ec6048a65d5da386a4defe4 to your computer and use it in GitHub Desktop.
Save developer-guy/e0e35d961ec6048a65d5da386a4defe4 to your computer and use it in GitHub Desktop.
A registry server impl using google/go-containerregistry pkg
package main
import (
"context"
"fmt"
"net/http/httptest"
"os"
"os/signal"
"strings"
"syscall"
"github.com/google/go-containerregistry/pkg/registry"
)
func main() {
_, cancel := context.WithCancel(context.Background())
defer cancel()
// Setup a local registry and have tests push to that.
srv := httptest.NewServer(registry.New())
defer srv.Close()
parts := strings.Split(srv.URL, ":")
url := fmt.Sprintf("localhost:%s", parts[len(parts)-1])
fmt.Println("Registry URL:", url)
c := setupSignalHandler()
<-c
fmt.Println("shutting down the registry server")
<-c
os.Exit(1)
}
func setupSignalHandler() chan os.Signal {
signalChan := make(chan os.Signal, 2)
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
return signalChan
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment