Skip to content

Commit 6679a14

Browse files
author
Bernhard B
committed
Merge branch 'jsonrpc'
2 parents 85dfe19 + 708e865 commit 6679a14

File tree

24 files changed

+1846
-814
lines changed

24 files changed

+1846
-814
lines changed

.github/ISSUE_TEMPLATE/bug-report.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ body:
3939
required: true
4040
attributes:
4141
label: In which mode are you using the docker container?
42-
description: If you have `USE_NATIVE=1` set in your `docker-compose.yml` file then you are using the native mode.
42+
description: Please have a look at the `MODE` parameter in you `docker-compose.yml` file. If you do not have the `MODE` parameter explicitly set, then you are running in normal mode.
4343
options:
4444
- Normal Mode
4545
- Native Mode
46+
- JSON-RPC Mode
4647
- type: dropdown
4748
validations:
4849
required: true

Dockerfile

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
ARG SIGNAL_CLI_VERSION=0.8.5
1+
ARG SIGNAL_CLI_VERSION=0.9.0
22
ARG ZKGROUP_VERSION=0.7.0
3-
ARG LIBSIGNAL_CLIENT_VERSION=0.8.1
3+
ARG LIBSIGNAL_CLIENT_VERSION=0.9.0
44

55
ARG SWAG_VERSION=1.6.7
66
ARG GRAALVM_JAVA_VERSION=11
7-
ARG GRAALVM_VERSION=21.0.0
7+
ARG GRAALVM_VERSION=21.2.0
88

9-
FROM golang:1.14-buster AS buildcontainer
9+
FROM golang:1.17-bullseye AS buildcontainer
1010

1111
ARG SIGNAL_CLI_VERSION
1212
ARG ZKGROUP_VERSION
@@ -125,16 +125,22 @@ RUN cd /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/distributions/ \
125125

126126

127127
COPY src/api /tmp/signal-cli-rest-api-src/api
128+
COPY src/client /tmp/signal-cli-rest-api-src/client
128129
COPY src/utils /tmp/signal-cli-rest-api-src/utils
130+
COPY src/scripts /tmp/signal-cli-rest-api-src/scripts
129131
COPY src/main.go /tmp/signal-cli-rest-api-src/
130132
COPY src/go.mod /tmp/signal-cli-rest-api-src/
131133
COPY src/go.sum /tmp/signal-cli-rest-api-src/
132134

135+
# build signal-cli-rest-api
133136
RUN cd /tmp/signal-cli-rest-api-src && swag init && go build
134137

138+
# build supervisorctl_config_creator
139+
RUN cd /tmp/signal-cli-rest-api-src/scripts && go build -o jsonrpc2-helper
140+
135141

136142
# Start a fresh container for release container
137-
FROM adoptopenjdk:11-jre-hotspot-bionic
143+
FROM eclipse-temurin:11-jre-focal
138144

139145
ENV GIN_MODE=release
140146

@@ -143,12 +149,13 @@ ENV PORT=8080
143149
ARG SIGNAL_CLI_VERSION
144150

