Skip to content

Commit

Permalink
Decoupled zot registry from satellite
Browse files Browse the repository at this point in the history
Added makefile to build and run zot and zli depending on host's OS and architecture (MacOS/Linux and ARM/Intel)
Added source code for zot/zli as tar.gz
Removed double execution of satellite in main.go
Removed launch of zot in satellite.go
  • Loading branch information
OneFlyingBanana committed May 28, 2024
1 parent 06ccca6 commit 70e2ed7
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 42 deletions.
Binary file added .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
HARBOR_USERNAME=admin
HARBOR_PASSWORD=Harbor12345
HARBOR_PASSWORD=Harbor12345
ZOT_URL="127.0.0.1:8585/"
35 changes: 0 additions & 35 deletions internal/satellite/satellite.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package satellite

import (
"bytes"
"context"
"fmt"
"os"
"os/exec"
"time"

"container-registry.com/harbor-satelite/internal/replicate"
Expand All @@ -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()
Expand Down Expand Up @@ -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
}
6 changes: 0 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
81 changes: 81 additions & 0 deletions registry/makefile
Original file line number Diff line number Diff line change
@@ -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)


Binary file added registry/zot-2.0.4.tar.gz
Binary file not shown.

0 comments on commit 70e2ed7

Please sign in to comment.