Now rendering the index.html using the Templ library.
This is in preparation for: 1. creating a base page 2. using tabs: Home, Using, Downloads, Status 3. htmx
This commit is contained in:
parent
d17ad9bc3e
commit
b1f7304eeb
6
Makefile
6
Makefile
@ -6,10 +6,14 @@
|
|||||||
fmt:
|
fmt:
|
||||||
go fmt ./...
|
go fmt ./...
|
||||||
|
|
||||||
|
|
||||||
|
generate:
|
||||||
|
templ generate
|
||||||
|
|
||||||
vet: fmt
|
vet: fmt
|
||||||
go vet ./...
|
go vet ./...
|
||||||
|
|
||||||
build: vet
|
build: generate vet
|
||||||
mkdir -p bin
|
mkdir -p bin
|
||||||
go build -o bin ./cmd/...
|
go build -o bin ./cmd/...
|
||||||
|
|
||||||
|
11
README.md
Normal file
11
README.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
|
||||||
|
* Environment
|
||||||
|
|
||||||
|
Go version 1.21
|
||||||
|
|
||||||
|
```
|
||||||
|
go install github.com/a-h/templ/cmd/templ@latest
|
||||||
|
|
||||||
|
|
||||||
|
```
|
@ -1,7 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"html/template"
|
"converge/pkg/templates"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -38,31 +38,22 @@ func (handler FileHandlerFilter) ServeHTTP(w http.ResponseWriter, r *http.Reques
|
|||||||
w.Header().Set("Pragma", "no-cache")
|
w.Header().Set("Pragma", "no-cache")
|
||||||
w.Header().Set("Expires", "0")
|
w.Header().Set("Expires", "0")
|
||||||
|
|
||||||
filters := make(map[string]string)
|
secure := ""
|
||||||
if r.TLS == nil {
|
if r.TLS == nil {
|
||||||
filters["secure"] = ""
|
secure = ""
|
||||||
} else {
|
} else {
|
||||||
filters["secure"] = "s"
|
secure = "s"
|
||||||
}
|
}
|
||||||
for _, header := range []string{"X-Forwarded-Proto", "X-Scheme", "X-Forwarded-Scheme"} {
|
for _, header := range []string{"X-Forwarded-Proto", "X-Scheme", "X-Forwarded-Scheme"} {
|
||||||
values := r.Header.Values(header)
|
values := r.Header.Values(header)
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
if strings.ToLower(value) == "https" {
|
if strings.ToLower(value) == "https" {
|
||||||
filters["secure"] = "s"
|
secure = "s"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
filters["host"] = r.Host
|
username, _ := os.LookupEnv("CONVERGE_USERNAME")
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles(filepath.Join(handler.dir, contextPath))
|
templates.Index(secure, r.Host, username).Render(
|
||||||
if err != nil {
|
r.Context(), w)
|
||||||
// let the filehandler generate the rror
|
|
||||||
handler.fileHandler.ServeHTTP(w, r)
|
|
||||||
}
|
|
||||||
filters["username"], _ = os.LookupEnv("CONVERGE_USERNAME")
|
|
||||||
err = tmpl.Execute(w, filters)
|
|
||||||
if err != nil {
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
// ok, tmpl has written the response
|
|
||||||
}
|
}
|
||||||
|
1
go.mod
1
go.mod
@ -16,6 +16,7 @@ require (
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
|
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
|
||||||
|
github.com/a-h/templ v0.2.747 // indirect
|
||||||
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
|
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
|
||||||
github.com/kr/fs v0.1.0 // indirect
|
github.com/kr/fs v0.1.0 // indirect
|
||||||
golang.org/x/sys v0.22.0 // indirect
|
golang.org/x/sys v0.22.0 // indirect
|
||||||
|
2
go.sum
2
go.sum
@ -2,6 +2,8 @@ github.com/ActiveState/termtest/conpty v0.5.0 h1:JLUe6YDs4Jw4xNPCU+8VwTpniYOGeKz
|
|||||||
github.com/ActiveState/termtest/conpty v0.5.0/go.mod h1:LO4208FLsxw6DcNZ1UtuGUMW+ga9PFtX4ntv8Ymg9og=
|
github.com/ActiveState/termtest/conpty v0.5.0/go.mod h1:LO4208FLsxw6DcNZ1UtuGUMW+ga9PFtX4ntv8Ymg9og=
|
||||||
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8=
|
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8=
|
||||||
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
|
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
|
||||||
|
github.com/a-h/templ v0.2.747 h1:D0dQ2lxC3W7Dxl6fxQ/1zZHBQslSkTSvl5FxP/CfdKg=
|
||||||
|
github.com/a-h/templ v0.2.747/go.mod h1:69ObQIbrcuwPCU32ohNaWce3Cb7qM5GMiqN1K+2yop4=
|
||||||
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
|
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
|
||||||
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
|
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
|
||||||
github.com/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0=
|
github.com/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0=
|
||||||
|
217
pkg/templates/index.templ
Normal file
217
pkg/templates/index.templ
Normal file
@ -0,0 +1,217 @@
|
|||||||
|
package templates
|
||||||
|
|
||||||
|
templ Index(secure string, host string, username string) {
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<link rel="stylesheet" href="css/bootstrap.min.css"
|
||||||
|
crossorigin="anonymous">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
|
<title>Converge</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<script src="js/bootstrap.bundle.min.js"
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<h1>About</h1>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Converge is a utility for troubleshooting builds on continuous integration servers.
|
||||||
|
It solves a common problem where the cause of job failure is difficult to determine.
|
||||||
|
This is complicated further by the fact that build jobs are usually run on a build
|
||||||
|
farm where there is no access to the build agents or in more modern envrionments when
|
||||||
|
jobs are run in ephemeral containers.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
With Converge it is possible to get remote shell access to such jobs. This works
|
||||||
|
by configuring the build job to connect to a Converge server using an agent program.
|
||||||
|
The agent program can be downloaded from within the CI job using curl or wget.
|
||||||
|
Next, an end-user can connect to the Converge server, a rendez-vous server, that connects
|
||||||
|
the client and server together.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The setup is such that the connection from client (end-user) to server (agent on CI job)
|
||||||
|
is end-to-end encrypted. The Converge server itself is no more than a bitpipe which pumps
|
||||||
|
data between client and agent.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Both ssh and sftp are supported. Multiple shells are also allowed.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
There is a timeout mechanism in the agent such that jobs do not hang indefinitely
|
||||||
|
waiting for a connection. This mechanism is useful to make sure build agents do not keep
|
||||||
|
build agents occupied for a long time. By default, the agent exits with status 0 when
|
||||||
|
the first client exits after logging in. This behavior as well as general expiry can be
|
||||||
|
controlled from within a shell session by touching a .hold file. After logging in, the
|
||||||
|
user can control expiry of the session as instructed by messages in the ssh session.
|
||||||
|
When the timeout of a session is near the user is informed about this with messages
|
||||||
|
in the shell.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h1>Usage</h1>
|
||||||
|
|
||||||
|
<h2>Continous integration jobs</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
In a continous integration job, download the agent, chmod it and run it.
|
||||||
|
</p>
|
||||||
|
<pre>{`
|
||||||
|
# linux
|
||||||
|
`}curl http{secure}://{host}/docs/agent > agent{`
|
||||||
|
chmod 755 agent
|
||||||
|
`}./agent --id ID ws{secure}://{host}{`
|
||||||
|
|
||||||
|
# windows
|
||||||
|
`}curl http{secure}://{host}/docs/agent.exe > agent.exe{`
|
||||||
|
`}agent --id ID ws{secure}://{host}{`
|
||||||
|
`}</pre>
|
||||||
|
<p>
|
||||||
|
Above, ID is a unique id for the job, the so-called rendez-cous ID. This should not conflict with IDs
|
||||||
|
used by other agents. The ID is used for a rendez-vous between the end-user on a local system and
|
||||||
|
the continuous integration job running on a build agent. If you don't specify an id, a random
|
||||||
|
id will be generated.
|
||||||
|
|
||||||
|
The agent to the converge server and tells it the ID. Clients can now connect to the Converge
|
||||||
|
server to establish a connection to the CI job through converge by also specifying the same
|
||||||
|
ID.
|
||||||
|
|
||||||
|
Communication between
|
||||||
|
end-user and agent is encrypted using SSH and the rendez-vous server is unable to
|
||||||
|
read the contents. The rendez-vous server is nothing more then a glorified bit pipe,
|
||||||
|
simply transferring data between end-user SSH client and the agent which runs an
|
||||||
|
embedded SSH server.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
NOTE: When running the agent on windows, an exit of the remote session using
|
||||||
|
exit in powershell or command prompt does not terminate the shell completely.
|
||||||
|
To terminate the client ssh session must be killed by closing the terminal.
|
||||||
|
Cleanup of remote processes on the agent appears to work properly despite this
|
||||||
|
problem. It is just that exit of the windows shell (powershell or command prompt)
|
||||||
|
is not detected properly.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The agent has more options, download the agent and run it without arguments to
|
||||||
|
see all options.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Local clients: using ssh with a proxy command </h2>
|
||||||
|
|
||||||
|
<p><code>wsproxy</code> is a command that can be used as a proxy command for SSH which performs the connection to the
|
||||||
|
remote server. This command needs to be downloaded only once (see <a href="#downloads">downloads</a> below). It does not depend on
|
||||||
|
the converge implementation but only on the websocket standards. Other tools that
|
||||||
|
provide a mapping of stdio to a websocket can also be used instead of wsproxy.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Next step is to run a local SSH or SFTP client:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
{`
|
||||||
|
`}ssh -oServerAliveInterval=10 -oProxyCommand="wsproxy ws{secure}://{host}/client/ID" { username }{"@localhost"} {`
|
||||||
|
`}sftp -oServerAliveInterval=10 -oProxyCommand="wsproxy ws{secure}://{host}/client/ID" { username }{"@localhost"} {`
|
||||||
|
`}</pre>
|
||||||
|
|
||||||
|
<h2>Local clients: using SSH with a local TCP forwarding proxy</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
This option is less convenient than the proxy command because it requires two separate
|
||||||
|
commands to execute.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Local clients can connect using regular ssh and sftp commands through a tunnel that
|
||||||
|
translates a local TCP port to a websocket connection in converge. See
|
||||||
|
the <a href="#downloads">downloads</a> section.
|
||||||
|
This runs a local client that allows SSH to port 10000 and connects to converge using
|
||||||
|
a websocket connection.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Next step is to run a local SSH of SFTP client:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre> {`
|
||||||
|
`}ssh -oServerAliveInterval=10 -p 10000 { username }{"@localhost"} {`
|
||||||
|
`}sftp -oServerAliveInterval=10 -oPort=10000 { username }{"@localhost"} {`
|
||||||
|
`}</pre>
|
||||||
|
|
||||||
|
<h2>Authentication</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The <code>{ username }</code> user above the Converge server and
|
||||||
|
communicated to the agent when the agent is started. This is the
|
||||||
|
username that must be used when setting up an ssh connection.
|
||||||
|
Another way to authenticate is through an .authorized_keys file in the
|
||||||
|
same directory as where the agent is started.
|
||||||
|
|
||||||
|
This can be setup as follows before starting the agent:
|
||||||
|
</p>
|
||||||
|
<pre> {`
|
||||||
|
`}# linux {`
|
||||||
|
`}echo "ssh-rsa dkddkdkkk a@b.c" > .authorized_keys {`
|
||||||
|
`}echo "ssh-rsa adfadjfdf d@e.f" >> .authorized_keys {`
|
||||||
|
`} {`
|
||||||
|
`}# windows {`
|
||||||
|
`}echo ssh-rsa dkddkdkkk a@b.c > .authorized_keys {`
|
||||||
|
`}echo ssh-rsa adfadjfdf d@e.f >> .authorized_keys
|
||||||
|
</pre>
|
||||||
|
<p>
|
||||||
|
Note that on windows you should not used quotes.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h1 id="downloads">Downloads</h1>
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Component</th>
|
||||||
|
<th>Purpose</th>
|
||||||
|
<th>Linux</th>
|
||||||
|
<th>Windows</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tr>
|
||||||
|
<td>agent</td>
|
||||||
|
<td>The agent to run inside aa CI job</td>
|
||||||
|
<td><a href="/docs/agent">agent</a></td>
|
||||||
|
<td><a href="/docs/agent.exe">agent.exe</a></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>wsproxy</td>
|
||||||
|
<td>SSH proxy command that can be directly used by ssh</td>
|
||||||
|
<td><a href="/docs/wsproxy">wsproxy</a></td>
|
||||||
|
<td><a href="/docs/wsproxy.exe">wsproxy.exe</a></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>tcptows</td>
|
||||||
|
<td>TCP to WS tunnel for allowing regular
|
||||||
|
SSH and SFTP clients to connect to converge</td>
|
||||||
|
<td><a href="/docs/tcptows">tcptows</a></td>
|
||||||
|
<td><a href="/docs/tcptows.exe">tcptows.exe</a></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
}
|
||||||
|
|
@ -117,8 +117,8 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
ssh -oServerAliveInterval=10 -oProxyCommand="wsproxy ws{{.secure}}://{{.host}}/client/ID" {{ .username }}@localhost
|
ssh -oServerAliveInterval=10 -oProxyCommand="wsproxy ws{{.secure}}://{{.host}}/client/ID" {{ .username }}@@localhost
|
||||||
sftp -oServerAliveInterval=10 -oProxyCommand="wsproxy ws{{.secure}}://{{.host}}/client/ID" {{ .username }}@localhost
|
sftp -oServerAliveInterval=10 -oProxyCommand="wsproxy ws{{.secure}}://{{.host}}/client/ID" {{ .username }}@@localhost
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<h2>Local clients: using SSH with a local TCP forwarding proxy</h2>
|
<h2>Local clients: using SSH with a local TCP forwarding proxy</h2>
|
||||||
@ -142,8 +142,8 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
ssh -oServerAliveInterval=10 -p 10000 {{ .username }}@localhost
|
ssh -oServerAliveInterval=10 -p 10000 {{ .username }}@@localhost
|
||||||
sftp -oServerAliveInterval=10 -oPort=10000 {{ .username }}@localhost
|
sftp -oServerAliveInterval=10 -oPort=10000 {{ .username }}@@localhost
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<h2>Authentication</h2>
|
<h2>Authentication</h2>
|
||||||
|
Loading…
Reference in New Issue
Block a user