Created
October 26, 2022 20:31
-
-
Save developer-guy/e0e35d961ec6048a65d5da386a4defe4 to your computer and use it in GitHub Desktop.
A registry server impl using google/go-containerregistry pkg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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