Skip to content

Commit

Permalink
added docker support
Browse files Browse the repository at this point in the history
  • Loading branch information
eric2788 committed Jan 16, 2024
1 parent 592761d commit cce1bb6
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/Lagrange.OneBot-docker-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Lagrange.OneBot Docker Push

on:
push:
tags:
- '*'
branches:
- 'master'
paths:
- "**.cs"
- "Dockerfile"
- "**.csproj"
- "appsettings.onebot.json"
workflow_dispatch:

jobs:
build_push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
with:
images: |
docker.io/${{ secrets.DOCKER_USERNAME }}/lagrange.onebot
tags: |
type=edge
type=sha,event=branch
type=ref,event=tag
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/arm64/v8, linux/amd64

48 changes: 48 additions & 0 deletions Docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Lagrange.Core

[![Core](https://img.shields.io/badge/Lagrange-Core-blue)](#)
[![OneBot](https://img.shields.io/badge/Lagrange-OneBot-blue)](#)
[![C#](https://img.shields.io/badge/Core-%20.NET_6-blue)](#)
[![C#](https://img.shields.io/badge/OneBot-%20.NET_7-blue)](#)

[![License](https://img.shields.io/static/v1?label=LICENSE&message=GPL-3.0&color=lightrey)](#)
[![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)

An Implementation of NTQQ Protocol, with Pure C#, Derived from Konata.Core


# Using with Docker

```bash
# 8081 port for ForwardWebSocket
docker run -d -p 8081:8081 eric1008818/lagrange.onebot:edge
```

## Persistence Storage

```bash
docker volume create lagrange_data
docker run -d -v lagrange_data:/app/data eric1008818/lagrange.onebot:edge
```

## Configure appsettings.json in Docker

### Using Mount

use bind mount to mount your `appsettings.json` to `/App/appsettings.json`
```bash
docker run -d -v /etc/appsettings.json:/appsettings.json eric1008818/lagrange.onebot:edge
```

### Using Environment Variables

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
```bash
# disable reverse websocket
docker run -d -e Implementations__1__Enable=false eric1008818/lagrange.onebot:edge
```

```bash
# input username and password
docker run -d -e Account__Uin=123456 -e Account__Password=1234 eric1008818/lagrange.onebot:edge
```
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM mcr.microsoft.com/dotnet/sdk:7.0.403-alpine3.18 AS build-env
WORKDIR /App

ARG TARGETARCH
ARG TARGETOS

COPY . ./
RUN dotnet restore -a $TARGETARCH
RUN dotnet publish Lagrange.OneBot/Lagrange.OneBot.csproj \
-a $TARGETARCH \
-c Release \
-o out \
--no-restore \
--no-self-contained \
-p:PublishSingleFile=true \
-p:IncludeContentInSingleFile=true


FROM mcr.microsoft.com/dotnet/runtime:7.0.13-alpine3.18
WORKDIR /app

COPY --from=build-env /App/out .
COPY appsettings.onebot.json ./appsettings.json
ENTRYPOINT ["./Lagrange.OneBot"]
1 change: 1 addition & 0 deletions Lagrange.OneBot/Core/Network/LagrangeWebSvcCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
var operationSvc = services.GetRequiredService<OperationService>();
foreach (var section in implsSection.GetChildren())
{
if (section["Enable"] == "false") continue;
var scope = services.CreateScope();
var serviceProvider = scope.ServiceProvider;

Expand Down
1 change: 1 addition & 0 deletions Lagrange.OneBot/LagrangeAppBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ internal LagrangeAppBuilder(string[] args)
public LagrangeAppBuilder ConfigureConfiguration(string path, bool optional = false, bool reloadOnChange = false)
{
Configuration.AddJsonFile(path, optional, reloadOnChange);
Configuration.AddEnvironmentVariables(); // use this to configure appsettings.json with environment variables in docker container
return this;
}

Expand Down
40 changes: 40 additions & 0 deletions appsettings.onebot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"ConfigPath": {
"Keystore": "./data/keystore.json",
"DeviceInfo": "./data/device.json",
"Database": "./data/Lagrange.db"
},
"SignServerUrl": "",
"Account": {
"Uin": 0,
"Password": "",
"Protocol": "Linux",
"AutoReconnect": true,
"GetOptimumServer": true
},
"Implementations": [
{
"Type": "ForwardWebSocket",
"Host": "0.0.0.0",
"Port": 8081,
"HeartBeatInterval": 5000,
"AccessToken": ""
},
{
"Type": "ReverseWebSocket",
"Host": "127.0.0.1",
"Port": 8080,
"Suffix": "/onebot/v11/ws",
"ReconnectInterval": 5000,
"HeartBeatInterval": 5000,
"AccessToken": ""
}
]
}

0 comments on commit cce1bb6

Please sign in to comment.