Coronavirus (COVID-19) statistics with Slack notification
COVID-19 datasource: https://corona.lmao.ninja
- Send statistics on daily basis (at 4:00AM UTC+0)
- Send statistics in chat by slack command using endpoint
/corona/stats
Project provides complete docker image for usage. To run docker container you should do the following steps:
mkdir -p /opt/corona-stats && touch /opt/corona-slack/env.list- Put environment variables
SLACK_CHANNELandSLACK_TOKENto/opt/corona-slack/env.listSLACK_CHANNEL- Slack channel id
SLACK_TOKEN- Slack bot token - Run
docker run --rm --name docker.corona-slack.service --env-file /opt/corona-slack/env.list -p 8082:8080 mdsina/corona-slack:latest - Slack requires
httpsprotocol connection, so you need a front proxy before application that can be accessible thoughhttps. You can do that thoughnginxas for example:
location ~ ^/corona-bot(/?)(.*) {
proxy_pass http://0.0.0.0:8082/$2;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Client-Verify SUCCESS;
proxy_set_header X-Client-DN $ssl_client_s_dn;
proxy_set_header X-SSL-Subject $ssl_client_s_dn;
proxy_set_header X-SSL-Issuer $ssl_client_i_dn;
proxy_read_timeout 1800;
proxy_connect_timeout 1800;
}
- After that specify URL to
https://<server>/corona-bot/corona/statsin your Slack App configuration for slash command
You can also use docker.corona-slack.service file that can pull docker image and run container without any additional configuration, except /opt/corona-slack/env.list file.
- JDK 11 and set
JAVA_HOMEenvironment variable- you can use GraalVM 20.0.0 if you need to build Docker image and use Native Image
- maven
- can be used though mvnw wrapper, that downloads maven automatically and run them
- Docker, to build docker container with Native Image through GraalVM
Run in root directory ./mvnw clean install.
Jar file car be found at <project root>/target/corona-slack-0.1.jar
To run jar file you can use the following commands:
$ export SLACK_CHANNEL=<channel id>
$ export SLACK_TOKEN=<slack token>
$ java -jar ./target/corona-slack-0.1.jar
That will run http server on port 8080:
/corona-slack# java -jar target/corona-slack-0.1.jar
18:50:31.650 [main] INFO io.micronaut.runtime.Micronaut - Startup completed in 2066ms. Server Running: http://localhost:8080
First of all you need to compile jar file as described in in that README.
After that, if you planned to add some libraries that do not support GraalVM SVM you need to rebuild native image configuration files:
java -agentlib:native-image-agent=config-output-dir=./src/main/resources/META-INF/native-image/,caller-filter-file=./native-image-filter.json -jar target/corona-slack-0.1.jar
After start the application, you can do some requests to endpoint /corona/stats with your bot or by hands. That will help native image aget to collect information about used classes via reflection, as described in documentation.
That will updates files in <project root>/src/main/resources/META-INF/native-image/ directory.
After that you need to remove some records in json files reflect-config.json and in resource-config.json. SVM has some issues on filtering classes that should not be loaded on building native image.
The records, that relates to the following packages should be removed to prevent runtime errors. This classes already SVM-optimized and will be collected by native image build proccess:
io.nettyio.micronautcom.github.mdsina.corona
To build Docker Image just simply run ./docker-build.sh
- Federated accessing to bot backend
- Global Slack App with registration in bot backend
- Non-docker based systemd configuration file for pure java
- Configurable list of countries to show in statistics
- ...
