Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbb5f5f2

Browse files
committed
feat: bundle a local version of install.sh
1 parent0008c13 commitbb5f5f2

File tree

4 files changed

+487
-6
lines changed

4 files changed

+487
-6
lines changed

‎Makefile

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,17 @@ site/node_modules/.installed: site/package.json
399399
cd site/
400400
../scripts/pnpm_install.sh
401401

402-
site/out/index.html: site/node_modules/.installed$(shell find ./site$(FIND_EXCLUSIONS) -type f \( -name '*.ts' -o -name '*.tsx' \))
402+
SITE_GEN_FILES :=\
403+
site/src/api/typesGenerated.ts\
404+
site/src/api/rbacresourcesGenerated.ts\
405+
site/src/api/countriesGenerated.ts\
406+
site/src/theme/icons.json
407+
408+
site/out/index.html:\
409+
site/node_modules/.installed\
410+
site/static/install.sh\
411+
$(SITE_GEN_FILES)\
412+
$(shell find ./site$(FIND_EXCLUSIONS) -type f \( -name '*.ts' -o -name '*.tsx' \))
403413
cd site/
404414
# prevents this directory from getting to big, and causing "too much data" errors
405415
rm -rf out/assets/
@@ -541,22 +551,21 @@ GEN_FILES := \
541551
provisionersdk/proto/provisioner.pb.go\
542552
provisionerd/proto/provisionerd.pb.go\
543553
vpn/vpn.pb.go\
544-
site/src/api/typesGenerated.ts\
554+
$(DB_GEN_FILES)\
555+
$(SITE_GEN_FILES)\
545556
coderd/rbac/object_gen.go\
546557
codersdk/rbacresources_gen.go\
547-
site/src/api/rbacresourcesGenerated.ts\
548-
site/src/api/countriesGenerated.ts\
549558
docs/admin/integrations/prometheus.md\
550559
docs/reference/cli/index.md\
551560
docs/admin/security/audit-logs.md\
552561
coderd/apidoc/swagger.json\
553562
provisioner/terraform/testdata/version\
554563
site/e2e/provisionerGenerated.ts\
555-
site/src/theme/icons.json\
556564
examples/examples.gen.json\
557565
$(TAILNETTEST_MOCKS)\
558566
coderd/database/pubsub/psmock/psmock.go
559567

568+
560569
# all gen targets should be added here and to gen/mark-fresh
561570
gen: gen/db$(GEN_FILES)
562571
.PHONY: gen

‎site/site.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ func New(opts *Options) *Handler {
160160
handler.buildInfoJSON=html.EscapeString(string(buildInfoResponse))
161161
handler.handler=mux.ServeHTTP
162162

163+
handler.installScript,err=parseInstallScript(opts.SiteFS,opts.BuildInfo)
164+
iferr!=nil {
165+
_=xerrors.Errorf("install.sh will be unavailable: %w",err)
166+
}
167+
163168
returnhandler
164169
}
165170

@@ -169,8 +174,8 @@ type Handler struct {
169174
secureHeaders*secure.Secure
170175
handler http.HandlerFunc
171176
htmlTemplates*template.Template
172-
173177
buildInfoJSONstring
178+
installScript []byte
174179

175180
// RegionsFetcher will attempt to fetch the more detailed WorkspaceProxy data, but will fall back to the
176181
// regions if the user does not have the correct permissions.
@@ -217,6 +222,16 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
217222
// If the asset does not exist, this will return a 404.
218223
h.handler.ServeHTTP(rw,r)
219224
return
225+
// If requesting the install.sh script, respond with the preprocessed version
226+
// which contains the correct hostname and version information.
227+
casereqFile=="install.sh":
228+
ifh.installScript==nil {
229+
http.NotFound(rw,r)
230+
return
231+
}
232+
rw.Header().Add("Content-Type","text/plain; charset=utf-8")
233+
http.ServeContent(rw,r,reqFile, time.Time{},bytes.NewReader(h.installScript))
234+
return
220235
// If the original file path exists we serve it.
221236
caseh.exists(reqFile):
222237
ifShouldCacheFile(reqFile) {
@@ -533,6 +548,32 @@ func findAndParseHTMLFiles(files fs.FS) (*template.Template, error) {
533548
returnroot,nil
534549
}
535550

551+
typeinstallScriptStatestruct {
552+
Originstring
553+
Versionstring
554+
}
555+
556+
funcparseInstallScript(files fs.FS,buildInfo codersdk.BuildInfoResponse) ([]byte,error) {
557+
scriptFile,err:=fs.ReadFile(files,"install.sh")
558+
iferr!=nil {
559+
returnnil,err
560+
}
561+
562+
script,err:=template.New("install.sh").Parse(string(scriptFile))
563+
iferr!=nil {
564+
returnnil,err
565+
}
566+
567+
varbuf bytes.Buffer
568+
state:=installScriptState{Origin:buildInfo.DashboardURL,Version:buildInfo.Version}
569+
err=script.Execute(&buf,state)
570+
iferr!=nil {
571+
returnnil,err
572+
}
573+
574+
returnbuf.Bytes(),nil
575+
}
576+
536577
// ExtractOrReadBinFS checks the provided fs for compressed coder binaries and
537578
// extracts them into dest/bin if found. As a fallback, the provided FS is
538579
// checked for a /bin directory, if it is non-empty it is returned. Finally

‎site/site_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ func TestServingFiles(t *testing.T) {
207207
"dashboard.css":&fstest.MapFile{
208208
Data: []byte("dashboard-css-bytes"),
209209
},
210+
"install.sh":&fstest.MapFile{
211+
Data: []byte("install-sh-bytes"),
212+
},
210213
}
211214
binFS:=http.FS(fstest.MapFS{})
212215

@@ -248,6 +251,9 @@ func TestServingFiles(t *testing.T) {
248251
// JS, CSS cases
249252
{"/dashboard.js","dashboard-js-bytes"},
250253
{"/dashboard.css","dashboard-css-bytes"},
254+
255+
// Install script
256+
{"/install.sh","install-sh-bytes"},
251257
}
252258

253259
for_,testCase:=rangetestCases {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp