Skip to content

feat: add a page to showcase the local installation script #16122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
yaaay
  • Loading branch information
aslilac committed Jan 11, 2025
commit 6a0d1cb1f41f28a48f20e35c89b6ff21100b7428
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,17 @@ site/node_modules/.installed: site/package.json
cd site/
../scripts/pnpm_install.sh

site/out/index.html: site/node_modules/.installed $(shell find ./site $(FIND_EXCLUSIONS) -type f \( -name '*.ts' -o -name '*.tsx' \))
SITE_GEN_FILES := \
site/src/api/typesGenerated.ts \
site/src/api/rbacresourcesGenerated.ts \
site/src/api/countriesGenerated.ts \
site/src/theme/icons.json

site/out/index.html: \
site/node_modules/.installed \
site/static/install.sh \
$(SITE_GEN_FILES) \
$(shell find ./site $(FIND_EXCLUSIONS) -type f \( -name '*.ts' -o -name '*.tsx' \))
cd site/
# prevents this directory from getting to big, and causing "too much data" errors
rm -rf out/assets/
Expand Down Expand Up @@ -542,22 +552,20 @@ GEN_FILES := \
vpn/vpn.pb.go \
coderd/database/dump.sql \
$(DB_GEN_FILES) \
site/src/api/typesGenerated.ts \
$(SITE_GEN_FILES) \
coderd/rbac/object_gen.go \
codersdk/rbacresources_gen.go \
site/src/api/rbacresourcesGenerated.ts \
site/src/api/countriesGenerated.ts \
docs/admin/integrations/prometheus.md \
docs/reference/cli/index.md \
docs/admin/security/audit-logs.md \
coderd/apidoc/swagger.json \
provisioner/terraform/testdata/version \
site/e2e/provisionerGenerated.ts \
site/src/theme/icons.json \
examples/examples.gen.json \
$(TAILNETTEST_MOCKS) \
coderd/database/pubsub/psmock/psmock.go


# all gen targets should be added here and to gen/mark-fresh
gen: $(GEN_FILES)
.PHONY: gen
Expand Down
43 changes: 42 additions & 1 deletion site/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ func New(opts *Options) *Handler {
handler.buildInfoJSON = html.EscapeString(string(buildInfoResponse))
handler.handler = mux.ServeHTTP

handler.installScript, err = parseInstallScript(opts.SiteFS, opts.BuildInfo)
if err != nil {
panic("failed to parse install script")
}

return handler
}

Expand All @@ -169,8 +174,8 @@ type Handler struct {
secureHeaders *secure.Secure
handler http.HandlerFunc
htmlTemplates *template.Template

buildInfoJSON string
installScript []byte

// RegionsFetcher will attempt to fetch the more detailed WorkspaceProxy data, but will fall back to the
// regions if the user does not have the correct permissions.
Expand Down Expand Up @@ -217,6 +222,11 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
// If the asset does not exist, this will return a 404.
h.handler.ServeHTTP(rw, r)
return
// If requesting the install.sh script, fill in the template with the
// appropriate hostname and version info.
case reqFile == "install.sh":
h.serveInstallScript(rw, r)
return
// If the original file path exists we serve it.
case h.exists(reqFile):
if ShouldCacheFile(reqFile) {
Expand Down Expand Up @@ -306,6 +316,11 @@ func ShouldCacheFile(reqFile string) bool {
return true
}

func (h *Handler) serveInstallScript(rw http.ResponseWriter, r *http.Request) {
rw.Header().Add("content-type", "text/plain; charset=utf-8")
http.ServeContent(rw, r, "install.sh", time.Time{}, bytes.NewReader(h.installScript))
}

func (h *Handler) serveHTML(resp http.ResponseWriter, request *http.Request, reqPath string, state htmlState) bool {
if data, err := h.renderHTMLWithState(request, reqPath, state); err == nil {
if reqPath == "" {
Expand Down Expand Up @@ -533,6 +548,32 @@ func findAndParseHTMLFiles(files fs.FS) (*template.Template, error) {
return root, nil
}

type installScriptState struct {
Origin string
Version string
}

func parseInstallScript(files fs.FS, buildInfo codersdk.BuildInfoResponse) ([]byte, error) {
scriptFile, err := fs.ReadFile(files, "install.sh")
if err != nil {
return []byte{}, err
}

script, err := template.New("install.sh").Parse(string(scriptFile))
if err != nil {
return []byte{}, err
}

var buf bytes.Buffer
state := installScriptState{Origin: buildInfo.DashboardURL, Version: buildInfo.Version}
err = script.Execute(&buf, state)
if err != nil {
return []byte{}, err
}

return buf.Bytes(), err
}

// ExtractOrReadBinFS checks the provided fs for compressed coder binaries and
// extracts them into dest/bin if found. As a fallback, the provided FS is
// checked for a /bin directory, if it is non-empty it is returned. Finally
Expand Down
Loading
Loading