Skip to content

Commit

Permalink
Start the reverse proxy but don't use it
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay committed Nov 28, 2023
1 parent 9b19615 commit be39ce7
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 14 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
run: |
sudo apt-get update && sudo apt-get install -y libolm3 libolm-dev
go install -v github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
docker pull ghcr.io/matrix-org/complement-crypto-reverse-proxy:latest
# Install whatever version of the JS SDK is in package.json
- name: Build JS SDK
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ Why:
### How do I run it?
It's currently pretty awful to run, as you need toolchains for both Rust and JS. Working on improving this.

You need this image:
```
docker pull ghcr.io/matrix-org/complement-crypto-reverse-proxy:latest
```

You need to build Rust SDK FFI bindings _and_ JS SDK before you can get this to run. You also need a Complement homeserver image. When that is setup:

```
Expand Down
4 changes: 3 additions & 1 deletion cmd/reverseproxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ $ docker run --rm -e "REVERSE_PROXY_CONTROLLER_URL=http://somewhere-tests-are-li
```
Then tell clients to connect to the reverse proxy on the respective port.

This is handled for you by complement-crypto by default.
This is handled for you by complement-crypto by default.

This docker image is uploaded to `ghcr.io/matrix-org/complement-crypto-reverse-proxy:latest`.
66 changes: 53 additions & 13 deletions internal/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import (

type SlidingSyncDeployment struct {
complement.Deployment
postgres testcontainers.Container
slidingSync testcontainers.Container
slidingSyncURL string
tcpdump *exec.Cmd
ReverseProxyController *ReverseProxyController
postgres testcontainers.Container
slidingSync testcontainers.Container
reverseProxy testcontainers.Container
slidingSyncURL string
tcpdump *exec.Cmd
}

func (d *SlidingSyncDeployment) SlidingSyncURL(t *testing.T) string {
Expand Down Expand Up @@ -52,6 +54,12 @@ func (d *SlidingSyncDeployment) Teardown(writeLogs bool) {
log.Fatalf("failed to stop postgres: %s", err)
}
}
if d.reverseProxy != nil {
d.ReverseProxyController.Terminate()
if err := d.reverseProxy.Terminate(context.Background()); err != nil {
log.Fatalf("failed to stop reverse proxy: %s", err)
}
}
if d.tcpdump != nil {
fmt.Println("Sent SIGINT to tcpdump, waiting for it to exit, err=", d.tcpdump.Process.Signal(os.Interrupt))
fmt.Println("tcpdump finished, err=", d.tcpdump.Wait())
Expand All @@ -67,6 +75,35 @@ func RunNewDeployment(t *testing.T, shouldTCPDump bool) *SlidingSyncDeployment {
deployment := complement.Deploy(t, 2)
networkName := deployment.Network()

controller := NewReverseProxyController()
controllerPort, err := controller.Listen()
if err != nil {
t.Fatalf("reverse proxy controller failed to listen: %v", err)
}

// make a reverse proxy.
hs1ExposedPort := "3000/tcp"
hs2ExposedPort := "3001/tcp"
rpContainer, err := testcontainers.GenericContainer(context.Background(), testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "ghcr.io/matrix-org/complement-crypto-reverse-proxy:latest",
ExposedPorts: []string{hs1ExposedPort, hs2ExposedPort},
Env: map[string]string{
"REVERSE_PROXY_CONTROLLER_URL": fmt.Sprintf("http://host.docker.internal:", controllerPort),
"REVERSE_PROXY_HOSTS": "http://hs1,3000;http://hs2,3001",
},
WaitingFor: wait.ForLog("listening"),
Networks: []string{networkName},
NetworkAliases: map[string][]string{
networkName: {"reverseproxy"},
},
},
Started: true,
})
must.NotError(t, "failed to start reverse proxy container", err)
rpHS1URL := externalURL(t, rpContainer, hs1ExposedPort)
rpHS2URL := externalURL(t, rpContainer, hs2ExposedPort)

// Make a postgres container
postgresContainer, err := testcontainers.GenericContainer(context.Background(), testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Expand Down Expand Up @@ -119,11 +156,12 @@ func RunNewDeployment(t *testing.T, shouldTCPDump bool) *SlidingSyncDeployment {

// log for debugging purposes
t.Logf("SlidingSyncDeployment created (network=%s):", networkName)
t.Logf(" NAME INT EXT")
t.Logf(" sliding sync: ssproxy %s", ssURL)
t.Logf(" synapse: hs1 %s", csapi1.BaseURL)
t.Logf(" synapse: hs2 %s", csapi2.BaseURL)
t.Logf(" NAME INT EXT")
t.Logf(" sliding sync: ssproxy %s", ssURL)
t.Logf(" synapse: hs1 %s", csapi1.BaseURL)
t.Logf(" synapse: hs2 %s", csapi2.BaseURL)
t.Logf(" postgres: postgres")
t.Logf(" reverseproxy: reverseproxy hs1=%s hs2=%s", rpHS1URL, rpHS2URL)
var cmd *exec.Cmd
if shouldTCPDump {
t.Log("Running tcpdump...")
Expand All @@ -140,11 +178,13 @@ func RunNewDeployment(t *testing.T, shouldTCPDump bool) *SlidingSyncDeployment {
t.Logf("Started tcpdumping: PID %d", cmd.Process.Pid)
}
return &SlidingSyncDeployment{
Deployment: deployment,
slidingSync: ssContainer,
postgres: postgresContainer,
slidingSyncURL: ssURL,
tcpdump: cmd,
Deployment: deployment,
ReverseProxyController: controller,
slidingSync: ssContainer,
postgres: postgresContainer,
reverseProxy: rpContainer,
slidingSyncURL: ssURL,
tcpdump: cmd,
}
}

Expand Down

0 comments on commit be39ce7

Please sign in to comment.