Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite in Rust & use Nix to build Docker images #303

Merged
merged 90 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
45403e9
initial rewrite in rust & moderation commands
getchoo Dec 3, 2023
e928eb6
feat: add nix package, module, and container
getchoo Dec 3, 2023
65fc5d5
ci: add clippy/rustfmt checks
getchoo Dec 3, 2023
a26a2fd
ci: add nix workflows
getchoo Dec 3, 2023
4b80ec7
ci: build docker images with nix
getchoo Dec 3, 2023
358df91
feat: reintroduce eta
TheKodeToad Dec 3, 2023
a8eb4a2
chore: deprecate modrinth command
getchoo Dec 3, 2023
30cc4a6
feat: reintroduce tag command
getchoo Dec 4, 2023
368b5e0
feat: delete messages on ❌ again
getchoo Dec 4, 2023
604a81f
feat: reintroduce support onboarding
getchoo Dec 4, 2023
640409f
feat: reintroduce message link embeds
getchoo Dec 4, 2023
4bf3136
fix: don't filter out tags in nix build
getchoo Dec 4, 2023
1c168bd
fix: use regex for eta again
getchoo Dec 4, 2023
5b16c14
feat: set presence info on ready again
getchoo Dec 4, 2023
542ecf6
chore: add RUST_LOG to .env.example
getchoo Dec 4, 2023
6e33299
feat: reintroduce ping command
getchoo Dec 4, 2023
8bad9d9
feat: add descriptions to commands & arguments
getchoo Dec 4, 2023
640690d
refactor: use unwrap_or_default() for kick/ban reason
TheKodeToad Dec 4, 2023
95fe620
chore: remove tag aliases
TheKodeToad Dec 4, 2023
f955cbb
feat: reintroduce PK support
getchoo Dec 5, 2023
55ccfe4
fix: use camelCase for MinecraftPackageJson
TheKodeToad Dec 5, 2023
174d935
fix: do not
TheKodeToad Dec 5, 2023
20e2dbb
refactor moderation; change prefix to `r`
TheKodeToad Dec 6, 2023
ed496f5
chore: ignore .idea
TheKodeToad Dec 7, 2023
78c8aa7
refactor: create ModAction struct
getchoo Dec 7, 2023
8376c45
feat: flesh out storage object
getchoo Dec 8, 2023
7e96bce
feat: add message logger
getchoo Dec 8, 2023
026d4cb
rory: handle errors from api
getchoo Dec 8, 2023
c6f4295
feat: log analysis
TheKodeToad Dec 9, 2023
2067697
feat: LWJGL 2 & Java 9, Pre 1.12 native transport & Java 9 issues
TheKodeToad Dec 10, 2023
a86bbfe
analyze_logs: detect outdated launchers
getchoo Dec 12, 2023
bb52188
deps: update cargo and flake lockfiles
getchoo Dec 12, 2023
3e992bf
actions: update DeterminateSystems/nix-installer-action
getchoo Dec 12, 2023
885e28f
refactor framework setup
getchoo Dec 13, 2023
9ae8b98
feat: cleanly shutdown on ctrl+c & sigterm
getchoo Dec 13, 2023
3e3be2a
feat: better handle errors during setup
getchoo Dec 13, 2023
9dce57f
moderation: dm user before taking action
getchoo Dec 13, 2023
e0fea8d
refactor: use User over Member in moderation commands
getchoo Dec 13, 2023
f2979d4
Goodbye moderation
TheKodeToad Jan 8, 2024
f0550dd
style: use tabs over spaces
getchoo Jan 8, 2024
f2a3582
nix/deployment: pre-select system in crossPkgsFor
getchoo Jan 8, 2024
48c2dba
chore: cleanup and bump workflow actions
getchoo Jan 8, 2024
203ba11
fix: compilation on windows
getchoo Jan 27, 2024
7252ced
refactor!: use poise 0.6.1
getchoo Jan 28, 2024
2acb319
fix(storage): set expiry for launcher version key
getchoo Jan 28, 2024
72e171b
chore: cleanup unused config properties
getchoo Jan 28, 2024
2b3d81c
refactor: better scope eta messages const
getchoo Jan 28, 2024
a4abdd7
refactor: harden clippy lints
getchoo Jan 28, 2024
fafa0bf
refactor: don't use re-exports of eyre & owo-colors
getchoo Jan 28, 2024
f4fa737
refactor: `ok_or_else()` -> `ok_or_eyre()`
getchoo Jan 28, 2024
24c8406
chore: cleanup + update nix flake
getchoo Jan 28, 2024
46fd026
chore: cleanup docker & nix workflows
getchoo Jan 28, 2024
651f14d
storage: make constructors more idiomatic
getchoo Mar 3, 2024
915ef54
log more actions + tidy up things
getchoo Mar 3, 2024
cd1e322
support_onboard: check if bot has already joined thread
getchoo Mar 3, 2024
1ea0867
ci: automerge dependabot PRs
getchoo Mar 4, 2024
9d0c022
Many fixes and tweaks
TheKodeToad Mar 18, 2024
af9938a
handlers::event: improve tracing
getchoo Mar 18, 2024
6bd5db7
utils::resolve_message: use perms from behind pk proxy
getchoo Mar 18, 2024
3c4cf67
nix: `naersk`/`fenix` -> `rustPlatform`/`rust-overlay`
getchoo Mar 24, 2024
e847ea0
api: use `error_for_status_ref()`
getchoo Mar 23, 2024
b63ecde
commands: tidy up help & joke
getchoo Mar 23, 2024
827b5a4
analyze_logs: introduce LogProvider trait
getchoo Mar 23, 2024
a9a63f3
treewide: allow for running w/o storage
getchoo Mar 27, 2024
4e11bd2
analyze_logs: fix 0x0 regex
getchoo Mar 27, 2024
9f82337
nix: use correct env var for redis url
getchoo Mar 27, 2024
239928a
crates: bump octocrab, redis, & reqwest
getchoo Mar 27, 2024
59bf429
feat: add /set_welcome command
getchoo Mar 29, 2024
a41a84f
say: use channel_id, only use prefix command
getchoo Mar 29, 2024
90387c5
once_cell -> std
getchoo Mar 30, 2024
b161a1a
drop redis-macros
getchoo Mar 30, 2024
29ed728
drop rand
getchoo Mar 30, 2024
1ff95de
make sure to borrow in getters
getchoo Mar 30, 2024
a3014f2
consts: store colors as hex codes in struct
getchoo Mar 30, 2024
a2106ca
set_welcome: bulk delete messages
getchoo Mar 31, 2024
9dfc3b2
set_welcome: wire up role interaction
getchoo Mar 31, 2024
0b0779f
clean up
getchoo Mar 31, 2024
5cfb079
nix: improve RUSTFLAGS + add overlay
getchoo Mar 31, 2024
bdce1f4
nix: use toolchain from refraction package
getchoo Mar 31, 2024
da95309
nix: update flake.lock
getchoo Mar 31, 2024
dfa4d66
ci: update actions
getchoo Mar 31, 2024
a8d6a2b
nix: use self'.packages as a default in module
getchoo Apr 1, 2024
94b12a1
remove reactions from messages older than n days
getchoo Apr 2, 2024
4795e15
block_reaction: log old reactions
getchoo Apr 2, 2024
3503dda
block_reaction: avoid rate limits
getchoo Apr 10, 2024
921540e
nix: move dev outputs to subflake
getchoo Apr 10, 2024
84a7cfe
use http client from context
getchoo Apr 27, 2024
d25776d
Revert "block_reaction: avoid rate limits"
Scrumplex Apr 30, 2024
a512102
Revert "block_reaction: log old reactions"
Scrumplex Apr 30, 2024
ca7bacb
Revert "remove reactions from messages older than n days"
Scrumplex Apr 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .dockerignore

