From 9a37fa4b2fa050ea2e9bdd7ad002dd433871dedf Mon Sep 17 00:00:00 2001 From: Simon Kim Date: Thu, 22 Oct 2026 23:01:59 -0700 Subject: [PATCH] Adding docker file and Github Action Workflow --- .dockerignore | 5 +++ .github/workflows/deploy.yml | 68 ++++++++++++++++++++++++++++++++++++ Dockerfile | 15 ++++++++ README.md | 28 +++++++++++---- 4 files changed, 110 insertions(+), 6 deletions(-) create mode 100755 .dockerignore create mode 100755 .github/workflows/deploy.yml create mode 100755 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100755 index 0000000..aaa1d4b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.env +.git +.github +*.exe +/frodo-bot diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100755 index 0000000..da934e9 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,68 @@ +name: Deploy + +on: + push: + branches: [main] + pull_request: + workflow_dispatch: + +permissions: + contents: read + +env: + IMAGE: ghcr.io/simonkimdev/frodo-bot + +jobs: + image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + + - uses: docker/setup-buildx-action@v3 + + - name: Log in to GitHub Container Registry + if: github.ref == 'refs/heads/main' + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Pull requests only check that the image builds; main also pushes it. + - uses: docker/build-push-action@v6 + with: + context: . + push: ${{ github.ref == 'refs/heads/main' }} + tags: | + ${{ env.IMAGE }}:${{ github.sha }} + ${{ env.IMAGE }}:latest + labels: org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} + cache-from: type=gha + cache-to: type=gha,mode=max + + deploy: + needs: image + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + concurrency: deploy + permissions: + contents: read + id-token: write + steps: + - uses: azure/login@v2 + with: + client-id: ${{ vars.AZURE_CLIENT_ID }} + tenant-id: ${{ vars.AZURE_TENANT_ID }} + subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }} + + - name: Deploy the new image + run: | + az config set extension.use_dynamic_install=yes_without_prompt + az containerapp update \ + --name "${{ vars.AZURE_CONTAINER_APP }}" \ + --resource-group "${{ vars.AZURE_RESOURCE_GROUP }}" \ + --image "${{ env.IMAGE }}:${{ github.sha }}" \ + --output none diff --git a/Dockerfile b/Dockerfile new file mode 100755 index 0000000..f4a3cda --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +# syntax=docker/dockerfile:1 + +FROM golang:1.26-alpine AS build +WORKDIR /src + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . +RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/frodo-bot ./cmd/frodo-bot + +# distroless/static has CA certificates (needed for Discord's TLS) and nothing else; runs as a non-root user. +FROM gcr.io/distroless/static-debian12:nonroot +COPY --from=build /out/frodo-bot /frodo-bot +ENTRYPOINT ["/frodo-bot"] diff --git a/README.md b/README.md index 6b7cc9b..178f6e7 100755 --- a/README.md +++ b/README.md @@ -3,11 +3,26 @@ A Discord bot that does one thing: whenever someone says "secret", bot replies with "Alright then, keep your secrets." -## Setup +## Add Frodo to your server + +**[Invite Frodo](https://discord.com/oauth2/authorize?client_id=1561964364746195014&permissions=84992&integration_type=0&scope=bot+applications.commands)** + +This is a hosted instance that always runs the latest `main` of this repo, so there's nothing to set up. +If you'd rather run your own, see [Self-hosting](#self-hosting). + +## Commands + +| Command | Description | +| ------------- | ------------------------------------------------------------------- | +| /morgul-blade | Stab Frodo with the cursed Morgul blade to silence him indefinitely | + +## Self-hosting ### Pre-Requisite -Only the self hosting is supported atm. You'd need to register your own bot on discord dev portal. +Register your own bot on the [Discord Developer Portal](https://discord.com/developers/applications), +and enable **Message Content Intent** in its Bot tab. Invite it with the `bot` and +`applications.commands` scopes. ### 1. Configure @@ -28,11 +43,12 @@ Then fill in `.env`: go run ./cmd/frodo-bot ``` -### 3. Supported Commands +Or with Docker: -| Command | Description | -| ------------- | ------------------------------------------------------------------- | -| /morgul-blade | Stab Frodo with the cursed Morgul blade to silence him indefinitely | +```bash +docker build -t frodo-bot . +docker run --rm --env-file .env frodo-bot +``` Press `Ctrl+C` to stop.