a2797a8dac8bc18d31cf03d3c189b0129f5935ed — Nick Parker 4 months ago 4030a94
Build docker images in CI, tidy up readme, add -v/--version arg
4 files changed, 72 insertions(+), 23 deletions(-)

M .build.yml
M Dockerfile
M src/main.rs
M .build.yml => .build.yml +29 -6
@@ 1,9 1,32 @@
image: alpine/edge
image: debian/testing
- cargo
- buildah
# required to avoid Dockerfile RUN errors around 'fork/exec : no such file or directory'
- podman
# both required to avoid Dockerfile RUN errors around 'Exec format error'
- binfmt-support
- qemu-user-static
# creates /home/build/.docker/config.json
- bab5a237-674a-4992-9dfd-dbb5fd3ac176
  repo: twitch-rss
  REPO_NAME: twitch-rss
  IMAGE_NAME: docker.io/nickbp/twitch-rss
  IMAGE_PLATFORMS: linux/amd64,linux/arm64
- build: |
    cd $repo/
    cargo test --all
# build amd64+arm64 images
- docker: |
    # required to fix errors like "potentially insufficient UIDs or GIDs available in user namespace"
    sudo touch /etc/subuid /etc/subgid
    sudo usermod --add-subuids 100000-165535 --add-subgids 100000-165535 $USER

    cd $REPO_NAME/
    # build to SHA and branchname tags
    GIT_REV="$(git rev-parse --short HEAD)"

    # build amd64+arm64 images to named manifest. requires buildah >=1.23.1 and takes a long time
    # see also https://podman.io/blogs/2021/10/11/multiarch.html
    buildah build --manifest "${REPO_NAME}_${GIT_REV}" --jobs=4 --platform="${IMAGE_PLATFORMS}" .

    # push manifest and built amd64+arm64 images to both rev and branch tags
    buildah manifest push --all "${REPO_NAME}_${GIT_REV}" "docker://${IMAGE_NAME}:${GIT_REV}"

M Dockerfile => Dockerfile +9 -4
@@ 1,8 1,13 @@
# Builds an image containing the binary and little else.
FROM rust:slim

# Builder image
FROM docker.io/library/rust:slim
COPY . /twitch-rss
RUN cd /twitch-rss && cargo build --all-targets --release
RUN cd /twitch-rss \
  && cargo --version \
  && cargo build --all-targets --release

FROM debian:buster-slim
# Release image: copy executable from builder
FROM docker.io/library/debian:buster-slim
COPY --from=0 /twitch-rss/target/release/twitch-rss /twitch-rss
RUN chmod +x /twitch-rss
RUN chmod +x /twitch-rss && /twitch-rss --version

M README.md => README.md +25 -11
@@ 1,5 1,7 @@
# Twitch-RSS

[![builds.sr.ht status](https://builds.sr.ht/~nickbp/twitch-rss.svg)](https://builds.sr.ht/~nickbp/twitch-rss)

Generates RSS feeds for Twitch accounts.

This acts as a proxy to Twitch, presenting video history as an RSS feed. The idea is that you can add specific accounts to your RSS reader as separate URLs/feeds.

@@ 19,20 21,20 @@ To install `twitch-rss`, you can run `cargo install twitch-rss`. [Docker images]

0. Prerequisites: Get your Twitch App credentials, and install `twitch-rss` using `cargo install twitch-rss`.
1. Start `twitch-rss` with `CLIENT_ID` and `CLIENT_SECRET` envvars containing the Twitch App credentials. You can optionally also specify `LISTEN`, `` is the default:
$ CLIENT_ID=1234...abcd \
    CLIENT_SECRET=5678...efgh \
    LISTEN= \
2. Add `twitch-rss` URL(s) to your RSS reader (e.g. [`miniflux`](https://miniflux.app)), or test manually with `curl`:
$ curl -v ''
    $ CLIENT_ID=1234...abcd \
        CLIENT_SECRET=5678...efgh \
        LISTEN= \
2. Once `twitch-rss` is running, you can then add it to your RSS reader with `/rss?account=ACCOUNT_NAME_HERE` added to the end of the `LISTEN` address. You can test this manually with `curl`:
    $ curl -v ''

### CLI/stdout

Alternatively you can also run `twitch-rss` via the CLI with the account to query, and it will write the RSS to stdout. This is useful for testing or for writing the RSS payload to a static page.
You can also run `twitch-rss` via the command line with the account to query as an argument. The command will then write the RSS payload to stdout. This is mainly useful for testing, or for writing the RSS payload to a static file.

$ CLIENT_ID=1234...abcd \

@@ 40,6 42,18 @@ $ CLIENT_ID=1234...abcd \
    ./twitch-rss ACCOUNT_NAME_HERE

## Options

`twitch-rss` mainly exposes options via environment variables. The one exception is specifying an account name to fetch as an argument, as shown in the [CLI/stdout](#clistdout) example above.

- `CLIENT_ID`/`CLIENT_SECRET`: Your Twitch App credentials for querying the Twitch API. Required.
- `LOG_LEVEL`: Amount of logging you'd like to have. Defaults to `info`, can be set to `debug`/`trace` to get more logs or `warn`/`error`/`off` to get fewer logs.

HTTP-specific options:
- `LISTEN`: The listen address when running in HTTP mode. Defaults to `` (port `8080` on all interfaces).
- `USER_CACHE_SECS`: The duration in seconds to cache information about Twitch accounts. Default is `86400` or 1 day.
- `VIDEO_CACHE_SECS`: The duration in seconds to cache the recent videos for a given Twitch account. Default is `600` = 10 minutes)

## License

This project is [licensed](LICENCE.md) under the [FAFOL](https://git.sr.ht/~boringcactus/fafol/tree/master/README.md). This is intended to restrict use of the project for purposes that would be considered unethical by its authors.

M src/main.rs => src/main.rs +9 -2
@@ 34,7 34,7 @@ fn env_help() -> &'static str {
Environment variables:
  CLIENT_ID:     Twitch Client ID for querying feeds
  CLIENT_SECRET: Twitch Client Secret for querying feeds
  LOG_LEVEL:     error/warn/info/debug/trace/off
  LOG_LEVEL:     error/warn/info/debug/trace/off (default: 'info')

HTTP mode only:
  LISTEN:           Endpoint for HTTP service to listen on (default: '')

@@ 47,9 47,16 @@ fn main() -> Result<()> {

    match env::args().nth(1) {
        Some(username) => {
            if username == "-v" || username == "--version" {
                // Special case to just print the version and exit successfully.
                // Mainly useful for checking that the executable is valid in CI builds.
                println!("twitch-rss ({})", render_testament!(TESTAMENT));
                return Ok(());
            if username.starts_with('-') {
                // Probably a commandline argument like '-h'/'--help', avoid parsing as a user
                println!("{}", syntax());
                bail!("Unrecognized username argument: {}", username);
            let mut twitch_auth = TwitchAuth::new(
                reqenv("CLIENT_ID", "Twitch Client ID for querying feeds")?,