diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..89d2460 Binary files /dev/null and b/.DS_Store differ diff --git a/.env b/.env index 116dbab..56794e3 100644 --- a/.env +++ b/.env @@ -1,2 +1,3 @@ HARBOR_USERNAME=admin -HARBOR_PASSWORD=Harbor12345 \ No newline at end of file +HARBOR_PASSWORD=Harbor12345 +ZOT_URL="127.0.0.1:8585/" \ No newline at end of file diff --git a/internal/satellite/satellite.go b/internal/satellite/satellite.go index 32d166b..cb2beba 100644 --- a/internal/satellite/satellite.go +++ b/internal/satellite/satellite.go @@ -1,11 +1,8 @@ package satellite import ( - "bytes" "context" "fmt" - "os" - "os/exec" "time" "container-registry.com/harbor-satelite/internal/replicate" @@ -25,7 +22,6 @@ func NewSatellite(storer store.Storer, replicator replicate.Replicator) *Satelli } func (s *Satellite) Run(ctx context.Context) error { - s.StartZotRegistry() // Temporarily set to faster tick rate for testing purposes ticker := time.NewTicker(2 * time.Second) defer ticker.Stop() @@ -53,34 +49,3 @@ func (s *Satellite) Run(ctx context.Context) error { fmt.Print("--------------------------------\n") } } - -func (s *Satellite) StartZotRegistry() error { - fmt.Println("Starting Zot registry") - dir, err := os.Getwd() - if err != nil { - fmt.Println("Error getting current directory:", err) - return nil - } - - registryDir := dir + "/registry" - zotExecutablePath := registryDir + "/zot-darwin-arm64" - configurationPath := registryDir + "/config.json" - - cmd := exec.Command(zotExecutablePath, "serve", configurationPath) - cmd.Dir = registryDir - - // Capture output and error - var stdout, stderr bytes.Buffer - cmd.Stdout = &stdout - cmd.Stderr = &stderr - - err = cmd.Start() - if err != nil { - fmt.Println("Zot registry failed to start:", err) - fmt.Println("Command output:", stdout.String()) - fmt.Println("Command error:", stderr.String()) - return fmt.Errorf("failed to start zot registry: %w", err) - } - fmt.Println("Zot registry started successfully") - return nil -} diff --git a/main.go b/main.go index 07da22d..1a53736 100644 --- a/main.go +++ b/main.go @@ -150,12 +150,6 @@ func run() error { replicator := replicate.NewReplicator() s := satellite.NewSatellite(storer, replicator) - // Run the Satellite - if err := s.Run(ctx); err != nil { - fmt.Println("Error running satellite:", err) - os.Exit(1) - } - g.Go(func() error { return s.Run(ctx) }) diff --git a/registry/makefile b/registry/makefile new file mode 100644 index 0000000..f3d4a23 --- /dev/null +++ b/registry/makefile @@ -0,0 +1,81 @@ +SOURCE_FILE=zot-2.0.4.tar.gz +EXTRACTED_DIR=zot-2.0.4 +BIN_DIR=../bin +BIN=bin +ZOT_BINARY=zot-darwin-arm64 +ZLI_BINARY=zli-darwin-arm64 + +# Build calls the appropriate build function based on the OS +build: + @OS=$(shell uname | tr '[:upper:]' '[:lower:]'); \ + ARCH=$(shell uname -m); \ + if [ "$$OS" = "darwin" ] && [ "$$ARCH" = "arm64" ]; then \ + echo "Building for macOS ARM..."; \ + $(eval ZOT_BINARY := zot-darwin-arm64) \ + $(MAKE) _build; \ + elif [ "$$OS" = "darwin" ] && [ "$$ARCH" = "x86_64" ]; then \ + echo "Building for macOS Intel..."; \ + $(eval ZOT_BINARY := zot-darwin-amd64) \ + $(MAKE) build-macos-amd64; \ + elif [ "$$OS" = "linux" ] && ["$$ARCH" = "arm64" ] ; then \ + echo "Building for Linux ARM..."; \ + $(eval ZOT_BINARY := zot-linux-arm64) \ + $(MAKE) build-linux; \ + elif [ "$$OS" = "linux" ] && ["$$ARCH" = "x86_64" ] ; then \ + echo "Building for Linux Intel..."; \ + $(eval ZOT_BINARY := zot-linux-amd64) \ + $(MAKE) build-linux; \ + else \ + echo "Unsupported OS."; \ + exit 1; \ + fi + + +_build: + @test -d $(BIN) || mkdir -p $(BIN) + @if [ ! -f $(BIN)/$(ZOT_BINARY) ]; then \ + tar -xzvf $(SOURCE_FILE); \ + cd $(EXTRACTED_DIR) && make binary ; \ + cp $(BIN)/$(ZOT_BINARY) ../$(BIN)/$(ZOT_BINARY); \ + cp ../config.json ../$(BIN)/config.json; \ + rm -rf ../$(EXTRACTED_DIR); \ + echo "---------------------------------------------------------------------------" ; \ + else \ + echo "$(ZOT_BINARY) already exists, skipping build."; \ + echo "---------------------------------------------------------------------------" ; \ + fi + + @if [ ! -f $(BIN)/$(ZLI_BINARY) ]; then \ + tar -xzvf $(SOURCE_FILE); \ + cd $(EXTRACTED_DIR) && make cli; \ + cp $(BIN)/$(ZLI_BINARY) ../$(BIN)/$(ZLI_BINARY); \ + cp ../config.json ../$(BIN)/config.json; \ + rm -rf ../$(EXTRACTED_DIR); \ + else \ + echo "$(ZLI_BINARY) already exists, skipping build."; \ + fi + +run: + @OS=$(shell uname | tr '[:upper:]' '[:lower:]'); \ + ARCH=$(shell uname -m); \ + if [ "$$OS" = "darwin" ] && [ "$$ARCH" = "arm64" ]; then \ + echo "Running for MacOS ARM..."; \ + $(BIN)/zot-darwin-arm64 serve ./config.json; \ + elif [ "$$OS" = "darwin" ] && [ "$$ARCH" = "x86_64" ]; then \ + echo "Running for MacOS Intel..."; \ + $(BIN)/zot-darwin-amd64 serve ./config.json; \ + elif [ "$$OS" = "linux" ] && [ "$$ARCH" = "arm64" ]; then \ + echo "Running for Linux ARM..."; \ + $(BIN)/zot-linux-arm64 serve ./config.json; \ + elif [ "$$OS" = "linux" ] && [ "$$ARCH" = "x86_64" ]; then \ + echo "Running for Linux Intel..."; \ + $(BIN)/zot-linux-amd64 serve ./config.json; \ + else \ + echo "Unsupported OS or architecture."; \ + exit 1; \ + fi + +clean: + rm -rf $(EXTRACTED_DIR) $(BIN) + + diff --git a/registry/zot-2.0.4.tar.gz b/registry/zot-2.0.4.tar.gz new file mode 100644 index 0000000..c362783 Binary files /dev/null and b/registry/zot-2.0.4.tar.gz differ