Skip to content

Commit 8de9321

Browse files
committed
added docker support
1 parent 0c2d078 commit 8de9321

File tree

6 files changed

+155
-0
lines changed

6 files changed

+155
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Lagrange.OneBot Docker Push
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
branches:
8+
- 'master'
9+
paths:
10+
- "**.cs"
11+
- "Dockerfile"
12+
- "**.csproj"
13+
- "appsettings.onebot.json"
14+
workflow_dispatch:
15+
16+
jobs:
17+
build_push:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
- name: Set up QEMU
22+
uses: docker/setup-qemu-action@v3
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v3
25+
- name: Login to DockerHub
26+
uses: docker/login-action@v3
27+
with:
28+
username: ${{ secrets.DOCKER_USERNAME }}
29+
password: ${{ secrets.DOCKER_PASSWORD }}
30+
- name: Extract metadata (tags, labels) for Docker
31+
id: meta
32+
uses: docker/metadata-action@v5
33+
with:
34+
images: |
35+
docker.io/${{ secrets.DOCKER_USERNAME }}/lagrange.onebot
36+
tags: |
37+
type=edge
38+
type=sha,event=branch
39+
type=ref,event=tag
40+
- name: Build and push
41+
id: docker_build
42+
uses: docker/build-push-action@v5
43+
with:
44+
context: .
45+
push: true
46+
tags: ${{ steps.meta.outputs.tags }}
47+
labels: ${{ steps.meta.outputs.labels }}
48+
platforms: linux/arm64/v8, linux/amd64
49+

Docker.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Lagrange.Core
2+
3+
[![Core](https://img.shields.io/badge/Lagrange-Core-blue)](#)
4+
[![OneBot](https://img.shields.io/badge/Lagrange-OneBot-blue)](#)
5+
[![C#](https://img.shields.io/badge/Core-%20.NET_6-blue)](#)
6+
[![C#](https://img.shields.io/badge/OneBot-%20.NET_7-blue)](#)
7+
8+
[![License](https://img.shields.io/static/v1?label=LICENSE&message=GPL-3.0&color=lightrey)](#)
9+
[![Telegram](https://img.shields.io/endpoint?url=https%3A%2F%2Ftelegram-badge-4mbpu8e0fit4.runkit.sh%2F%3Furl%3Dhttps%3A%2F%2Ft.me%2F%2B6HNTeJO0JqtlNmRl)](https://t.me/+6HNTeJO0JqtlNmRl)
10+
11+
An Implementation of NTQQ Protocol, with Pure C#, Derived from Konata.Core
12+
13+
14+
# Using with Docker
15+
16+
```bash
17+
# 8081 port for ForwardWebSocket
18+
docker run -d -p 8081:8081 eric1008818/lagrange.onebot:edge
19+
```
20+
21+
## Persistence Storage
22+
23+
```bash
24+
docker volume create lagrange_data
25+
docker run -d -v lagrange_data:/app/data eric1008818/lagrange.onebot:edge
26+
```
27+
28+
## Configure appsettings.json in Docker
29+
30+
### Using Mount
31+
32+
use bind mount to mount your `appsettings.json` to `/App/appsettings.json`
33+
```bash
34+
docker run -d -v /etc/appsettings.json:/appsettings.json eric1008818/lagrange.onebot:edge
35+
```
36+
37+
### Using Environment Variables
38+
39+
use [Enviroment Variables](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-7.0#naming-of-environment-variables) to set your appsettings.json
40+
```bash
41+
# disable reverse websocket
42+
docker run -d -e Implementations__1__Enable=false eric1008818/lagrange.onebot:edge
43+
```
44+
45+
```bash
46+
# input username and password
47+
docker run -d -e Account__Uin=123456 -e Account__Password=1234 eric1008818/lagrange.onebot:edge
48+
```

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine3.18 AS build-env
2+
WORKDIR /App
3+
4+
COPY . ./
5+
RUN dotnet publish Lagrange.OneBot/Lagrange.OneBot.csproj \
6+
-c Release \
7+
-o out \
8+
--no-self-contained \
9+
-p:PublishSingleFile=true \
10+
-p:IncludeContentInSingleFile=true
11+
12+
FROM mcr.microsoft.com/dotnet/runtime:7.0-alpine3.18
13+
WORKDIR /app
14+
COPY --from=build-env /App/out .
15+
COPY appsettings.onebot.json ./appsettings.json
16+
ENTRYPOINT ["./Lagrange.OneBot"]

Lagrange.OneBot/Core/Network/LagrangeWebSvcCollection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
3636
var operationSvc = services.GetRequiredService<OperationService>();
3737
foreach (var section in implsSection.GetChildren())
3838
{
39+
if (section["Enable"] == "false") continue;
3940
var scope = services.CreateScope();
4041
var serviceProvider = scope.ServiceProvider;
4142

Lagrange.OneBot/LagrangeAppBuilder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ internal LagrangeAppBuilder(string[] args)
3131
public LagrangeAppBuilder ConfigureConfiguration(string path, bool optional = false, bool reloadOnChange = false)
3232
{
3333
Configuration.AddJsonFile(path, optional, reloadOnChange);
34+
Configuration.AddEnvironmentVariables(); // use this to configure appsettings.json with environment variables in docker container
3435
return this;
3536
}
3637

appsettings.onebot.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
7+
}
8+
},
9+
"ConfigPath": {
10+
"Keystore": "./data/keystore.json",
11+
"DeviceInfo": "./data/device.json",
12+
"Database": "./data/Lagrange.db"
13+
},
14+
"SignServerUrl": "",
15+
"Account": {
16+
"Uin": 0,
17+
"Password": "",
18+
"Protocol": "Linux",
19+
"AutoReconnect": true,
20+
"GetOptimumServer": true
21+
},
22+
"Implementations": [
23+
{
24+
"Type": "ForwardWebSocket",
25+
"Host": "0.0.0.0",
26+
"Port": 8081,
27+
"HeartBeatInterval": 5000,
28+
"AccessToken": ""
29+
},
30+
{
31+
"Type": "ReverseWebSocket",
32+
"Host": "127.0.0.1",
33+
"Port": 8080,
34+
"Suffix": "/onebot/v11/ws",
35+
"ReconnectInterval": 5000,
36+
"HeartBeatInterval": 5000,
37+
"AccessToken": ""
38+
}
39+
]
40+
}

0 commit comments

Comments
 (0)