Skip to content

Commit

Permalink
feat(runner): display variants of usage on web
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftin committed Feb 2, 2025
1 parent fc086df commit 8c8857e
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 52 deletions.
6 changes: 1 addition & 5 deletions api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,7 @@ func serveFile(w http.ResponseWriter, r *http.Request, name string) {
}

func getSystemInfo(w http.ResponseWriter, r *http.Request) {
host := ""

if util.WebHostURL != nil {
host = util.WebHostURL.String()
}
host := util.GetPublicHost()

var authMethods LoginAuthMethods

Expand Down
9 changes: 8 additions & 1 deletion util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ func LookupDefaultApps() {
}
}

func GetPublicAliasURL(scope string, alias string) string {
func GetPublicHost() string {
aliasURL := Config.WebHost
port := Config.Port
if port == "" {
Expand All @@ -908,6 +908,13 @@ func GetPublicAliasURL(scope string, alias string) string {
aliasURL = "http://localhost:" + port
}

return aliasURL

}

func GetPublicAliasURL(scope string, alias string) string {
aliasURL := GetPublicHost()

if !strings.HasSuffix(aliasURL, "/") {
aliasURL += "/"
}
Expand Down
155 changes: 110 additions & 45 deletions web/src/views/Runners.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template xmlns:v-slot="http://www.w3.org/1999/XSL/Transform">
<div v-if="items != null">

<v-toolbar flat >
<v-toolbar flat>
<v-app-bar-nav-icon @click="showDrawer()"></v-app-bar-nav-icon>
<v-toolbar-title>
{{ $t('dashboard2') }}
Expand Down Expand Up @@ -89,49 +89,96 @@
</div>
</div>

<div class="mb-4">
<div>{{ $t('runnerUsage') }}</div>
<div style="position: relative;">
<pre style="white-space: pre-wrap;
background: gray;
color: white;
border-radius: 10px;
margin-top: 5px;"
class="pa-2"
>{{ runnerUsageCommand }}</pre>

<v-btn
style="position: absolute; right: 10px; top: 10px;"
icon
color="white"
@click="copyToClipboard(runnerUsageCommand)"
>
<v-icon>mdi-content-copy</v-icon>
</v-btn>
</div>
</div>

<div>
<div>{{ $t('runnerDockerCommand') }}</div>
<div style="position: relative;">
<pre style="white-space: pre-wrap;
background: gray;
color: white;
border-radius: 10px;
margin-top: 5px;"
class="pa-2"
>{{ runnerDockerCommand }}</pre>

<v-btn
style="position: absolute; right: 10px; top: 10px;"
icon
color="white"
@click="copyToClipboard(runnerDockerCommand)"
>
<v-icon>mdi-content-copy</v-icon>
</v-btn>
</div>
</div>
<v-tabs v-model="usageTab" :show-arrows="false">
<v-tab key="config">Config file</v-tab>
<v-tab key="setup">Setup</v-tab>
<v-tab key="env">Env Vars</v-tab>
<v-tab key="docker">Docker</v-tab>
</v-tabs>

<v-tabs-items v-model="usageTab">
<v-tab-item key="config">
<div style="position: relative;">
<pre style="overflow: auto;
background: gray;
color: white;
border-radius: 10px;
margin-top: 5px;"
class="pa-2"
>{{ runnerConfigCommand }}</pre>

<v-btn
style="position: absolute; right: 10px; top: 10px;"
icon
color="white"
@click="copyToClipboard(runnerEnvCommand)"
>
<v-icon>mdi-content-copy</v-icon>
</v-btn>
</div>
</v-tab-item>
<v-tab-item key="setup">
<div style="position: relative;">
<pre style="overflow: auto;
background: gray;
color: white;
border-radius: 10px;
margin-top: 5px;"
class="pa-2"
>{{ runnerSetupCommand }}</pre>

<v-btn
style="position: absolute; right: 10px; top: 10px;"
icon
color="white"
@click="copyToClipboard(runnerSetupCommand)"
>
<v-icon>mdi-content-copy</v-icon>
</v-btn>
</div>
</v-tab-item>
<v-tab-item key="env">
<div style="position: relative;">
<pre style="overflow: auto;
background: gray;
color: white;
border-radius: 10px;
margin-top: 5px;"
class="pa-2"
>{{ runnerEnvCommand }}</pre>

<v-btn
style="position: absolute; right: 10px; top: 10px;"
icon
color="white"
@click="copyToClipboard(runnerEnvCommand)"
>
<v-icon>mdi-content-copy</v-icon>
</v-btn>
</div>
</v-tab-item>

<v-tab-item key="docker">
<div style="position: relative;">
<pre style="overflow: auto;
background: gray;
color: white;
border-radius: 10px;
margin-top: 5px;"
class="pa-2"
>{{ runnerDockerCommand }}</pre>

<v-btn
style="position: absolute; right: 10px; top: 10px;"
icon
color="white"
@click="copyToClipboard(runnerDockerCommand)"
>
<v-icon>mdi-content-copy</v-icon>
</v-btn>
</div>
</v-tab-item>
</v-tabs-items>
</div>
</template>
</EditDialog>
Expand Down Expand Up @@ -257,16 +304,33 @@ export default {
},
computed: {
runnerUsageCommand() {
runnerConfigCommand() {
return `{
"web_host": "${this.webHost}",
"runner": {
"token": "${(this.newRunner || {}).token}",
"private_key_file": "/path/to/the/private/key"
}
}`;
},
runnerSetupCommand() {
return 'semaphore runner setup';
},
runnerEnvCommand() {
return `SEMAPHORE_WEB_ROOT=${this.webHost} \\
SEMAPHORE_RUNNER_TOKEN=${(this.newRunner || {}).token} \\
SEMAPHORE_RUNNER_PRIVATE_KEY_FILE=/path/to/the/private/key \\
semaphore runner --no-config`;
},
runnerDockerCommand() {
return `docker run \\
-e SEMAPHORE_WEB_ROOT=${this.webHost} \\
-e SEMAPHORE_RUNNER_TOKEN=${(this.newRunner || {}).token} \\
-e SEMAPHORE_RUNNER_PRIVATE_KEY_FILE=/config.runner.key \\
-v "/path/to/the/private/key:/config.runner.key" \\
-d semaphoreui/runner:${this.version}`;
},
},
Expand All @@ -275,6 +339,7 @@ semaphore runner --no-config`;
return {
newRunnerTokenDialog: null,
newRunner: null,
usageTab: null,
};
},
Expand Down
4 changes: 3 additions & 1 deletion web/src/views/project/template/TemplateTerraformState.vue
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@
<v-btn
color="hsl(348deg, 86%, 61%)"
href="https://semaphoreui.com/pro"
>Upgrade
>
Learn more
<v-icon>mdi-chevron-right</v-icon>
</v-btn>
</v-alert>

Expand Down

0 comments on commit 8c8857e

Please sign in to comment.