Skip to content

Commit

Permalink
copy some tech improvements from fridgebot (simplified docker-compose…
Browse files Browse the repository at this point in the history
…, version command
  • Loading branch information
Foxite committed Mar 5, 2024
1 parent 49f1d30 commit 78007f3
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 55 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- id: compute-version-code
shell: bash
run: echo "release-version=$(echo ${GITHUB_SHA:0:8})" >> $GITHUB_OUTPUT
- name: Publish Docker
uses: elgohr/[email protected]
env:
HIGHLIGHTBOT_VERSION: ${{ steps.compute-version-code.outputs.release-version }}
- name: Publish Docker
uses: elgohr/[email protected]
with:
Expand All @@ -20,3 +27,4 @@ jobs:
password: ${{ secrets.REPO_PASSWD }}
default_branch: master
no_push: ${{ github.event_name == 'pull_request' }}
buildargs: HIGHLIGHTBOT_VERSION
6 changes: 6 additions & 0 deletions HighlightBot/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ RUN mv appsettings.json.example appsettings.json
RUN dotnet publish "HighlightBot.csproj" -c Release -o /app/publish

FROM mcr.microsoft.com/dotnet/runtime:6.0-alpine AS final

ARG FRIDGEBOT_VERSION

WORKDIR /app
COPY --from=build /app/publish .

ENV FRIDGEBOT_VERSION=$FRIDGEBOT_VERSION

ENTRYPOINT ["./HighlightBot"]
11 changes: 11 additions & 0 deletions HighlightBot/HighlightCommandModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ public override Task BeforeExecutionAsync(CommandContext ctx) {
return Task.CompletedTask;
}

[Command("version")]
public Task ShowVersion(CommandContext context) {
string? response = Environment.GetEnvironmentVariable("HIGHLIGHTBOT_VERSION");

if (string.IsNullOrWhiteSpace(response)) {
response = "Unset";
}

return context.RespondAsync(response);
}

[Command("show")]
public Task GetAllHighlights(CommandContext context) {
return Session.GetAllHighlights(Hcc);
Expand Down
11 changes: 11 additions & 0 deletions HighlightBot/SlashCommandModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ public override Task<bool> BeforeSlashExecutionAsync(InteractionContext ctx) {
return Task.FromResult(true);
}

[SlashCommand("version", "Get the bot's version.")]
public Task ShowVersion(InteractionContext context) {
string? response = Environment.GetEnvironmentVariable("HIGHLIGHTBOT_VERSION");

if (string.IsNullOrWhiteSpace(response)) {
response = "Unset";
}

return context.CreateResponseAsync(response);
}

[SlashCommand("show", "Show all your highlights.")]
public Task GetAllHighlights(InteractionContext context) {
return Session.GetAllHighlights(Hcc);
Expand Down
27 changes: 0 additions & 27 deletions docker-compose.dev.yml

This file was deleted.

25 changes: 0 additions & 25 deletions docker-compose.prod.yml

This file was deleted.

31 changes: 31 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: "3.3"

services:
database:
image: "postgres:13.3"
environment:
POSTGRES_USER: highlightbot
POSTGRES_PASSWORD: test123
POSTGRES_DB: highlightbot-data
ports:
- "5432:5432"
networks:
- highlightbot-network
volumes:
- database-data:/var/lib/postgresql/data/ # persist data even if container shuts down
bot:
build: HighlightBot
environment:
HIGHLIGHT_Discord__Token: "try not to commit this line."
HIGHLIGHT_DiscordNotifications__WebhookUrl: ""
HIGHLIGHT_ConnectionStrings__HighlightDbContext: "Host=database; Database=highlightbot-data; Port=5432; Username=highlightbot; Password=test123"
depends_on:
- database
networks:
- highlightbot-network

networks:
highlightbot-network:

volumes:
database-data: # named volumes can be managed easier using docker-compose
3 changes: 0 additions & 3 deletions postgres.env.example

This file was deleted.

0 comments on commit 78007f3

Please sign in to comment.