This file was deleted.

2 changes: 0 additions & 2 deletions .env.example

This file was deleted.

5 changes: 4 additions & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
use flake
if has nix_direnv_version; then
use flake ./nix/dev
fi

dotenv_if_exists
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

11 changes: 0 additions & 11 deletions .eslintrc.cjs

This file was deleted.

28 changes: 28 additions & 0 deletions .github/workflows/autobot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Auto-merge Dependabot

on: pull_request

jobs:
automerge:
name: Check and merge PR
runs-on: ubuntu-latest

permissions:
contents: write
pull-requests: write

if: github.actor == 'dependabot[bot]'

steps:
- uses: dependabot/fetch-metadata@v2
id: metadata
with:
github-token: ${{ github.token }}

# auto merge minor releases
- name: Enable auto-merge
if: steps.metadata.outputs.update-type == 'version-update:semver-patch' || steps.metadata.outputs.update-type == 'version-update:semver-minor'
run: gh pr merge --auto --rebase "$PR"
env:
GH_TOKEN: ${{ github.token }}
PR: ${{ github.event.pull_request.html_url }}
68 changes: 68 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Check

on:
push:
branches: ['main']
pull_request:

jobs:
rustfmt:
name: Run rustfmt
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: rustfmt

- name: Setup Rust cache
uses: Swatinem/rust-cache@v2

