Monorepo for Tangled
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

appview/sites: use repoIdentifier for archive requests

we could just use the knotmirror here directly instead of deploying from
the knot, but we'd need the knotmirror to update before the site. for
now just deploy from the knot.

Signed-off-by: oppiliappan <me@oppi.li>

+19 -20
+1 -7
appview/repo/settings.go
··· 295 295 if ownerClaim == nil { 296 296 rp.logger.Info("skipping deploy: no active domain claim", "repo", f.RepoIdentifier()) 297 297 } else if rp.cfClient.Enabled() { 298 - scheme := "http" 299 - if !rp.config.Core.Dev { 300 - scheme = "https" 301 - } 302 - knotHost := fmt.Sprintf("%s://%s", scheme, f.Knot) 303 - 304 298 go func() { 305 299 ctx := context.Background() 306 300 ··· 311 305 Trigger: models.SiteDeployTriggerConfigChange, 312 306 } 313 307 314 - deployErr := sites.Deploy(ctx, rp.cfClient, knotHost, f.Did, f.Name, branch, dir) 308 + deployErr := sites.Deploy(ctx, rp.cfClient, rp.config, f, branch, dir) 315 309 if deployErr != nil { 316 310 l.Error("sites: initial R2 sync failed", "repo", f.RepoIdentifier(), "err", deployErr) 317 311 deploy.Status = models.SiteDeployStatusFailure
+16 -5
appview/sites/sites.go
··· 16 16 indigoxrpc "github.com/bluesky-social/indigo/xrpc" 17 17 "tangled.org/core/api/tangled" 18 18 "tangled.org/core/appview/cloudflare" 19 + "tangled.org/core/appview/config" 20 + "tangled.org/core/appview/models" 19 21 ) 20 22 21 23 // DomainMapping is the value stored in Workers KV, keyed by the bare domain. ··· 114 116 func Deploy( 115 117 ctx context.Context, 116 118 cf *cloudflare.Client, 117 - knotHost, repoDid, repoName, branch, deployDir string, 119 + config *config.Config, 120 + f *models.Repo, 121 + branch string, 122 + deployDir string, 118 123 ) error { 119 124 tmpDir, err := os.MkdirTemp("", "tangled-sites-*") 120 125 if err != nil { ··· 122 127 } 123 128 defer os.RemoveAll(tmpDir) 124 129 125 - if err := extractArchive(ctx, knotHost, repoDid, repoName, branch, tmpDir); err != nil { 130 + if err := extractArchive(ctx, config, f, branch, tmpDir); err != nil { 126 131 return fmt.Errorf("extracting archive: %w", err) 127 132 } 128 133 ··· 153 158 return fmt.Errorf("walking deploy dir: %w", err) 154 159 } 155 160 156 - if err := cf.SyncFiles(ctx, prefix(repoDid, repoName), files); err != nil { 161 + if err := cf.SyncFiles(ctx, prefix(f.Did, f.Name), files); err != nil { 157 162 return fmt.Errorf("syncing files to R2: %w", err) 158 163 } 159 164 ··· 170 175 171 176 // extractArchive fetches the tar.gz archive for the given repo+branch from 172 177 // the knot via XRPC and extracts it into destDir. 173 - func extractArchive(ctx context.Context, knotHost, repoDid, repoName, branch, destDir string) error { 178 + func extractArchive(ctx context.Context, config *config.Config, f *models.Repo, branch, destDir string) error { 179 + scheme := "https" 180 + if config.Core.Dev { 181 + scheme = "http" 182 + } 183 + knotHost := fmt.Sprintf("%s://%s", scheme, f.Knot) 184 + 174 185 xrpcc := &indigoxrpc.Client{Host: knotHost} 175 - data, err := tangled.RepoArchive(ctx, xrpcc, "tar.gz", "", branch, repoDid+"/"+repoName) 186 + data, err := tangled.RepoArchive(ctx, xrpcc, "tar.gz", "", branch, f.RepoIdentifier()) 176 187 if err != nil { 177 188 return fmt.Errorf("fetching archive: %w", err) 178 189 }
+2 -8
appview/state/knotstream.go
··· 158 158 159 159 // triggerSitesDeployIfNeeded checks whether the pushed ref matches the sites 160 160 // branch configured for this repo and, if so, syncs the site to R2 161 - func triggerSitesDeployIfNeeded(ctx context.Context, d *db.DB, cfClient *cloudflare.Client, c *config.Config, record tangled.GitRefUpdate, source ec.Source) { 161 + func triggerSitesDeployIfNeeded(ctx context.Context, d *db.DB, cfClient *cloudflare.Client, cfg *config.Config, record tangled.GitRefUpdate, source ec.Source) { 162 162 logger := log.FromContext(ctx) 163 163 164 164 ref := plumbing.ReferenceName(record.Ref) ··· 185 185 return 186 186 } 187 187 188 - scheme := "https" 189 - if c.Core.Dev { 190 - scheme = "http" 191 - } 192 - knotHost := fmt.Sprintf("%s://%s", scheme, source.Key()) 193 - 194 188 deploy := &models.SiteDeploy{ 195 189 RepoAt: repo.RepoAt().String(), 196 190 Branch: siteConfig.Branch, ··· 199 193 Trigger: models.SiteDeployTriggerPush, 200 194 } 201 195 202 - deployErr := sites.Deploy(ctx, cfClient, knotHost, repo.RepoIdentifier(), record.RepoName, siteConfig.Branch, siteConfig.Dir) 196 + deployErr := sites.Deploy(ctx, cfClient, cfg, repo, siteConfig.Branch, siteConfig.Dir) 203 197 if deployErr != nil { 204 198 logger.Error("sites: R2 sync failed on push", "repo", repo.RepoIdentifier(), "err", deployErr) 205 199 deploy.Status = models.SiteDeployStatusFailure