Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
OoLunar committed May 17, 2022
1 parent 9bf043f commit 0e5e0bf
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.github
.vscode
.gitignore
.editorconfig
bin
obj
39 changes: 39 additions & 0 deletions .github/workflows/docker_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Publish Docker image
on:
release:
types: [published]

jobs:
push_to_registry:
name: Publish Docker image
runs-on: self-hosted
steps:
- name: Check out the repo
uses: actions/checkout@v2

- name: Get Previous tag
id: previoustag
uses: WyriHaximus/github-action-get-previous-tag@master

- 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:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: |
ghcr.io/dsharpplus/dsharpplusdocs:latest
ghcr.io/dsharpplus/dsharpplusdocs:${{ steps.previoustag.outputs.tag }}
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/net6.0/DSharpPlusDocs.dll",
"args": [],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
41 changes: 41 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/DSharpPlusDocs.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/DSharpPlusDocs.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/DSharpPlusDocs.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build
WORKDIR /src

COPY ./ /src
RUN dotnet restore -r linux-musl-x64 && dotnet publish -c Release -r linux-musl-x64 --no-restore --self-contained -p:PublishSingleFile=true -p:EnableCompressionInSingleFile=true -p:DebugType=embedded

FROM alpine:latest
WORKDIR /src

COPY --from=build /src/bin/Release/net6.0/linux-musl-x64/publish /src
COPY ./res /src/res
RUN apk upgrade --update-cache --available && apk add openssl libstdc++ icu-libs && rm -rf /var/cache/apk/*

ENTRYPOINT /src/DSharpPlusDocs
16 changes: 9 additions & 7 deletions Modules/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@
using Microsoft.CodeAnalysis.Scripting;
using Microsoft.Extensions.DependencyInjection;

#pragma warning disable CA1822 // Mark members as static

namespace DSharpPlusDocs.Modules
{
public class GeneralCommands : BaseCommandModule
{
[Command("clean")]
[Description("Delete all the messages from this bot within the last X messages")]
public static async Task CleanAsync(CommandContext ctx, int messages = 30)
public async Task CleanAsync(CommandContext ctx, int messages = 30)
{
if (messages > 50)
{
Expand All @@ -68,16 +70,16 @@ public static async Task CleanAsync(CommandContext ctx, int messages = 30)

[Command("docs")]
[Description("Show the docs url")]
public static async Task DocsAsync(CommandContext ctx) => await ctx.RespondAsync($"Docs: {QueryHandler.DocsBaseUrl}");
public async Task DocsAsync(CommandContext ctx) => await ctx.RespondAsync($"Docs: {QueryHandler.DocsBaseUrl}");

[Command("invite")]
[Description("Show the invite url")]
public static async Task InviteAsync(CommandContext ctx) => await ctx.RespondAsync("Invite: https://discordapp.com/oauth2/authorize?client_id=341606460720939008&scope=bot");
public async Task InviteAsync(CommandContext ctx) => await ctx.RespondAsync("Invite: https://discordapp.com/oauth2/authorize?client_id=341606460720939008&scope=bot");

[Command("guides")]
[Aliases("guide")]
[Description("Show the url of a guide")]
public static async Task GuidesAsync(CommandContext ctx, [RemainingText] string guide = null)
public async Task GuidesAsync(CommandContext ctx, [RemainingText] string guide = null)
{
try
{
Expand Down Expand Up @@ -202,7 +204,7 @@ public static async Task GuidesAsync(CommandContext ctx, [RemainingText] string

[Command("info")]
[Description("Show some information about the application")]
public static async Task InfoAsync(CommandContext ctx)
public async Task InfoAsync(CommandContext ctx)
{
_ = ctx.Client.CurrentApplication;
MainHandler mainHandler = ctx.Services.GetService<MainHandler>();
Expand Down Expand Up @@ -244,7 +246,7 @@ public static async Task InfoAsync(CommandContext ctx)

[Command("eval")] //TODO: Safe eval ? 👀
[RequireOwner]
public static async Task EvalAsync(CommandContext ctx, [RemainingText] string code)
public async Task EvalAsync(CommandContext ctx, [RemainingText] string code)
{
/*using (Context.Channel.EnterTypingState())
{*/
Expand Down Expand Up @@ -278,7 +280,7 @@ public static async Task EvalAsync(CommandContext ctx, [RemainingText] string co

[Command("setdocsurl")]
[RequireOwner]
public static async Task SetDocsUrlAsync(CommandContext ctx, [RemainingText] string url)
public async Task SetDocsUrlAsync(CommandContext ctx, [RemainingText] string url)
{
if (!url.EndsWith("/"))
{
Expand Down
5 changes: 1 addition & 4 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ namespace DSharpPlusDocs
{
public class Program
{
public static void Main()
{
new DSharpPlusDocs().RunAsync().GetAwaiter().GetResult();
}
public static void Main() => new DSharpPlusDocs().RunAsync().GetAwaiter().GetResult();
}
}
3 changes: 2 additions & 1 deletion Query/Extensions/BaseDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ private static string GetDocsUrlPath(object o)

public static bool IsInherited(object o) => o is PropertyInfoWrapper property
? $"{property.Parent.TypeInfo.Namespace}.{property.Parent.TypeInfo.Name}" != $"{property.Property.DeclaringType.Namespace}.{property.Property.DeclaringType.Name}"
: o is MethodInfoWrapper method && $"{method.Parent.TypeInfo.Namespace}.{method.Parent.TypeInfo.Name}" != $"{method.Method.DeclaringType.Namespace}.{method.Method.DeclaringType.Name}";
: o is MethodInfoWrapper method
&& $"{method.Parent.TypeInfo.Namespace}.{method.Parent.TypeInfo.Name}" != $"{method.Method.DeclaringType.Namespace}.{method.Method.DeclaringType.Name}";

private static List<string> GetPaths(IEnumerable<object> list) => list.Select(x => GetPath(x)).ToList();

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# DSharpPlus Documentation Bot
Don't host this until the rewrite. PR's to make the code more optimized are welcome.

# Getting Started
Set the `DISCORD_TOKEN` environment variable to your bot's token, then `dotnet run`. Alternatively you can use Docker.
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: "3.9"

services:
tomoe:
build: .
environment:
- "DISCORD_TOKEN": ""
restart: unless-stopped

0 comments on commit 0e5e0bf

Please sign in to comment.