From 667bbe2fc6918e0f8f83a7a171ac6db2e1a462b7 Mon Sep 17 00:00:00 2001 From: Eslam-Nawara Date: Tue, 10 Jun 2025 12:11:17 +0300 Subject: [PATCH 1/7] use urls from zos-config if exists --- pkg/environment/config.go | 9 ++++++++- pkg/environment/environment.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/pkg/environment/config.go b/pkg/environment/config.go index 292fd7fc..211784a7 100644 --- a/pkg/environment/config.go +++ b/pkg/environment/config.go @@ -30,7 +30,14 @@ type Config struct { RolloutUpgrade struct { TestFarms []uint32 `json:"test_farms"` } `json:"rollout_upgrade"` - RelaysURLs []string `json:"relays_urls"` + RelaysURLs []string `json:"relays_urls"` + SubstrateURL []string `json:"substrate_urls"` + ActivationURL []string `json:"activation_urls"` + GraphQL []string `json:"graphql_urls"` + KycURL string `json:"kyc_url"` + RegistrarURL string `json:"registrar_url"` + FlistURL string `json:"flist_url"` + BinRepo string `json:"bin_repo"` } // Merge, updates current config with cfg merging and override config diff --git a/pkg/environment/environment.go b/pkg/environment/environment.go index 37498c9d..346ce3f4 100644 --- a/pkg/environment/environment.go +++ b/pkg/environment/environment.go @@ -269,6 +269,10 @@ func getEnvironmentFromParams(params kernel.Params) (Environment, error) { if len(runmode) == 0 { runmode = string(RunningMain) } + config, err := GetConfig() + if err != nil { + return env, err + } switch RunMode(runmode) { case RunningDev: @@ -287,18 +291,44 @@ func getEnvironmentFromParams(params kernel.Params) (Environment, error) { if len(substrate) > 0 { env.SubstrateURL = substrate } + } else if substrate := config.SubstrateURL; len(substrate) > 0 { + env.SubstrateURL = substrate } if relay, ok := params.Get("relay"); ok { if len(relay) > 0 { env.relaysURLs = relay } + } else if relay := config.RelaysURLs; len(relay) > 0 { + env.relaysURLs = relay } if activation, ok := params.Get("activation"); ok { if len(activation) > 0 { env.ActivationURL = activation } + } else if activation := config.ActivationURL; len(activation) > 0 { + env.ActivationURL = activation + } + + if graphql := config.GraphQL; len(graphql) > 0 { + env.GraphQL = graphql + } + + if flist := config.FlistURL; len(flist) > 0 { + env.FlistURL = flist + } + + if bin := config.FlistURL; len(bin) > 0 { + env.FlistURL = bin + } + + if kyc := config.FlistURL; len(kyc) > 0 { + env.FlistURL = kyc + } + + if registrar := config.FlistURL; len(registrar) > 0 { + env.FlistURL = registrar } if farmSecret, ok := params.Get("secret"); ok { From cf49efc8fea14b7bcd13caaeff9fae216756d232 Mon Sep 17 00:00:00 2001 From: Eslam-Nawara Date: Wed, 11 Jun 2025 12:40:06 +0300 Subject: [PATCH 2/7] fix check urls length --- pkg/environment/environment.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/environment/environment.go b/pkg/environment/environment.go index 346ce3f4..caad2023 100644 --- a/pkg/environment/environment.go +++ b/pkg/environment/environment.go @@ -319,15 +319,15 @@ func getEnvironmentFromParams(params kernel.Params) (Environment, error) { env.FlistURL = flist } - if bin := config.FlistURL; len(bin) > 0 { + if bin := config.BinRepo; len(bin) > 0 { env.FlistURL = bin } - if kyc := config.FlistURL; len(kyc) > 0 { + if kyc := config.KycURL; len(kyc) > 0 { env.FlistURL = kyc } - if registrar := config.FlistURL; len(registrar) > 0 { + if registrar := config.RegistrarURL; len(registrar) > 0 { env.FlistURL = registrar } From 2bade3b87213cda7a3a3a081a55b431e0e84ec8f Mon Sep 17 00:00:00 2001 From: Eslam-Nawara Date: Mon, 16 Jun 2025 16:05:29 +0300 Subject: [PATCH 3/7] update not working domains to the new domains in zosbase --- bootstrap/bootstrap/README.md | 6 ++-- bootstrap/bootstrap/src/hub.rs | 6 ++-- pkg/container/README.md | 54 +++++++++++++++++----------------- pkg/environment/environment.go | 40 +++++++++++++++++-------- pkg/flist/flist_test.go | 26 ++++++++++++---- pkg/gateway/flist.go | 13 +++++--- pkg/gateway_light/flist.go | 12 +++++--- pkg/geoip/geoip.go | 2 +- pkg/primitives/vm-light/vm.go | 11 +++++-- pkg/primitives/vm/vm.go | 11 +++++-- pkg/primitives/zdb/zdb.go | 38 ++++++++++++++++++++++-- pkg/qsfsd/qsfs.go | 11 +++++-- pkg/upgrade/README.md | 2 +- pkg/upgrade/hub/hub.go | 8 ++--- scripts/debug_image.md | 4 +-- scripts/debug_image.sh | 2 +- 16 files changed, 168 insertions(+), 78 deletions(-) diff --git a/bootstrap/bootstrap/README.md b/bootstrap/bootstrap/README.md index e36b4bfd..a71c1723 100644 --- a/bootstrap/bootstrap/README.md +++ b/bootstrap/bootstrap/README.md @@ -19,8 +19,8 @@ will do a multiple stage bootstrap. Currently this is only two stages: - Bootstrap is used by [0-initramfs](https://github.com/threefoldtech/0-initramfs/blob/development-zos-v3/packages/modules.sh) to basically add `internet` and `bootstrap` services to the base image - After internet service is fully started, bootstrap will start to download flists needed for zos node to work properly - As described above bootstrap run in two stages: - - The first stage is used to update bootstrap itself, and it is done like that to avoid re-building the image if we only changed the bootstrap code. this update is basically done from `tf-autobuilder` repo in the [hub/tf-autobuilder](https://hub.grid.tf/tf-autobuilder) and download the latest bootstrap flist - - For the second stage bootstrap will download the flists for that env. bootstrap cares about `runmode` argument that we pass during the start of the node. for example if we passed `runmode=dev` it will get the the tag `development` under [hub/tf-zos](https://hub.grid.tf/tf-zos) each tag is linked to a sub-directory where all flists for this env exists to be downloaded and installed on the node + - The first stage is used to update bootstrap itself, and it is done like that to avoid re-building the image if we only changed the bootstrap code. this update is basically done from `tf-autobuilder` repo in the [hub/tf-autobuilder](https://hub.threefold.me/tf-autobuilder) and download the latest bootstrap flist + - For the second stage bootstrap will download the flists for that env. bootstrap cares about `runmode` argument that we pass during the start of the node. for example if we passed `runmode=dev` it will get the the tag `development` under [hub/tf-zos](https://hub.threefold.me/tf-zos) each tag is linked to a sub-directory where all flists for this env exists to be downloaded and installed on the node ## Testing in Developer setup @@ -40,6 +40,6 @@ after: - internet ``` -- remove overlay link under `qemu/overlay ` +- remove overlay link under `qemu/overlay` - create a new link pointing to overlay.custom under zos/qemu `ln -s overlay.custom overlay` - boot your vm as normal diff --git a/bootstrap/bootstrap/src/hub.rs b/bootstrap/bootstrap/src/hub.rs index e1de1490..21217e32 100644 --- a/bootstrap/bootstrap/src/hub.rs +++ b/bootstrap/bootstrap/src/hub.rs @@ -6,7 +6,7 @@ use std::fs::{write, OpenOptions}; use std::io::copy; use std::path::Path; -const HUB: &str = "https://hub.grid.tf"; +const HUB: &str = "https://hub.threefold.me"; pub struct Repo { name: String, @@ -172,7 +172,7 @@ mod tests { let flist = repo.get("test.flist")?; assert_eq!(flist.name, "test.flist"); assert_eq!(flist.kind, Kind::Regular); - assert_eq!(flist.url, "https://hub.grid.tf/azmy/test.flist"); + assert_eq!(flist.url, "https://hub.threefold.me/azmy/test.flist"); Ok(()) } @@ -227,7 +227,7 @@ mod tests { let found = found.unwrap(); assert_eq!(found.name, "test.flist"); - assert_eq!(found.url, "https://hub.grid.tf/azmy/test.flist"); + assert_eq!(found.url, "https://hub.threefold.me/azmy/test.flist"); Ok(()) } diff --git a/pkg/container/README.md b/pkg/container/README.md index 781e4d59..b06ca64d 100644 --- a/pkg/container/README.md +++ b/pkg/container/README.md @@ -14,43 +14,43 @@ the container rootfs package main import ( - "github.com/threefoldtech/zbus" - "github.com/threefoldtech/zosbase/pkg" - "github.com/threefoldtech/zosbase/pkg/stubs" + "github.com/threefoldtech/zbus" + "github.com/threefoldtech/zosbase/pkg" + "github.com/threefoldtech/zosbase/pkg/stubs" ) func main() { - client, err := zbus.NewRedisClient("tcp://localhost:6379") - if err != nil { - panic(client) - } + client, err := zbus.NewRedisClient("tcp://localhost:6379") + if err != nil { + panic(client) + } - containerd := stubs.NewContainerModuleStub(client) - namespace := "example" + containerd := stubs.NewContainerModuleStub(client) + namespace := "example" - // make sure u have a network namespace ready using ip - // sudo ip netns add mynetns + // make sure u have a network namespace ready using ip + // sudo ip netns add mynetns - info := pkg.Container{ - Name: "test", - FList: "https://hub.grid.tf/thabet/redis.flist", - Env: []string{}, - Network: pkg.NetworkInfo{Namespace: "mynetns"}, - Mounts: nil, - Entrypoint: "redis-server", - } + info := pkg.Container{ + Name: "test", + FList: "https://hub.threefold.me/thabet/redis.flist", + Env: []string{}, + Network: pkg.NetworkInfo{Namespace: "mynetns"}, + Mounts: nil, + Entrypoint: "redis-server", + } - id, err := containerd.Run(namespace, info) + id, err := containerd.Run(namespace, info) - if err != nil { - panic(err) - } + if err != nil { + panic(err) + } - // DO WORK WITH CONTAINER ... + // DO WORK WITH CONTAINER ... - if err = containerd.Delete(namespace, id); err != nil { - panic(err) - } + if err = containerd.Delete(namespace, id); err != nil { + panic(err) + } } ``` diff --git a/pkg/environment/environment.go b/pkg/environment/environment.go index caad2023..62da75ed 100644 --- a/pkg/environment/environment.go +++ b/pkg/environment/environment.go @@ -1,6 +1,7 @@ package environment import ( + "net/http" "os" "slices" "strconv" @@ -16,6 +17,10 @@ import ( const ( baseExtendedURL = "https://raw.githubusercontent.com/threefoldtech/zos-config/main/" + hubURL = "https://hub.threefold.me" + v4HubURL = "https://v4.hub.threefold.me" + flistURL = "redis://hub.threefold.me:9900" + v4FlistURL = "redis://v4.hub.threefold.me:9940" ) // PubMac specify how the mac address of the public nic @@ -53,6 +58,7 @@ type Environment struct { GraphQL []string KycURL string RegistrarURL string + HubURL string // private vlan to join // if set, zos will use this as its priv vlan @@ -121,7 +127,8 @@ var ( "https://activation.dev.grid.tf/activation/activate", "https://activation.02.dev.grid.tf/activation/activate", }, - FlistURL: "redis://hub.grid.tf:9900", + FlistURL: flistURL, + HubURL: hubURL, BinRepo: "tf-zos-v3-bins.dev", GraphQL: []string{ "https://graphql.dev.grid.tf/graphql", @@ -145,7 +152,8 @@ var ( "https://activation.test.grid.tf/activation/activate", "https://activation.02.test.grid.tf/activation/activate", }, - FlistURL: "redis://hub.grid.tf:9900", + FlistURL: flistURL, + HubURL: hubURL, BinRepo: "tf-zos-v3-bins.test", GraphQL: []string{ "https://graphql.test.grid.tf/graphql", @@ -169,7 +177,8 @@ var ( "https://activation.qa.grid.tf/activation/activate", "https://activation.02.qa.grid.tf/activation/activate", }, - FlistURL: "redis://hub.grid.tf:9900", + FlistURL: flistURL, + HubURL: hubURL, BinRepo: "tf-zos-v3-bins.qanet", GraphQL: []string{ "https://graphql.qa.grid.tf/graphql", @@ -193,17 +202,20 @@ var ( // "wss://relay.02.grid.tf", }, ActivationURL: []string{ + "https://activation.grid.threefold.me/activation/activate", "https://activation.grid.tf/activation/activate", "https://activation.02.grid.tf/activation/activate", }, - FlistURL: "redis://hub.grid.tf:9900", + HubURL: hubURL, + FlistURL: flistURL, BinRepo: "tf-zos-v3-bins", GraphQL: []string{ + "https://graphql.grid.threefold.me/graphql", "https://graphql.grid.tf/graphql", "https://graphql.02.grid.tf/graphql", }, - KycURL: "https://kyc.grid.tf", - RegistrarURL: "https://registrar.prod4.grid.tf", + KycURL: "https://kyc.threefold.me", + RegistrarURL: "https://registrar.prod4.threefold.me", } ) @@ -269,10 +281,6 @@ func getEnvironmentFromParams(params kernel.Params) (Environment, error) { if len(runmode) == 0 { runmode = string(RunningMain) } - config, err := GetConfig() - if err != nil { - return env, err - } switch RunMode(runmode) { case RunningDev: @@ -287,6 +295,13 @@ func getEnvironmentFromParams(params kernel.Params) (Environment, error) { env = envProd } + config, err := getConfig(env.RunningMode, baseExtendedURL, http.DefaultClient) + if err != nil { + // maybe the node can't reach the internet right now + // this will enforce node to skip config + config = Config{} + } + if substrate, ok := params.Get("substrate"); ok { if len(substrate) > 0 { env.SubstrateURL = substrate @@ -408,9 +423,10 @@ func getEnvironmentFromParams(params kernel.Params) (Environment, error) { env.BinRepo = e } - // if the node running v4 chage flisturl to use v4.hub.grid.tf + // if the node running v4 chage flisturl to use v4.hub.threefold.me if params.IsV4() { - env.FlistURL = "redis://v4.hub.grid.tf:9940" + env.FlistURL = v4FlistURL + env.HubURL = v4HubURL } return env, nil diff --git a/pkg/flist/flist_test.go b/pkg/flist/flist_test.go index 24025e36..2592a4c0 100644 --- a/pkg/flist/flist_test.go +++ b/pkg/flist/flist_test.go @@ -3,6 +3,7 @@ package flist import ( "bytes" "context" + "net/url" "os" "os/exec" "path/filepath" @@ -15,6 +16,7 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" "github.com/threefoldtech/zosbase/pkg" + "github.com/threefoldtech/zosbase/pkg/environment" "github.com/threefoldtech/zosbase/pkg/gridtypes" ) @@ -159,7 +161,10 @@ func TestMountUnmount(t *testing.T) { sys.On("Mount", "overlay", filepath.Join(root, "mountpoint", name), "overlay", uintptr(syscall.MS_NOATIME), mock.Anything).Return(nil) - mnt, err := flister.mountInNamespace(name, "https://hub.grid.tf/thabet/redis.flist", pkg.DefaultMountOptions, "") + redisFlist, err := url.JoinPath(environment.MustGet().HubURL, "thabet", "redis.flist") + require.NoError(t, err) + + mnt, err := flister.mountInNamespace(name, redisFlist, pkg.DefaultMountOptions, "") require.NoError(t, err) // Trick flister into thinking that 0-fs has exited @@ -186,7 +191,10 @@ func TestMountUnmountRO(t *testing.T) { flist := mock.Anything sys.On("Mount", flist, filepath.Join(root, "mountpoint", name), "bind", uintptr(syscall.MS_BIND), "").Return(nil) - mnt, err := flister.mountInNamespace(name, "https://hub.grid.tf/thabet/redis.flist", pkg.ReadOnlyMountOptions, "") + redisFlist, err := url.JoinPath(environment.MustGet().HubURL, "thabet", "redis.flist") + require.NoError(t, err) + + mnt, err := flister.mountInNamespace(name, redisFlist, pkg.ReadOnlyMountOptions, "") require.NoError(t, err) // Trick flister into thinking that 0-fs has exited @@ -223,11 +231,14 @@ func TestIsolation(t *testing.T) { name2 := "test2" sys.On("Mount", "overlay", filepath.Join(root, "mountpoint", name2), "overlay", uintptr(syscall.MS_NOATIME), mock.Anything).Return(nil) - path1, err := flister.mountInNamespace(name1, "https://hub.grid.tf/thabet/redis.flist", pkg.DefaultMountOptions, "") + redisFlist, err := url.JoinPath(environment.MustGet().HubURL, "thabet", "redis.flist") + require.NoError(err) + + path1, err := flister.mountInNamespace(name1, redisFlist, pkg.DefaultMountOptions, "") require.NoError(err) args1 := cmder.m - path2, err := flister.mountInNamespace(name2, "https://hub.grid.tf/thabet/redis.flist", pkg.DefaultMountOptions, "") + path2, err := flister.mountInNamespace(name2, redisFlist, pkg.DefaultMountOptions, "") require.NoError(err) args2 := cmder.m @@ -246,14 +257,17 @@ func TestDownloadFlist(t *testing.T) { f := newFlister(root, strg, cmder, sys) - hash1, path1, err := f.downloadFlist("https://hub.grid.tf/thabet/redis.flist", "") + redisFlist, err := url.JoinPath(environment.MustGet().HubURL, "thabet", "redis.flist") + require.NoError(err) + + hash1, path1, err := f.downloadFlist(redisFlist, "") require.NoError(err) // now corrupt the flist err = os.Truncate(string(path1), 512) require.NoError(err) - hash2, path2, err := f.downloadFlist("https://hub.grid.tf/thabet/redis.flist", "") + hash2, path2, err := f.downloadFlist(redisFlist, "") require.NoError(err) require.EqualValues(path1, path2) diff --git a/pkg/gateway/flist.go b/pkg/gateway/flist.go index 99fdce5b..344c48b0 100644 --- a/pkg/gateway/flist.go +++ b/pkg/gateway/flist.go @@ -3,24 +3,29 @@ package gateway import ( "context" "fmt" + "net/url" "path/filepath" "github.com/pkg/errors" "github.com/threefoldtech/zbus" "github.com/threefoldtech/zosbase/pkg" + "github.com/threefoldtech/zosbase/pkg/environment" "github.com/threefoldtech/zosbase/pkg/stubs" ) -const ( - flist = "https://hub.grid.tf/tf-autobuilder/traefik-2.9.9.flist" -) - // ensureTraefikBin makes sure traefik flist is mounted. // TODO: we need to "update" traefik and restart the service // if new version is available! func ensureTraefikBin(ctx context.Context, cl zbus.Client) (string, error) { const bin = "traefik" flistd := stubs.NewFlisterStub(cl) + + env := environment.MustGet() + flist, err := url.JoinPath(env.HubURL, "tf-autobuilder", "traefik-2.9.9.flist") + if err != nil { + return "", errors.Wrap(err, "failed to constract traefik flist url") + } + hash, err := flistd.FlistHash(ctx, flist) if err != nil { return "", errors.Wrap(err, "failed to get traefik flist hash") diff --git a/pkg/gateway_light/flist.go b/pkg/gateway_light/flist.go index 99fdce5b..b3e179ea 100644 --- a/pkg/gateway_light/flist.go +++ b/pkg/gateway_light/flist.go @@ -3,24 +3,28 @@ package gateway import ( "context" "fmt" + "net/url" "path/filepath" "github.com/pkg/errors" "github.com/threefoldtech/zbus" "github.com/threefoldtech/zosbase/pkg" + "github.com/threefoldtech/zosbase/pkg/environment" "github.com/threefoldtech/zosbase/pkg/stubs" ) -const ( - flist = "https://hub.grid.tf/tf-autobuilder/traefik-2.9.9.flist" -) - // ensureTraefikBin makes sure traefik flist is mounted. // TODO: we need to "update" traefik and restart the service // if new version is available! func ensureTraefikBin(ctx context.Context, cl zbus.Client) (string, error) { const bin = "traefik" flistd := stubs.NewFlisterStub(cl) + + env := environment.MustGet() + flist, err := url.JoinPath(env.HubURL, "tf-autobuilder", "traefik-2.9.9.flist") + if err != nil { + return "", errors.Wrap(err, "failed to construct traefik flist url") + } hash, err := flistd.FlistHash(ctx, flist) if err != nil { return "", errors.Wrap(err, "failed to get traefik flist hash") diff --git a/pkg/geoip/geoip.go b/pkg/geoip/geoip.go index 43966cbf..72ca179d 100644 --- a/pkg/geoip/geoip.go +++ b/pkg/geoip/geoip.go @@ -20,7 +20,7 @@ type Location struct { } var ( - geoipURLs = []string{"https://geoip.grid.tf/", "https://02.geoip.grid.tf/", "https://03.geoip.grid.tf/"} + geoipURLs = []string{"https://geoip.threefold.me/", "https://geoip.grid.tf/", "https://02.geoip.grid.tf/", "https://03.geoip.grid.tf/"} defaultHTTPClient = retryablehttp.NewClient() ) diff --git a/pkg/primitives/vm-light/vm.go b/pkg/primitives/vm-light/vm.go index cc5c0d99..a0d13160 100644 --- a/pkg/primitives/vm-light/vm.go +++ b/pkg/primitives/vm-light/vm.go @@ -6,12 +6,14 @@ import ( "fmt" "io" "net" + "net/url" "os" "github.com/pkg/errors" "github.com/rs/zerolog/log" "github.com/threefoldtech/zbus" "github.com/threefoldtech/zosbase/pkg" + "github.com/threefoldtech/zosbase/pkg/environment" "github.com/threefoldtech/zosbase/pkg/gridtypes" "github.com/threefoldtech/zosbase/pkg/gridtypes/zos" "github.com/threefoldtech/zosbase/pkg/primitives/vmgpu" @@ -20,7 +22,6 @@ import ( ) const ( - cloudContainerFlist = "https://hub.grid.tf/tf-autobuilder/cloud-container-9dba60e.flist" cloudContainerName = "cloud-container" ) @@ -109,7 +110,6 @@ func (p *Manager) mountVolume(ctx context.Context, wl *gridtypes.WorkloadWithID, } func (p *Manager) mountQsfs(wl *gridtypes.WorkloadWithID, mount zos.MachineMount, vm *pkg.VM) error { - var info zos.QuatumSafeFSResult if err := wl.Result.Unmarshal(&info); err != nil { return fmt.Errorf("invalid qsfs result '%s': %w", mount.Name, err) @@ -216,6 +216,12 @@ func (p *Manager) virtualMachineProvisionImpl(ctx context.Context, wl *gridtypes log.Debug().Msgf("detected flist type: %+v", imageInfo) // mount cloud-container flist (or reuse) which has kernel, initrd and also firmware + env := environment.MustGet() + cloudContainerFlist, err := url.JoinPath(env.FlistURL, "tf-autobuilder", "cloud-container-9dba60e.flist") + if err != nil { + return zos.ZMachineLightResult{}, errors.Wrap(err, "failed to construct cloud-container flist url") + } + hash, err := flist.FlistHash(ctx, cloudContainerFlist) if err != nil { return zos.ZMachineLightResult{}, errors.Wrap(err, "failed to get cloud-container flist hash") @@ -237,7 +243,6 @@ func (p *Manager) virtualMachineProvisionImpl(ctx context.Context, wl *gridtypes if err = p.prepVirtualMachine(ctx, cloudImage, imageInfo, &machine, &config, &deployment, wl); err != nil { return result, err } - } // - Attach mounts diff --git a/pkg/primitives/vm/vm.go b/pkg/primitives/vm/vm.go index 1a1655ee..ab0d2b30 100644 --- a/pkg/primitives/vm/vm.go +++ b/pkg/primitives/vm/vm.go @@ -6,12 +6,14 @@ import ( "fmt" "io" "net" + "net/url" "os" "github.com/pkg/errors" "github.com/rs/zerolog/log" "github.com/threefoldtech/zbus" "github.com/threefoldtech/zosbase/pkg" + "github.com/threefoldtech/zosbase/pkg/environment" "github.com/threefoldtech/zosbase/pkg/gridtypes" "github.com/threefoldtech/zosbase/pkg/gridtypes/zos" "github.com/threefoldtech/zosbase/pkg/primitives/vmgpu" @@ -20,8 +22,7 @@ import ( ) const ( - cloudContainerFlist = "https://hub.grid.tf/tf-autobuilder/cloud-container-9dba60e.flist" - cloudContainerName = "cloud-container" + cloudContainerName = "cloud-container" ) // ZMachine type @@ -254,6 +255,12 @@ func (p *Manager) virtualMachineProvisionImpl(ctx context.Context, wl *gridtypes log.Debug().Msgf("detected flist type: %+v", imageInfo) // mount cloud-container flist (or reuse) which has kernel, initrd and also firmware + env := environment.MustGet() + cloudContainerFlist, err := url.JoinPath(env.FlistURL, "tf-autobuilder", "cloud-container-9dba60e.flist") + if err != nil { + return zos.ZMachineResult{}, errors.Wrap(err, "failed to construct cloud-container flist url") + } + hash, err := flist.FlistHash(ctx, cloudContainerFlist) if err != nil { return zos.ZMachineResult{}, errors.Wrap(err, "failed to get cloud-container flist hash") diff --git a/pkg/primitives/zdb/zdb.go b/pkg/primitives/zdb/zdb.go index 79f10194..0bd02910 100644 --- a/pkg/primitives/zdb/zdb.go +++ b/pkg/primitives/zdb/zdb.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "net" + "net/url" "os" "path/filepath" "regexp" @@ -13,6 +14,7 @@ import ( "github.com/cenkalti/backoff/v3" "github.com/threefoldtech/zbus" + "github.com/threefoldtech/zosbase/pkg/environment" "github.com/threefoldtech/zosbase/pkg/gridtypes" "github.com/threefoldtech/zosbase/pkg/gridtypes/zos" "github.com/threefoldtech/zosbase/pkg/kernel" @@ -29,7 +31,8 @@ import ( const ( // https://hub.grid.tf/api/flist/tf-autobuilder/threefoldtech-0-db-development.flist/light // To get the latest symlink pointer - zdbFlistURL = "https://hub.grid.tf/tf-autobuilder/threefoldtech-0-db-release-v2.0.8-55737c9202.flist" + flistRepo = "tf-autobuilder" + flistName = "threefoldtech-0-db-release-v2.0.8-55737c9202.flist" zdbContainerNS = "zdb" zdbContainerDataMnt = "/zdb" zdbPort = 9900 @@ -160,7 +163,6 @@ func (p *Manager) zdbProvisionImpl(ctx context.Context, wl *gridtypes.WorkloadWi if kernel.GetParams().IsLight() { containerIPs, err = p.waitZDBIPsLight(ctx, container.Network.Namespace, container.CreatedAt) } else { - containerIPs, err = p.waitZDBIPs(ctx, container.Network.Namespace, container.CreatedAt) } if err != nil { @@ -202,7 +204,6 @@ func (p *Manager) zdbProvisionImpl(ctx context.Context, wl *gridtypes.WorkloadWi if kernel.GetParams().IsLight() { containerIPs, err = p.waitZDBIPsLight(ctx, cont.Network.Namespace, cont.CreatedAt) } else { - containerIPs, err = p.waitZDBIPs(ctx, cont.Network.Namespace, cont.CreatedAt) } if err != nil { @@ -255,6 +256,12 @@ func (p *Manager) zdbRootFS(ctx context.Context) (string, error) { var err error var rootFS string + env := environment.MustGet() + zdbFlistURL, err := url.JoinPath(env.FlistURL, flistRepo, flistName) + if err != nil { + return "", errors.Wrap(err, "failed to construct zdb flist url") + } + hash, err := flist.FlistHash(ctx, zdbFlistURL) if err != nil { return "", errors.Wrap(err, "failed to get flist hash") @@ -282,6 +289,11 @@ func (p *Manager) createZdbContainer(ctx context.Context, device pkg.Device) err slog = log.With().Str("containerID", string(name)).Logger() ) + env := environment.MustGet() + zdbFlistURL, err := url.JoinPath(env.FlistURL, flistRepo, flistName) + if err != nil { + return errors.Wrap(err, "failed to construct zdb flist url") + } slog.Debug().Str("flist", zdbFlistURL).Msg("mounting flist") rootFS, err := p.zdbRootFS(ctx) @@ -369,6 +381,7 @@ func (p *Manager) dataMigration(ctx context.Context, volume string) { } } } + func (p *Manager) createZdbContainerLight(ctx context.Context, device pkg.Device) error { var ( name = pkg.ContainerID(device.ID) @@ -380,6 +393,11 @@ func (p *Manager) createZdbContainerLight(ctx context.Context, device pkg.Device slog = log.With().Str("containerID", string(name)).Logger() ) + env := environment.MustGet() + zdbFlistURL, err := url.JoinPath(env.FlistURL, flistRepo, flistName) + if err != nil { + return errors.Wrap(err, "failed to construct zdb flist url") + } slog.Debug().Str("flist", zdbFlistURL).Msg("mounting flist") rootFS, err := p.zdbRootFS(ctx) @@ -565,6 +583,7 @@ func (p *Manager) waitZDBIPs(ctx context.Context, namespace string, created time return containerIPs, nil } + func (p *Manager) waitZDBIPsLight(ctx context.Context, namespace string, created time.Time) ([]net.IP, error) { // TODO: is there a need for retrying anymore?? var ( @@ -932,6 +951,12 @@ func (p *Manager) initialize(ctx context.Context) error { flistmod = stubs.NewFlisterStub(p.zbus) ) // fetching extected hash + env := environment.MustGet() + zdbFlistURL, err := url.JoinPath(env.FlistURL, flistRepo, flistName) + if err != nil { + return errors.Wrap(err, "failed to construct zdb flist url") + } + log.Debug().Msg("fetching flist hash") expected, err := flistmod.FlistHash(ctx, zdbFlistURL) if err != nil { @@ -993,6 +1018,12 @@ func (p *Manager) initializeLight(ctx context.Context) error { flistmod = stubs.NewFlisterStub(p.zbus) ) // fetching extected hash + env := environment.MustGet() + zdbFlistURL, err := url.JoinPath(env.FlistURL, flistRepo, flistName) + if err != nil { + return errors.Wrap(err, "failed to construct zdb flist url") + } + log.Debug().Msg("fetching flist hash") expected, err := flistmod.FlistHash(ctx, zdbFlistURL) if err != nil { @@ -1039,6 +1070,7 @@ func (p *Manager) initializeLight(ctx context.Context) error { } return nil } + func (p *Manager) upgradeRuntime(ctx context.Context, expected string, container pkg.ContainerID) error { var ( flistmod = stubs.NewFlisterStub(p.zbus) diff --git a/pkg/qsfsd/qsfs.go b/pkg/qsfsd/qsfs.go index fd1a5978..e4107e27 100644 --- a/pkg/qsfsd/qsfs.go +++ b/pkg/qsfsd/qsfs.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "net/url" "os" "os/exec" "path/filepath" @@ -15,13 +16,13 @@ import ( "github.com/rs/zerolog/log" "github.com/threefoldtech/zbus" "github.com/threefoldtech/zosbase/pkg" + "github.com/threefoldtech/zosbase/pkg/environment" "github.com/threefoldtech/zosbase/pkg/gridtypes" "github.com/threefoldtech/zosbase/pkg/gridtypes/zos" "github.com/threefoldtech/zosbase/pkg/stubs" ) const ( - qsfsFlist = "https://hub.grid.tf/tf-autobuilder/qsfs-0.2.0-rc2.flist" qsfsContainerNS = "qsfs" qsfsRootFsPropagation = pkg.RootFSPropagationSlave zstorSocket = "/var/run/zstor.sock" @@ -122,6 +123,13 @@ func (q *QSFS) Mount(wlID string, cfg zos.QuantumSafeFS) (info pkg.QSFSInfo, err if err != nil { return info, errors.Wrap(err, "failed to prepare qsfs") } + + env := environment.MustGet() + qsfsFlist, err := url.JoinPath(env.HubURL, "tf-autobuilder", "qsfs-0.2.0-rc2.flist") + if err != nil { + err = errors.Wrap(err, "failed to construct url") + return + } flistPath, err := flistd.Mount(ctx, wlID, qsfsFlist, pkg.MountOptions{ ReadOnly: false, Limit: cfg.Cache, @@ -195,7 +203,6 @@ func (f *QSFS) waitUntilMounted(ctx context.Context, path string) error { return fmt.Errorf("waiting for zdbfs mount %s timedout: context cancelled", path) } } - } func (f *QSFS) isMounted(path string) (bool, error) { diff --git a/pkg/upgrade/README.md b/pkg/upgrade/README.md index 607906c0..6ac17006 100644 --- a/pkg/upgrade/README.md +++ b/pkg/upgrade/README.md @@ -15,7 +15,7 @@ To run the upgrade module you first need to create a new upgrader instance with | Option | Description | Default | | :------------: | :------------------------------------------: | :-------------------: | | `NoZosUpgrade` | enable or disable the update of zos binaries | enabled by default | -| `Storage` | overrides the default hub storage url | `hub.grid.tf` | +| `Storage` | overrides the default hub storage url | `hub.threefold.me` | | `Zinit` | overrides the default zinit socket | "/var/run/zinit.sock" | ```go diff --git a/pkg/upgrade/hub/hub.go b/pkg/upgrade/hub/hub.go index 5c8ba4f8..d3f22988 100644 --- a/pkg/upgrade/hub/hub.go +++ b/pkg/upgrade/hub/hub.go @@ -20,12 +20,12 @@ import ( const ( // hubBaseURL base hub url - hubBaseURL = "https://hub.grid.tf/" - hubv4BaseURL = "https://v4.hub.grid.tf/" + hubBaseURL = "https://hub.threefold.me/" + hubv4BaseURL = "https://v4.hub.threefold.me" // hubStorage default hub db - hubStorage = "zdb://hub.grid.tf:9900" - hubv4Storage = "zdb://hub.grid.tf:9940" + hubStorage = "zdb://hub.threefold.me:9900" + hubv4Storage = "zdb://hub.threefold.me:9940" defaultHubCallTimeout = 20 * time.Second ) diff --git a/scripts/debug_image.md b/scripts/debug_image.md index 19f070b6..518476bd 100644 --- a/scripts/debug_image.md +++ b/scripts/debug_image.md @@ -19,7 +19,7 @@ sudo -i ./install_deps # run image from a directory -./debug_image.sh -d --image https://hub.grid.tf/omarabdulaziz.3bot/ubuntu-jammy.flist +./debug_image.sh -d --image https://hub.threefold.me/omarabdulaziz.3bot/ubuntu-jammy.flist ``` ## Image Types @@ -28,7 +28,7 @@ sudo -i the creation tutorial [here](../docs/manual/zmachine/zmachine.md) - Container: Contains only the rootfs. - in this case wil use kernel and initramfs from cloud container [flist](https://hub.grid.tf/tf-autobuilder/cloud-container-9dba60e.flist.md) + in this case wil use kernel and initramfs from cloud container [flist](https://hub.threefold.me/tf-autobuilder/cloud-container-9dba60e.flist.md) ## Flags diff --git a/scripts/debug_image.sh b/scripts/debug_image.sh index fbe9b01f..fd8beb2d 100755 --- a/scripts/debug_image.sh +++ b/scripts/debug_image.sh @@ -4,7 +4,7 @@ readonly SOCKET="/tmp/virtiofs.sock" readonly CH_API_SOCKET="/tmp/ch-api.sock" readonly OVERLAYFS="/tmp/overlay" -readonly CCFLIST="https://hub.grid.tf/tf-autobuilder/cloud-container-9dba60e.flist" +readonly CCFLIST="https://hub.threefold.me/tf-autobuilder/cloud-container-9dba60e.flist" readonly MACHINE_TYPE="machine" readonly CONTAINER_TYPE="container" From 0a89f06d07500f21df0edeeabc0733e8fb6a12f3 Mon Sep 17 00:00:00 2001 From: Eslam-Nawara Date: Mon, 16 Jun 2025 18:26:43 +0300 Subject: [PATCH 4/7] load huburl from zos-conf --- pkg/environment/config.go | 1 + pkg/environment/environment.go | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/environment/config.go b/pkg/environment/config.go index 211784a7..468023d9 100644 --- a/pkg/environment/config.go +++ b/pkg/environment/config.go @@ -37,6 +37,7 @@ type Config struct { KycURL string `json:"kyc_url"` RegistrarURL string `json:"registrar_url"` FlistURL string `json:"flist_url"` + HubURL string `json:"hub_url"` BinRepo string `json:"bin_repo"` } diff --git a/pkg/environment/environment.go b/pkg/environment/environment.go index 62da75ed..f75a2b57 100644 --- a/pkg/environment/environment.go +++ b/pkg/environment/environment.go @@ -334,12 +334,16 @@ func getEnvironmentFromParams(params kernel.Params) (Environment, error) { env.FlistURL = flist } + if hub := config.HubURL; len(hub) > 0 { + env.FlistURL = hub + } + if bin := config.BinRepo; len(bin) > 0 { env.FlistURL = bin } if kyc := config.KycURL; len(kyc) > 0 { - env.FlistURL = kyc + env.KycURL = kyc } if registrar := config.RegistrarURL; len(registrar) > 0 { From 35c21b42b397abef8c3a4b82b196b46f66679284 Mon Sep 17 00:00:00 2001 From: Eslam-Nawara Date: Mon, 16 Jun 2025 18:30:10 +0300 Subject: [PATCH 5/7] update hub storage --- pkg/upgrade/upgrade.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/upgrade/upgrade.go b/pkg/upgrade/upgrade.go index 5adc4c46..7a7a8211 100644 --- a/pkg/upgrade/upgrade.go +++ b/pkg/upgrade/upgrade.go @@ -42,8 +42,8 @@ var ( const ( service = "upgrader" - defaultHubStorage = "zdb://hub.grid.tf:9900" - defaultHubv4Storage = "zdb://hub.grid.tf:9940" + defaultHubStorage = "zdb://hub.threefold.me:9900" + defaultHubv4Storage = "zdb://v4.hub.threefold.me:9940" defaultZinitSocket = "/var/run/zinit.sock" checkForUpdateEvery = 60 * time.Minute From f20708ea5997e66da925044cfe510e3577651e21 Mon Sep 17 00:00:00 2001 From: Ashraf Fouda Date: Tue, 17 Jun 2025 10:33:23 +0300 Subject: [PATCH 6/7] fix typos in getting config from zos-config Signed-off-by: Ashraf Fouda --- pkg/environment/environment.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/environment/environment.go b/pkg/environment/environment.go index f75a2b57..e5110236 100644 --- a/pkg/environment/environment.go +++ b/pkg/environment/environment.go @@ -339,7 +339,7 @@ func getEnvironmentFromParams(params kernel.Params) (Environment, error) { } if bin := config.BinRepo; len(bin) > 0 { - env.FlistURL = bin + env.BinRepo = bin } if kyc := config.KycURL; len(kyc) > 0 { @@ -347,7 +347,7 @@ func getEnvironmentFromParams(params kernel.Params) (Environment, error) { } if registrar := config.RegistrarURL; len(registrar) > 0 { - env.FlistURL = registrar + env.RegistrarURL = registrar } if farmSecret, ok := params.Get("secret"); ok { From 239cdf7c3392acf9354cd9a775d24f66b579e95f Mon Sep 17 00:00:00 2001 From: Ashraf Fouda Date: Wed, 18 Jun 2025 12:51:38 +0300 Subject: [PATCH 7/7] fixing huburl Signed-off-by: Ashraf Fouda --- pkg/environment/environment.go | 2 +- pkg/primitives/vm-light/vm.go | 4 ++-- pkg/primitives/vm/vm.go | 2 +- pkg/primitives/zdb/zdb.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/environment/environment.go b/pkg/environment/environment.go index e5110236..be2ae748 100644 --- a/pkg/environment/environment.go +++ b/pkg/environment/environment.go @@ -335,7 +335,7 @@ func getEnvironmentFromParams(params kernel.Params) (Environment, error) { } if hub := config.HubURL; len(hub) > 0 { - env.FlistURL = hub + env.HubURL = hub } if bin := config.BinRepo; len(bin) > 0 { diff --git a/pkg/primitives/vm-light/vm.go b/pkg/primitives/vm-light/vm.go index a0d13160..0c41ad60 100644 --- a/pkg/primitives/vm-light/vm.go +++ b/pkg/primitives/vm-light/vm.go @@ -22,7 +22,7 @@ import ( ) const ( - cloudContainerName = "cloud-container" + cloudContainerName = "cloud-container" ) // ZMachine type @@ -217,7 +217,7 @@ func (p *Manager) virtualMachineProvisionImpl(ctx context.Context, wl *gridtypes // mount cloud-container flist (or reuse) which has kernel, initrd and also firmware env := environment.MustGet() - cloudContainerFlist, err := url.JoinPath(env.FlistURL, "tf-autobuilder", "cloud-container-9dba60e.flist") + cloudContainerFlist, err := url.JoinPath(env.HubURL, "tf-autobuilder", "cloud-container-9dba60e.flist") if err != nil { return zos.ZMachineLightResult{}, errors.Wrap(err, "failed to construct cloud-container flist url") } diff --git a/pkg/primitives/vm/vm.go b/pkg/primitives/vm/vm.go index ab0d2b30..8dc20e07 100644 --- a/pkg/primitives/vm/vm.go +++ b/pkg/primitives/vm/vm.go @@ -256,7 +256,7 @@ func (p *Manager) virtualMachineProvisionImpl(ctx context.Context, wl *gridtypes // mount cloud-container flist (or reuse) which has kernel, initrd and also firmware env := environment.MustGet() - cloudContainerFlist, err := url.JoinPath(env.FlistURL, "tf-autobuilder", "cloud-container-9dba60e.flist") + cloudContainerFlist, err := url.JoinPath(env.HubURL, "tf-autobuilder", "cloud-container-9dba60e.flist") if err != nil { return zos.ZMachineResult{}, errors.Wrap(err, "failed to construct cloud-container flist url") } diff --git a/pkg/primitives/zdb/zdb.go b/pkg/primitives/zdb/zdb.go index 0bd02910..dd4c70a9 100644 --- a/pkg/primitives/zdb/zdb.go +++ b/pkg/primitives/zdb/zdb.go @@ -257,7 +257,7 @@ func (p *Manager) zdbRootFS(ctx context.Context) (string, error) { var rootFS string env := environment.MustGet() - zdbFlistURL, err := url.JoinPath(env.FlistURL, flistRepo, flistName) + zdbFlistURL, err := url.JoinPath(env.HubURL, flistRepo, flistName) if err != nil { return "", errors.Wrap(err, "failed to construct zdb flist url") }