Skip to content

Commit

Permalink
feat(ui): serve current doc on /docs (#5364)
Browse files Browse the repository at this point in the history
* feat(ui): serve current doc on /docs
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
  • Loading branch information
yesnault committed Aug 12, 2020
1 parent 215ce5b commit df0c712
Show file tree
Hide file tree
Showing 28 changed files with 52 additions and 59 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ COPY dist/cdsctl-* /app/
COPY dist/cds-worker-* /app/
COPY dist/sql.tar.gz /app/
COPY dist/ui.tar.gz /app/
COPY dist/cds-docs.tar.gz /app/

RUN groupadd -r cds && useradd --create-home -r -g cds cds
RUN chmod +w /app/panic_dumps && \
chmod +x /app/cds-engine-linux-amd64 && \
tar xzf /app/sql.tar.gz -C /app/sql && \
tar xzf /app/ui.tar.gz -C /app/ui_static_files && \
tar xzf /app/cds-docs.tar.gz -C /app/ui_static_files && \
mv /app/ui_static_files/cds-docs /app/ui_static_files/docs && \
chown -R cds:cds /app
USER cds
WORKDIR /app
Expand Down
5 changes: 3 additions & 2 deletions docs/config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
baseURL = "https://ovh.github.io/cds"
baseURL = ""
title = "CDS - Continuous Delivery Service"

languageCode = "en-us"
Expand All @@ -7,7 +7,8 @@ defaultContentLanguageInSubdir = false
contentDir = "content"

disableKinds = ["taxonomy", "taxonomyTerm"]
canonifyurls = true
canonifyurls = false
relativeURLs = true

[outputs]
home = [ "HTML", "RSS", "JSON"]
4 changes: 1 addition & 3 deletions docs/layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@
</script>
<script type="text/javascript" src="{{ "js/script.js" | relURL }}"></script>
<script type="text/javascript" src="{{ "js/lunr.min.js" | relURL}}"></script>
<script type="text/javascript">
var baseurl = "{{.Site.BaseURL}}";
<a id="indexJSON" href="{{ "./index.json" | relURL}}"></a>

</script>
<script type="text/javascript" src="{{ "js/auto-complete.js" | relURL}}"></script>
<script type="text/javascript" src="{{ "js/search.js" | relURL}}"></script>
<script type="text/javascript" src="{{ "js/asciinema-player.js" | relURL}}"></script>
9 changes: 1 addition & 8 deletions docs/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ function endsWith(str, suffix) {

// Initialize lunrjs using our generated index file
function initLunr() {
if (!endsWith(baseurl,"/")){
baseurl = baseurl+'/'
};

// First retrieve the index file
$.getJSON(baseurl +"index.json")
$.getJSON($('#indexJSON').attr('href'))
.done(function(index) {
pagesIndex = index;
// Set up lunrjs by declaring the fields we use
Expand Down Expand Up @@ -74,9 +70,6 @@ $( document ).ready(function() {
item.context = text;

var pathItem = item.uri;
if (pathItem.startsWith(baseurl)) {
pathItem = pathItem.slice(baseurl.length);
}
if (endsWith(pathItem,"/")) {
pathItem = pathItem.substring(0, pathItem.length-1);
};
Expand Down
9 changes: 0 additions & 9 deletions engine/api/mail/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,6 @@ Regards,
CDS Team
`

const templateReset = `Hi {{.Username}},
Your password was successfully reset.
Regards,
--
CDS Team
`

// Init initializes configuration
func Init(user, password, from, host, port string, tls, disable bool) {
smtpUser = user
Expand Down
1 change: 1 addition & 0 deletions engine/ui/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Service struct {
Cfg Configuration
Router *api.Router
HTMLDir string
DocsDir string
}

// Configuration is the ui configuration structure
Expand Down
3 changes: 2 additions & 1 deletion engine/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func (s *Service) ApplyConfiguration(config interface{}) error {
// HTMLDir must contains the ui dist directory.
// ui.tar.gz contains the dist directory
s.HTMLDir = filepath.Join(s.Cfg.Staticdir, "dist")
s.DocsDir = filepath.Join(s.Cfg.Staticdir, "docs")
s.Cfg.BaseURL = strings.TrimSpace(s.Cfg.BaseURL)
if s.Cfg.BaseURL == "" { // s.Cfg.BaseURL could not be empty
s.Cfg.BaseURL = "/"
Expand Down Expand Up @@ -257,7 +258,7 @@ func (s *Service) askForGettingStaticFiles(ctx context.Context, version string)

opts = append(opts, answerDoNothing)

ask := fmt.Sprintf("What do you want to do?")
ask := "What do you want to do?"

selected := cli.AskChoice(ask, opts...)

Expand Down
13 changes: 9 additions & 4 deletions engine/ui/ui_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ func (s *Service) initRouter(ctx context.Context) {
r.Mux.PathPrefix(s.Cfg.DeployURL + "/cdshooks").Handler(s.getReverseProxy(s.Cfg.DeployURL+"/cdshooks", s.Cfg.HooksURL))

// serve static UI files
r.Mux.PathPrefix("/").Handler(s.uiServe(http.Dir(s.HTMLDir)))
r.Mux.PathPrefix("/docs").Handler(s.uiServe(http.Dir(s.DocsDir), s.DocsDir))
r.Mux.PathPrefix("/").Handler(s.uiServe(http.Dir(s.HTMLDir), s.HTMLDir))
}

func (s *Service) getReverseProxy(path, urlRemote string) *httputil.ReverseProxy {
Expand All @@ -57,14 +58,18 @@ func (s *Service) getReverseProxy(path, urlRemote string) *httputil.ReverseProxy
return &httputil.ReverseProxy{Director: director}
}

func (s *Service) uiServe(fs http.FileSystem) http.Handler {
func (s *Service) uiServe(fs http.FileSystem, dir string) http.Handler {
fsh := http.FileServer(fs)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r.URL.Path = strings.TrimPrefix(r.URL.Path, s.Cfg.DeployURL)
if dir == s.DocsDir {
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/docs")
} else {
r.URL.Path = strings.TrimPrefix(r.URL.Path, s.Cfg.DeployURL)
}
filePath := path.Clean(r.URL.Path)
_, err := fs.Open(filePath)
if os.IsNotExist(err) {
http.ServeFile(w, r, filepath.Join(s.HTMLDir, "index.html"))
http.ServeFile(w, r, filepath.Join(dir, "index.html"))
return
}
fsh.ServeHTTP(w, r)
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/shared/conditions/conditions.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ <h4 class="inline">{{'workflow_node_condition_lua_title' | translate}}</h4>
</div>
<div>
<i class="book icon"></i><a
href="https://ovh.github.io/cds/docs/concepts/workflow/run-conditions" target="_blank"
href="/docs/docs/concepts/workflow/run-conditions" target="_blank"
rel="noopener noreferrer">{{'common_cds_documentation' | translate}}</a>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/shared/keys/form/keys.form.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<div class="KeyForm">
<div class="ui form">
<div class="ui info message" *ngIf="newKey.type == 'ssh'">
{{ 'keys_ssh_key_help' | translate }} <a href="https://ovh.github.io/cds/docs/components/worker/key/install/">Worker Install Key</a>
{{ 'keys_ssh_key_help' | translate }} <a href="/docs/docs/components/worker/key/install/">Worker Install Key</a>
</div>
<div class="ui info message" *ngIf="newKey.type == 'pgp'">
{{ 'keys_pgp_key_help' | translate }} <a href="https://ovh.github.io/cds/docs/components/worker/key/install/">Worker Install Key</a>
{{ 'keys_pgp_key_help' | translate }} <a href="/docs/docs/components/worker/key/install/">Worker Install Key</a>
</div>
<div class="fields">
<div class="seven wide field">
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/shared/requirements/form/requirements.form.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
</div>
<p>
<i class="fa fa-book"></i>
<a href="https://ovh.github.io/cds/docs/concepts/requirement/" target="_blank" rel="noopener noreferrer">
<a href="/docs/docs/concepts/requirement/" target="_blank" rel="noopener noreferrer">
{{ 'requirement_documentation' | translate }} </a>
</p>
<p [innerHtml]="helpType[newRequirement.type]"></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<div class="inline fields">
<div class="four wide field">
<label>
<a href="https://ovh.github.io/cds/docs/concepts/workflow/mutex" target="_blank" rel="noopener noreferrer">
<a href="/docs/docs/concepts/workflow/mutex" target="_blank" rel="noopener noreferrer">
{{ 'workflow_root_context_mutex' | translate }}
<i class="external icon"></i>
</a>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/shared/workflow/wizard/hook/hook.form.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="ui form">
<h3 class="inline">{{ 'workflow_node_hook_form_title' | translate }}</h3>
<div class="right floated mb15">
<i class="book icon"></i><a href="https://ovh.github.io/cds/docs/concepts/workflow/hooks/" target="_blank" rel="noopener noreferrer">{{'common_documentation' | translate}}</a>
<i class="book icon"></i><a href="/docs/docs/concepts/workflow/hooks/" target="_blank" rel="noopener noreferrer">{{'common_documentation' | translate}}</a>
</div>
<ng-container *ngIf="isRun">
<input class="ui fluid input" [value]="hook?.hook_model_name" [readOnly]="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<div class="ui toggle checkbox ml10">
<input type="checkbox" id="mutex" name="mutex" [(ngModel)]="node.context.mutex">
<label for="mutex">
<a href="https://ovh.github.io/cds/docs/concepts/workflow/mutex" target="_blank" rel="noopener noreferrer">
<a href="/docs/docs/concepts/workflow/mutex" target="_blank" rel="noopener noreferrer">
{{ 'workflow_root_context_mutex' | translate }}
<i class="external icon"></i>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="ui form">
<h3 class="inline">{{ 'workflow_node_hook_form_title' | translate }}</h3>
<div class="right floated mb15">
<i class="book icon"></i><a href="https://ovh.github.io/cds/docs/concepts/workflow/hooks" target="_blank"
<i class="book icon"></i><a href="/docs/docs/concepts/workflow/hooks" target="_blank"
rel="noopener noreferrer">{{'common_documentation' | translate}}</a>
</div>
<ng-container *ngIf="!loadingModels">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ <h2 class="ui header"><i class="fa fa-book"></i> {{ 'settings_tips' | translate
<i class="fa fa-question-circle"></i> {{'worker_model_help_howtos' | translate}}
<div class="ui list">
<a class="item" target="_blank" rel="noopener noreferrer"
href="https://ovh.github.io/cds/docs/tutorials/worker_model-docker/">{{'worker_model_help_howto_link_1'
href="/docs/docs/tutorials/worker_model-docker/">{{'worker_model_help_howto_link_1'
| translate}}</a>
<a class="item" target="_blank" rel="noopener noreferrer"
href="https://ovh.github.io/cds/docs/tutorials/worker_model-docker/docker-customized/">{{'worker_model_help_howto_link_2'
href="/docs/docs/tutorials/worker_model-docker/docker-customized/">{{'worker_model_help_howto_link_2'
| translate}}</a>
<a class="item" target="_blank" rel="noopener noreferrer"
href="https://ovh.github.io/cds/docs/tutorials/worker_model-openstack/">{{'worker_model_help_howto_link_3'
href="/docs/docs/tutorials/worker_model-openstack/">{{'worker_model_help_howto_link_3'
| translate}}</a>
<a class="item" target="_blank" rel="noopener noreferrer" href="https://ovh.github.io/cds/docs/concepts/worker-model/">{{'common_read_more'
<a class="item" target="_blank" rel="noopener noreferrer" href="/docs/docs/concepts/worker-model/">{{'common_read_more'
| translate}}</a>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/views/application/show/application.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<div>
<div class="ui list">
<a class="item" target="_blank" rel="noopener noreferrer"
href="https://ovh.github.io/cds/docs/tutorials/init_workflow_with_cdsctl/">
href="/docs/docs/tutorials/init_workflow_with_cdsctl/">
{{'common_read_more'| translate}}
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/views/navbar/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@
<a sm-item href="#" [routerLink]="['settings', 'queue']">{{ 'admin_queue_title' | translate }}</a>
<div class="divider"></div>
<a sm-item href="#" [routerLink]="['settings', 'downloads']">{{ 'navbar_downloads' | translate }}</a>
<a sm-item href="https://ovh.github.io/cds/" target="_blank" rel="noopener noreferrer">{{ 'navbar_documentation' | translate }}</a>
<a sm-item href="#" [routerLink]="['docs', '']" target="_blank" rel="noopener noreferrer">{{ 'navbar_documentation' | translate }}</a>
<div class="divider"></div>
<sm-checkbox class="theme-switch" name="switch-theme" [control]="themeSwitch" type="toggle"
label="{{'navbar_dark_mode' | translate}}" (change)="changeTheme()"></sm-checkbox>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/views/pipeline/show/pipeline.show.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<div>
<div class="ui list">
<a class="item" target="_blank" rel="noopener noreferrer"
href="https://ovh.github.io/cds/docs/tutorials/init_workflow_with_cdsctl/">
href="/docs/docs/tutorials/init_workflow_with_cdsctl/">
{{'common_read_more'| translate}}
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/views/settings/action/help/action.help.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="ui segment">
<h2 class="ui header"><i class="fa fa-book"></i> {{ 'settings_tips' | translate }}</h2>
<div class="ui list">
<a class="item" href="https://ovh.github.io/cds/docs/actions/" target="_blank" rel="noopener noreferrer">{{'action_help_line_1'
<a class="item" href="/docs/docs/actions/" target="_blank" rel="noopener noreferrer">{{'action_help_line_1'
| translate}}</a>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/views/settings/cdsctl/cdsctl.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ <h1>{{ 'cdsctl_title_5' | translate }}</h1>
<h1>{{ 'cdsctl_title_6' | translate }}</h1>

{{ 'cdsctl_title_6_info_1' | translate }}
(<a href="https://ovh.github.io/cds/docs/concepts/workflow/hooks/git-repo-webhook/">Git Repository
(<a href="/docs/docs/concepts/workflow/hooks/git-repo-webhook/">Git Repository
Webhook</a>).
{{ 'cdsctl_title_6_info_2' | translate }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
[(ngModel)]="workerModel.restricted" [disabled]="!workerModel.editable">
<label for="restricted">{{'worker_model_restricted_help' | translate}} <a
target="_blank" rel="noopener noreferrer"
href="https://ovh.github.io/cds/docs/concepts/worker-model/#what-s-a-restricted-worker-model">{{'common_see_documentation'
href="/docs/docs/concepts/worker-model/#what-s-a-restricted-worker-model">{{'common_see_documentation'
| translate}}</a></label>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ <h2 class="ui header"><i class="fa fa-book"></i> {{ 'settings_tips' | translate
<i class="fa fa-question-circle"></i> {{'worker_model_help_howtos' | translate}}
<div class="ui list">
<a class="item" target="_blank" rel="noopener noreferrer"
href="https://ovh.github.io/cds/docs/tutorials/worker_model-docker/">{{'worker_model_help_howto_link_1'
href="/docs/docs/tutorials/worker_model-docker/">{{'worker_model_help_howto_link_1'
| translate}}</a>
<a class="item" target="_blank" rel="noopener noreferrer"
href="https://ovh.github.io/cds/docs/tutorials/worker_model-docker/docker-customized/">{{'worker_model_help_howto_link_2'
href="/docs/docs/tutorials/worker_model-docker/docker-customized/">{{'worker_model_help_howto_link_2'
| translate}}</a>
<a class="item" target="_blank" rel="noopener noreferrer"
href="https://ovh.github.io/cds/docs/tutorials/worker_model-openstack/">{{'worker_model_help_howto_link_3'
href="/docs/docs/tutorials/worker_model-openstack/">{{'worker_model_help_howto_link_3'
| translate}}</a>
<a class="item" target="_blank" rel="noopener noreferrer"
href="https://ovh.github.io/cds/docs/concepts/worker-model/">{{'common_read_more'
href="/docs/docs/concepts/worker-model/">{{'common_read_more'
| translate}}</a>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ <h2 class="ui header"><i class="fa fa-book"></i> {{ 'settings_tips' | translate

<div class="ui list">
<a class="item" target="_blank" rel="noopener noreferrer"
href="https://ovh.github.io/cds/docs/concepts/template">{{'common_read_more'
href="/docs/docs/concepts/template">{{'common_read_more'
| translate}}</a>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<div class="fifteen wide field center ui info message"
*ngIf="!eventIntegrations || eventIntegrations.length === 0">
{{'workflow_no_event_integration' | translate }} <a
href="https://ovh.github.io/cds/docs/concepts/workflow/notifications/" target="_blank"
href="/docs/docs/concepts/workflow/notifications/" target="_blank"
rel="noopener noreferrer">{{'common_click_more_informations' | translate }}</a>
</div>
<div class="one wide field" *ngIf="eventIntegrations && eventIntegrations.length > 0">
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/views/workflow/workflow.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<div>
<div class="ui list">
<a class="item" target="_blank" rel="noopener noreferrer"
href="https://ovh.github.io/cds/docs/tutorials/init_workflow_with_cdsctl/">{{'common_read_more'
href="/docs/docs/tutorials/init_workflow_with_cdsctl/">{{'common_read_more'
| translate}}</a>
</div>
</div>
Expand Down Expand Up @@ -71,7 +71,7 @@
<p>{{'workflow_template_help_line_2' | translate}}</p>
<div class="ui list">
<a class="item" target="_blank" rel="noopener noreferrer"
href="https://ovh.github.io/cds/docs/concepts/template">{{'common_read_more'
href="/docs/docs/concepts/template">{{'common_read_more'
| translate}}</a>
</div>
<p>{{'workflow_template_help_line_3' | translate}}</p>
Expand Down
Loading

0 comments on commit df0c712

Please sign in to comment.