From 29e86facece90b60b4fe92fbc32fbffa62572de0 Mon Sep 17 00:00:00 2001 From: James Loh Date: Wed, 25 Jun 2025 16:06:11 +1000 Subject: [PATCH] Improve Tinybird login experience - This helps clean up the TB setup since we no longer need to install the CLI tools locally - The service dependency chaining is a bit annoying here but it should all work - We have to change some of the mounts around because of how TB works and where it expects tokens to be --- compose.yml | 33 ++++++++++++++++++++++++++------- tinybird/Dockerfile | 3 +++ tinybird/handleLogin.sh | 11 +++++++++++ tinybird/tb-wrapper | 18 ++++++++++++++++++ 4 files changed, 58 insertions(+), 7 deletions(-) create mode 100755 tinybird/handleLogin.sh create mode 100755 tinybird/tb-wrapper diff --git a/compose.yml b/compose.yml index 733d6b5..a3e600d 100644 --- a/compose.yml +++ b/compose.yml @@ -116,21 +116,39 @@ services: # Suporting Services + tinybird-login: + build: + context: ./tinybird + dockerfile: Dockerfile + working_dir: /home/tinybird + command: /usr/local/bin/tinybird-login + volumes: + - tinybird_home:/home/tinybird + - tinybird_files:/data/tinybird + profiles: [analytics] + networks: + - ghost_network + tty: true + restart: no + tinybird-sync: # Do not alter this without updating the Ghost container as well image: ghost:${GHOST_VERSION:-5-alpine} command: > sh -c " if [ -d /var/lib/ghost/current/core/server/data/tinybird ]; then - rm -rf /shared/tinybird/*; - cp -rf /var/lib/ghost/current/core/server/data/tinybird/* /shared/tinybird/; + rm -rf /data/tinybird/*; + cp -rf /var/lib/ghost/current/core/server/data/tinybird/* /data/tinybird/; echo 'Tinybird files synced into shared volume.'; else echo 'Tinybird source directory not found.'; fi " volumes: - - tinybird_files:/shared/tinybird + - tinybird_files:/data/tinybird + depends_on: + tinybird-login: + condition: service_completed_successfully networks: - ghost_network profiles: [analytics] @@ -140,14 +158,14 @@ services: build: context: ./tinybird dockerfile: Dockerfile - working_dir: /home/tinybird + working_dir: /data/tinybird command: > sh -c " - tb --cloud deploy + tb-wrapper --cloud deploy " volumes: - - .tinyb:/home/tinybird/.tinyb - - tinybird_files:/home/tinybird + - tinybird_home:/home/tinybird + - tinybird_files:/data/tinybird depends_on: tinybird-sync: condition: service_completed_successfully @@ -172,6 +190,7 @@ volumes: caddy_data: caddy_config: tinybird_files: + tinybird_home: networks: ghost_network: diff --git a/tinybird/Dockerfile b/tinybird/Dockerfile index 3153238..53c9e8a 100644 --- a/tinybird/Dockerfile +++ b/tinybird/Dockerfile @@ -9,6 +9,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ WORKDIR /home/tinybird # Install Tinybird using the standard installation script +COPY handleLogin.sh /usr/local/bin/tinybird-login +COPY tb-wrapper /usr/local/bin/tb-wrapper + RUN curl https://tinybird.co | sh ENV PATH="/root/.local/bin:$PATH" diff --git a/tinybird/handleLogin.sh b/tinybird/handleLogin.sh new file mode 100755 index 0000000..48989de --- /dev/null +++ b/tinybird/handleLogin.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +# Check if already logged in +if [[ -f "/home/tinybird/.tinyb" ]] +then + echo "Tinybird already logged in" + exit 0 +fi + +# Login to Tinybird +tb login --method code diff --git a/tinybird/tb-wrapper b/tinybird/tb-wrapper new file mode 100755 index 0000000..7a10ef9 --- /dev/null +++ b/tinybird/tb-wrapper @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +# Check if .tinyb exists in current directory +if [[ ! -f "./.tinyb" ]] +then + # If not, try to copy from home directory + if [[ -f "/home/tinybird/.tinyb" ]] + then + cp /home/tinybird/.tinyb ./.tinyb + echo "Copied .tinyb auth file to current directory" + else + echo "No .tinyb auth file found, please run 'docker compose run --rm tinybird-login' first to login" + exit 1 + fi +fi + +# Run the tinybird command +tb "$@"