You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
WebSockets enable web applications to maintain a full-duplex connection between the backend and the frontend. This allows for many different use-cases, such as notifications, dynamic content updates (e.g., showing new comments/likes on a post), collaborative editing, etc.
4
8
5
9
At the moment, the Internet Computer does not natively support WebSocket connections and developers need to resort to work-arounds in the frontend to enable a similar functionality. This results in a poor developer experience and an overload of the backend canister.
@@ -8,12 +12,10 @@ This repository contains the implementation of a WebSocket Gateway enabling clie
8
12
9
13
# Running the WS Gateway
10
14
11
-
## Prerequisites
15
+
## Standalone
12
16
13
17
Make sure you have the **Rust toolchain** installed. You can find instructions [here](https://www.rust-lang.org/tools/install).
14
18
15
-
## Standalone
16
-
17
19
1. Run the gateway:
18
20
19
21
In **debug** mode:
@@ -39,25 +41,57 @@ Make sure you have the **Rust toolchain** installed. You can find instructions [
39
41
2024-03-14T11:19:33.650018Z INFO ic_websocket_gateway::manager: Start accepting incoming connections
40
42
```
41
43
42
-
### Options available
44
+
### Arguments available
43
45
44
46
There are some command line arguments that you can set when running the gateway:
45
47
| Argument | Description | Default |
46
48
| --- | --- | --- |
47
49
|`--gateway-address`| The **IP:port** on which the gateway will listen for incoming connections. |`0.0.0.0:8080`|
48
50
|`--ic-network-url`| The URL of the IC network to which the gateway will connect. |`http://127.0.0.1:4943`|
49
51
|`--polling-interval`| The interval (in **milliseconds**) at which the gateway will poll the canisters for new messages. |`100`|
52
+
|`--prometheus-endpoint`| The **IP:port** on which the gateway will expose Prometheus metrics. |`0.0.0.0:9090`|
50
53
|`--tls-certificate-pem-path`| The path to the TLS certificate file. See [Obtain a TLS certificate](#obtain-a-tls-certificate) for more details. | _empty_ |
51
54
|`--tls-certificate-key-pem-path`| The path to the TLS private key file. See [Obtain a TLS certificate](#obtain-a-tls-certificate) for more details. | _empty_ |
52
55
|`--opentelemetry-collector-endpoint`| OpenTelemetry collector endpoint. See [Tracing telemetry](#tracing-telemetry) for more details. | _empty_ |
53
56
54
57
## Docker
55
58
56
-
A [Dockerfile](./Dockerfile) is provided, together with the files [docker-compose.yml](./docker-compose.yml), [docker-compose-local.yml](./docker-compose-local.yml) and [docker-compose-prod.yml](./docker-compose-prod.yml) to run the gateway according to the needs. Make sure you have [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/) installed.
59
+
Make sure you have [Docker](https://docs.docker.com/get-docker/) installed.
60
+
61
+
A [Dockerfile](./Dockerfile) is provided. To build the image, run:
62
+
63
+
```bash
64
+
docker build -t ic-websocket-gateway .
65
+
```
66
+
67
+
Then, run the gateway with the following command:
68
+
69
+
```bash
70
+
docker run -p 8080:8080 ic-websocket-gateway
71
+
```
72
+
73
+
A Docker image is also available at [omniadevs/ic-websocket-gateway](https://hub.docker.com/r/omniadevs/ic-websocket-gateway), that you can run with the following command:
57
74
58
-
A Docker image is also available at [omniadevs/ic-websocket-gateway](https://hub.docker.com/r/omniadevs/ic-websocket-gateway). This is the image used in the [docker-compose.yml](./docker-compose.yml) file.
75
+
```bash
76
+
docker run -p 8080:8080 omniadevs/ic-websocket-gateway
77
+
```
78
+
79
+
Have a look at the [Arguments available](#arguments-available) to configure the gateway for your needs.
80
+
81
+
## Docker Compose
82
+
83
+
Make sure you have [Docker Compose](https://docs.docker.com/compose/install/) installed.
The following sections describe how to use the different compose files to run the gateway with Docker Compose.
59
92
60
93
### Local
94
+
61
95
To run the gateway in a local environment with Docker Compose, follow these steps:
62
96
1. To run all the required local structure you can execute the [start_local_docker_environment.sh](./scripts/start_local_docker_environment.sh) with the command:
63
97
@@ -71,18 +105,24 @@ To run the gateway in a local environment with Docker Compose, follow these step
2. To stop and clean all the local environment a bash script [stop_local_docker_environment.sh](./scripts/stop_local_docker_environment.sh) is provided. You can execute it with the command:
108
+
2. To stop and clean all the local environment, the bash script [stop_local_docker_environment.sh](./scripts/stop_local_docker_environment.sh) is provided. You can execute it with the command:
75
109
76
110
```
77
111
./scripts/stop_local_docker_environment.sh
78
112
```
79
113
80
-
3. The Gateway will print its principal in the container logs, just as explained above.
81
-
4. If you want to verify that all is started correctly a bash script [run_test_canister.sh](./scripts/run_test_canister.sh) is provided. This assumes that the gateway is already running.
114
+
3. The Gateway will print its principal in the container logs, just as explained in the [Standalone](#standalone) section.
115
+
4. If you want to verify that everything started correctly, the bash script [run_test_canister.sh](./scripts/run_test_canister.sh) is provided. This script assumes that the gateway is already running and reachable locally. You can execute it with the command:
116
+
117
+
```
118
+
./scripts/run_test_canister.sh
119
+
```
82
120
83
121
### Production
84
122
85
-
To run the gateway in a prod environment with Docker Compose, follow these steps:
123
+
This configuration uses the [omniadevs/ic-websocket-gateway](https://hub.docker.com/r/omniadevs/ic-websocket-gateway) image.
124
+
125
+
To run the gateway in a production environment with Docker Compose, follow these steps:
86
126
1. Set the environment variables:
87
127
88
128
```
@@ -91,26 +131,26 @@ To run the gateway in a prod environment with Docker Compose, follow these steps
91
131
92
132
2. To run the [docker-compose-prod.yml](./docker-compose-prod.yml) file you need a public domain (that you will put in the `DOMAIN_NAME` environment variable) and a TLS certificate for that domain (because it is configured to make the gateway run with TLS enabled). See [Obtain a TLS certificate](#obtain-a-tls-certificate) for more details.
93
133
3. Open the `443` port (or the port that you setin the `LISTEN_PORT` environment variable) on your server and make it reachable from the Internet.
94
-
4. To run all the required production structure you can execute the [start_prod_docker_environment.sh](./scripts/start_prod_docker_environment.sh) with the command:
134
+
4. To run all the required production containers you can execute the [start_prod_docker_environment.sh](./scripts/start_prod_docker_environment.sh) with the command:
95
135
96
136
```
97
137
./scripts/start_prod_docker_environment.sh
98
138
```
99
139
100
-
This script firstly generated the `telemetry/prometheus/prometheus-prod.yml` config file starting from the `telemetry/prometheus/prometheus-template.yml` (step required to perform the variable substitution) and thensimply run the gateway with the following command:
140
+
This script first generates the `telemetry/prometheus/prometheus-prod.yml` config file from the `telemetry/prometheus/prometheus-template.yml`template (step required to perform the environment variables substitution) and thenruns the gateway with the following command:
docker compose -f docker-compose.yml -f docker-compose-prod.yml --env-file .env up -d
104
144
```
105
145
106
-
5. To stop and clean all the local environment a bash script [stop_prod_docker_environment.sh](./scripts/stop_prod_docker_environment.sh) is provided. You can execute it with the command:
146
+
5. To stop and clean the containers, the bash script [stop_prod_docker_environment.sh](./scripts/stop_prod_docker_environment.sh) is provided. You can execute it with the command:
107
147
108
148
```
109
149
./scripts/stop_prod_docker_environment.sh
110
150
```
111
-
6. The Gateway will print its principal in the container logs, just as explained above.
151
+
6. The Gateway will print its principal in the container logs, just as explained in the [Standalone](#standalone) section.
112
152
113
-
### Obtain a TLS certificate
153
+
#### Obtain a TLS certificate
114
154
115
155
1. Buy a domain name and point it to the server where you are running the gateway.
116
156
2. Make sure the `.env` file is configured with the correct domain name, see above.
0 commit comments