145151
RUN apt-get update \
146-
&& apt-get install -y --no-install-recommends setpriv \
152+
&& apt-get install -y --no-install-recommends util-linux supervisor netcat \
147153
&& rm -rf /var/lib/apt/lists/*
148154

149155
COPY --from=buildcontainer /tmp/signal-cli-rest-api-src/signal-cli-rest-api /usr/bin/signal-cli-rest-api
150156
COPY --from=buildcontainer /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/distributions/signal-cli-${SIGNAL_CLI_VERSION}.tar /tmp/signal-cli-${SIGNAL_CLI_VERSION}.tar
151157
COPY --from=buildcontainer /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/native-image/signal-cli /tmp/signal-cli-native
158+
COPY --from=buildcontainer /tmp/signal-cli-rest-api-src/scripts/jsonrpc2-helper /usr/bin/jsonrpc2-helper
152159
COPY entrypoint.sh /entrypoint.sh
153160

154161
RUN tar xf /tmp/signal-cli-${SIGNAL_CLI_VERSION}.tar -C /opt

README.md

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,41 @@ At the moment, the following functionality is exposed via REST:
1515

1616
and [many more](https://bbernhard.github.io/signal-cli-rest-api/)
1717

18-
## Examples
18+
## Modes
19+
20+
The `signal-cli-rest-api` supports three different modes:
21+
22+
* Normal Mode: In normal mode, the `signal-cli` executable is invoked for every REST API request. As `signal-cli` is a Java application, a significant amount of time is spent in the JVM (Java Virtual Machine) startup - which makes this mode pretty slow.
23+
* Native Mode: Instead of calling a Java executable for every REST API request, a native image (compiled with GraalVM) is called. This mode therefore usually performs better than the normal mode.
24+
* JSON-RPC Mode: In JSON-RPC mode, a single `signal-cli` instance is spawned in daemon mode. The communication happens via JSON-RPC. This mode is usually the fastest.
25+
26+
27+
| architecture | normal mode | native mode | json-rpc mode |
28+
|--------------|:-----------:|:-----------:|---------------|
29+
| x86-64 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
30+
| armv7 | :heavy_check_mark: | ❌ <sup>1</sup> | :heavy_check_mark: |
31+
| arm64 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
32+
33+
34+
| mode | speed |
35+
|-------------:|:------------|
36+
| json-rpc | :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: |
37+
| native | :heavy_check_mark: :heavy_check_mark: |
38+
| normal | :heavy_check_mark: |
39+
40+
41+
Notes:
42+
1. If the signal-cli-rest-api docker container is started on an armv7 system in native mode, it automatically falls back to the normal mode.
43+
44+
## Auto Receive Schedule
45+
46+
> :warning: This setting is only needed in normal/native mode!
47+
48+
[signal-cli](https://github.com/AsamK/signal-cli), which this REST API wrapper is based on, recommends to call `receive` on a regular basis. So, if you are not already calling the `receive` endpoint regularily, it is recommended to set the `AUTO_RECEIVE_SCHEDULE` parameter in the docker-compose.yml file. The `AUTO_RECEIVE_SCHEDULE` accepts cron schedule expressions and automatically calls the `receive` endpoint at the given time. e.g: `0 22 * * *` calls `receive` daily at 10pm. If you are not familiar with cron schedule expressions, you can use this [website](https://crontab.guru).
49+
50+
**WARNING** Calling `receive` will fetch all the messages for the registered Signal number from the Signal Server! So, if you are using the REST API for receiving messages, it's _not_ a good idea to use the `AUTO_RECEIVE_SCHEDULE` parameter, as you might lose some messages that way.
51+
52+
## Example
1953

2054
Sample `docker-compose.yml`file:
2155

@@ -25,7 +59,7 @@ services:
2559
signal-cli-rest-api:
2660
image: bbernhard/signal-cli-rest-api:latest
2761
environment:
28-
- USE_NATIVE=0
62+
- MODE=normal #supported modes: json-rpc, native, normal
2963
#- AUTO_RECEIVE_SCHEDULE=0 22 * * * #enable this parameter on demand (see description below)
3064
ports:
3165
- "8080:8080" #map docker port 8080 to host port 8080.
@@ -34,21 +68,6 @@ services:
3468

3569
```
3670

37-
## Auto Receive Schedule
38-
39-
[signal-cli](https://github.com/AsamK/signal-cli), which this REST API wrapper is based on, recommends to call `receive` on a regular basis. So, if you are not already calling the `receive` endpoint regularily, it is recommended to set the `AUTO_RECEIVE_SCHEDULE` parameter in the docker-compose.yml file. The `AUTO_RECEIVE_SCHEDULE` accepts cron schedule expressions and automatically calls the `receive` endpoint at the given time. e.g: `0 22 * * *` calls `receive` daily at 10pm. If you are not familiar with cron schedule expressions, you can use this [website](https://crontab.guru).
40-
41-
**WARNING** Calling `receive` will fetch all the messages for the registered Signal number from the Signal Server! So, if you are using the REST API for receiving messages, it's _not_ a good idea to use the `AUTO_RECEIVE_SCHEDULE` parameter, as you might lose some messages that way.
42-
43-
44-
## Native Image (EXPERIMENTAL)
45-
46-
On Systems like the Raspberry Pi, some operations like sending messages can take quite a while. That's because signal-cli is a Java application and a significant amount of time is spent in the JVM (Java Virtual Machine) startup. signal-cli recently added the possibility to compile the Java application to a native binary (done via GraalVM).
47-
48-
By adding `USE_NATIVE=1` as environmental variable to the `docker-compose.yml` file the native mode will be enabled.
49-
50-
In case there's no native binary available (e.g on a 32 bit Raspian OS), it will fall back to the signal-cli Java application. The native mode only works on a 64bit system, when the native mode is enabled on a 32bit system, it falls back to the Java application.
51-
5271
## Documentation
5372

5473
### API Reference

docker-compose.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ services:
33
signal-cli-rest-api:
44
image: bbernhard/signal-cli-rest-api:latest
55
environment:
6-
- USE_NATIVE=0
7-
#- AUTO_RECEIVE_SCHEDULE=0 22 * * *
8-
- PORT=8080
6+
- MODE=normal #supported modes: json-rpc, native, normal
7+
#- AUTO_RECEIVE_SCHEDULE=0 22 * * * #enable this parameter on demand (see description below)
98
ports:
109
- "8080:8080" #map docker port 8080 to host port 8080.
1110
volumes:

entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,13 @@ EOF
1818
cap_prefix="-cap_"
1919
caps="$cap_prefix$(seq -s ",$cap_prefix" 0 $(cat /proc/sys/kernel/cap_last_cap))"
2020

21+
# TODO: check mode
22+
if [ "$MODE" = "json-rpc" ]
23+
then
24+
/usr/bin/jsonrpc2-helper
25+
service supervisor start
26+
supervisorctl start all
27+
fi
28+
2129
# Start API as signal-api user
2230
exec setpriv --reuid=1000 --regid=1000 --init-groups --inh-caps=$caps signal-cli-rest-api -signal-cli-config=${SIGNAL_CLI_CONFIG_DIR}
5.4 MB
Binary file not shown.
5.14 MB
Binary file not shown.
5.47 MB
Binary file not shown.
5.4 MB
Binary file not shown.
5.14 MB
Binary file not shown.

0 commit comments

Comments
 (0)