- name: Run rustfmt
run: cargo fmt --all -- --check

clippy:
name: Run Clippy scan
runs-on: ubuntu-latest

permissions:
security-events: write

steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: clippy

- name: Setup Rust cache
uses: Swatinem/rust-cache@v2

- name: Install SARIF tools
run: cargo install clippy-sarif sarif-fmt

- name: Fetch Cargo deps
run: cargo fetch --locked

- name: Run Clippy
continue-on-error: true
run: |
set -euo pipefail

cargo clippy \
--all-features \
--all-targets \
--message-format=json \
| clippy-sarif | tee /tmp/clippy.sarif | sarif-fmt

- name: Upload results
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: /tmp/clippy.sarif
wait-for-processing: true
136 changes: 56 additions & 80 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,112 +3,88 @@ name: Docker
on:
push:
branches: ['main']

env:
REGISTRY: ghcr.io
IMAGE_NAME: prismlauncher/refraction

permissions:
contents: read
packages: write
pull_request:
workflow_dispatch:

jobs:
build:
name: Build image
runs-on: ubuntu-latest

strategy:
matrix:
platform:
- linux/arm64
- linux/amd64
arch: [x86_64, aarch64]

steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
if: ${{ matrix.platform != 'linux/amd64' }}
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v10

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=raw,value=latest

- name: Build and push by digest
uses: docker/build-push-action@v5
- name: Build Docker image
id: build
with:
context: .
provenance: false
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ matrix.platform }}
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true

- name: Export digests
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
nix build --print-build-logs ./nix/dev#container-${{ matrix.arch }}
[ ! -L result ] && exit 1
echo "path=$(readlink -f result)" >> "$GITHUB_OUTPUT"

- name: Upload digests
uses: actions/upload-artifact@v3
- name: Upload image
uses: actions/upload-artifact@v4
with:
name: digests
path: /tmp/digests/*
name: container-${{ matrix.arch }}
path: ${{ steps.build.outputs.path }}
if-no-files-found: error
retention-days: 1
retention-days: 3

push:
name: Push image

needs: build
runs-on: ubuntu-latest
needs:
- build

permissions:
packages: write

env:
REGISTRY: ghcr.io
USERNAME: ${{ github.actor }}
IMAGE_NAME: ${{ github.repository }}

if: github.event_name == 'push'

steps:
- name: Download digests
uses: actions/download-artifact@v3
with:
name: digests
path: /tmp/digests
- uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Download images
uses: actions/download-artifact@v4
with:
path: images

- name: Log in to the Container registry
- name: Login to registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
username: ${{ env.USERNAME }}
password: ${{ github.token }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=raw,value=latest

- name: Create manifest list and push
working-directory: /tmp/digests
- name: Push to registry
env:
TAG: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
set -eu

- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
architectures=("x86_64" "aarch64")
for arch in "${architectures[@]}"; do
docker load < images/container-"$arch"/*.tar.gz
docker tag refraction:latest-"$arch" "$TAG"-"$arch"
docker push ${{ env.TAG }}-"$arch"
done

docker manifest create "$TAG" \
--amend "$TAG"-x86_64 \
--amend "$TAG"-aarch64

docker manifest push "$TAG"
Comment on lines +79 to +90
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: podman might be a better choice

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥸

25 changes: 0 additions & 25 deletions .github/workflows/lint.yml

This file was deleted.

53 changes: 53 additions & 0 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Nix

on:
push:
branches: ['main']
pull_request:
workflow_dispatch:

jobs:
build:
name: Build
strategy:
matrix:
os: [ubuntu-latest, macos-latest]

runs-on: ${{ matrix.os }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v10

- name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v4

- name: Build refraction
run: nix build --fallback --print-build-logs

check:
name: Check flake

strategy:
matrix:
os: [ubuntu-latest, macos-latest]

runs-on: ${{ matrix.os }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v10

- name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v4

- name: Run checks
run: |
cd ./nix/dev
nix flake check --print-build-logs --show-trace
Loading