From 0852d9bfa2880b43e6d5d3c7d4fc980eb667e280 Mon Sep 17 00:00:00 2001 From: Alexandru Ifrim Date: Sun, 31 Aug 2025 17:29:32 +0300 Subject: [PATCH] ci & preview-deployments resolved LTT-86 --- .dockerignore | 4 +- .github/workflows/checks.yaml | 79 +++++++++++ .github/workflows/ci.yaml | 86 ++++++++++++ .../workflows/remove-preview-deployment.yaml | 15 +++ DEPLOYMENT.md | 2 +- deploy-docs.sh | 23 ++-- deploy-typesense.sh | 22 ++++ deploy.sh | 30 ++--- deploy/utilities.bash | 124 ++++++++++++++++++ docker/dockerfile | 8 ++ docker/typesense-scraper.config.json | 6 +- docusaurus.config.ts | 6 +- docusaurus.production.config.ts | 11 +- lttle/certs.lttle.yaml | 4 +- lttle/docs.lttle.yaml | 15 ++- lttle/typesense.lttle.yaml | 20 +-- package-lock.json | 6 +- remove.sh | 39 ++++++ restart.sh | 31 +++++ tsconfig.json | 2 +- wait-for-app.sh | 19 +++ 21 files changed, 493 insertions(+), 59 deletions(-) create mode 100644 .github/workflows/checks.yaml create mode 100644 .github/workflows/ci.yaml create mode 100644 .github/workflows/remove-preview-deployment.yaml create mode 100755 deploy-typesense.sh create mode 100644 deploy/utilities.bash create mode 100755 remove.sh create mode 100755 restart.sh create mode 100755 wait-for-app.sh diff --git a/.dockerignore b/.dockerignore index 3e80e8c..8e089d4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,8 +4,8 @@ node_modules build -README.md +*.md -lttle.yaml +*.yaml .nvmrc \ No newline at end of file diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml new file mode 100644 index 0000000..1d0a8c5 --- /dev/null +++ b/.github/workflows/checks.yaml @@ -0,0 +1,79 @@ +name: ci + +on: + workflow_call: + +jobs: + prepare: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: actions/cache@v3 + with: + path: | + node_modules + key: dependencies-${{ hashFiles('package-lock.json') }} + restore-keys: | + dependencies-${{ hashFiles('package-lock.json') }} + + - uses: actions/setup-node@v3 + with: + node-version: 22.18.0 + + - run: npm install --frozen-lockfile 2> >(grep -v warning 1>&2) + + typecheck: + needs: [prepare] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: actions/cache@v3 + with: + path: | + node_modules + key: dependencies-${{ hashFiles('package-lock.json') }} + restore-keys: | + dependencies-${{ hashFiles('package-lock.json') }} + + - uses: actions/setup-node@v3 + with: + node-version: 22.18.0 + + - run: npm run typecheck + + build: + needs: [prepare] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: actions/cache@v3 + with: + path: | + node_modules + key: dependencies-${{ hashFiles('package-lock.json') }} + restore-keys: | + dependencies-${{ hashFiles('package-lock.json') }} + + - uses: actions/cache@v3 + with: + path: | + build + key: build-${{ hashFiles('package-lock.json') }}-${{ github.ref }} + restore-keys: | + build-${{ hashFiles('package-lock.json') }}-${{ github.ref }} + build-${{ hashFiles('package-lock.json') }} + + - name: "Setting up dummy environment variables into .env.production file" + run: | + echo "DOCS_URL='http://example.com'" >> .env.production + echo "TYPESENSE_FQDN='https://typesense.example.com'" >> .env.production + echo "TYPESENSE_API_KEY='your-typesense-api-key'" >> .env.production + + - uses: actions/setup-node@v3 + with: + node-version: 22.18.0 + + - run: npm run build:prod diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..7bf24c0 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,86 @@ +on: + push: + branches: ["main"] + paths-ignore: + - ".github/workflows/release.yml" + pull_request: + branches: ["main"] + workflow_call: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + preflight-checks: + uses: ./.github/workflows/checks.yaml + + deploy: + needs: [preflight-checks] + runs-on: ubuntu-latest + environment: + name: ${{ github.head_ref }} + url: ${{ steps.deploymentUrl.outputs.url }} + steps: + - uses: actions/checkout@v3 + + - uses: actions/cache@v3 + with: + path: | + node_modules + key: dependencies-${{ hashFiles('package-lock.json') }} + restore-keys: | + dependencies-${{ hashFiles('package-lock.json') }} + + - uses: actions/cache@v3 + with: + path: | + build + key: build-${{ hashFiles('package-lock.json') }}-${{ github.ref }} + restore-keys: | + build-${{ hashFiles('package-lock.json') }}-${{ github.ref }} + build-${{ hashFiles('package-lock.json') }} + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: "Installing lttle cli" + run: | + curl -fsSL https://raw.githubusercontent.com/lttle-cloud/ignition/refs/heads/master/get/lttle.sh | bash + + - name: "Authenticating with eu.lttle.cloud" + env: + LTTLE_JWT_TOKEN: ${{ secrets.LTTLE_JWT_TOKEN }} + run: | + lttle login --api "http://eu.lttle.cloud:5100" "$LTTLE_JWT_TOKEN"\ + + - uses: actions/setup-node@v3 + with: + node-version: 22.18.0 + - name: "Setting up environment variables into .env.production file" + run: | + echo "TYPESENSE_API_KEY='$TYPESENSE_API_KEY'" >> .env.production + + - name: "Setting deployment url" + id: deploymentUrl + run: | + url="https://"$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'docs.lttle.aifrim.com' : 'docs-' + env.GITHUB_HEAD_REF + '-lttle-aifrim.eu.lttle.host'") + echo "url=$url" >> $GITHUB_OUTPUT + + # TODO: Split this into several bash functions so that we can use the dedicated docker build actions + # To facilitate caching so that rebuilding will be faster + # https://docs.docker.com/build/ci/github-actions/ + - name: "Deploying the application" + run: ./deploy.sh + + # NOTE: This has been added because we need to wait for the application to be fully up before proceeding + # The status of the machine does not reflect the readiness of the service + machine to receive traffic + # And we want the scraper to actually scrape the documentation post-deployment & readiness + - name: "Waiting for the application to be ready" + run: ./wait-for-app.sh + + - name: "Restarting the application" + run: ./restart.sh scraper diff --git a/.github/workflows/remove-preview-deployment.yaml b/.github/workflows/remove-preview-deployment.yaml new file mode 100644 index 0000000..9979ca2 --- /dev/null +++ b/.github/workflows/remove-preview-deployment.yaml @@ -0,0 +1,15 @@ +on: + pull_request: + branches: + - main + types: + - closed + +jobs: + remove: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + steps: + - name: "Remove Preview Deployment" + run: | + ./remove.sh diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md index 58c8604..d8bb6c4 100644 --- a/DEPLOYMENT.md +++ b/DEPLOYMENT.md @@ -23,7 +23,7 @@ For production deployment there are multiple variables needed because we use the ```sh DOCS_URL=https://path.to.docs.url -TYPESENSE_URL=https://path.to.typesense.url +TYPESENSE_FQDN=https://path.to.typesense.url TYPESENSE_API_KEY=some-api-key ``` diff --git a/deploy-docs.sh b/deploy-docs.sh index 329e776..9602e74 100755 --- a/deploy-docs.sh +++ b/deploy-docs.sh @@ -2,14 +2,21 @@ set -e -echo "Building the lttle-docs image..." -docker build -f ./docker/dockerfile . -t aifrim/lttle-docs:latest +source ./deploy/utilities.bash -echo "Pushing the images to Docker Hub..." -docker push aifrim/lttle-docs:latest +if [[ -f .env.production ]]; then + export $(xargs < .env.production) +fi -echo "Deploying only the nginx-docs" -lttle deploy ./lttle/docs.lttle.yaml +if [ -z "${GITHUB_HEAD_REF+x}" ]; then + GITHUB_HEAD_REF=$(git rev-parse --abbrev-ref HEAD) + export GITHUB_HEAD_REF +fi -exec "Restarting the machine to apply changes" -lttle machine restart --ns docs nginx-docs \ No newline at end of file +namespace="docs-"$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'main' : env.GITHUB_HEAD_REF + '-branch'") +tag=$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'latest' : env.GITHUB_HEAD_REF + '-branch'") + +docsURL="https://"$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'docs.lttle.aifrim.com' : 'docs-' + env.GITHUB_HEAD_REF + '-lttle-aifrim.eu.lttle.host'") +typesenseFQDN=$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'docs-search.lttle.aifrim.com' : 'docs-search-' + env.GITHUB_HEAD_REF + '-lttle-aifrim.eu.lttle.host'") + +deployDocs "$namespace" "$tag" "$docsURL" "$typesenseFQDN" diff --git a/deploy-typesense.sh b/deploy-typesense.sh new file mode 100755 index 0000000..b5c81f0 --- /dev/null +++ b/deploy-typesense.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -e + +source ./deploy/utilities.bash + +if [[ -f .env.production ]]; then + export $(xargs < .env.production) +fi + +if [ -z "${GITHUB_HEAD_REF+x}" ]; then + GITHUB_HEAD_REF=$(git rev-parse --abbrev-ref HEAD) + export GITHUB_HEAD_REF +fi + +namespace="docs-"$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'main' : env.GITHUB_HEAD_REF + '-branch'"); +tag=$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'latest' : env.GITHUB_HEAD_REF + '-branch'") + +docsURL="https://"$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'docs.lttle.aifrim.com' : 'docs-' + env.GITHUB_HEAD_REF + '-lttle-aifrim.eu.lttle.host'") +typesenseFQDN=$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'docs-search.lttle.aifrim.com' : 'docs-search-' + env.GITHUB_HEAD_REF + '-lttle-aifrim.eu.lttle.host'") + +deployTypeSense "$namespace" "$tag" "$docsURL" "$typesenseFQDN" \ No newline at end of file diff --git a/deploy.sh b/deploy.sh index be6bb97..2ee5f85 100755 --- a/deploy.sh +++ b/deploy.sh @@ -2,23 +2,23 @@ set -e -echo "Building the lttle-docs image..." -docker build -f ./docker/dockerfile . -t aifrim/lttle-docs:latest +source ./deploy/utilities.bash -echo "Pushing the images to Docker Hub..." -docker push aifrim/lttle-docs:latest +if [[ -f .env.production ]]; then + export $(xargs < .env.production) +fi -echo "Building the Typesense Scraper image..." -docker build -f ./docker/typesense-scraper.dockerfile docker -t aifrim/typesense-scraper:latest +if [ -z "${GITHUB_HEAD_REF+x}" ]; then + GITHUB_HEAD_REF=$(git rev-parse --abbrev-ref HEAD) + export GITHUB_HEAD_REF +fi -docker push aifrim/typesense-scraper:latest -echo "Deploying to lttle.cloud..." -lttle deploy ./lttle +namespace="docs-"$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'main' : env.GITHUB_HEAD_REF + '-branch'"); +tag=$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'latest' : env.GITHUB_HEAD_REF + '-branch'") -# Restarting the machines to always make sure that new changes are picked up (e.g. env vars) -# TODO: Check wether this is still the case with @laurci -echo "Restarting the machines..." -lttle machine restart --ns docs nginx-docs -lttle machine restart --ns docs typesense-search -lttle machine restart --ns docs typesense-scraper \ No newline at end of file +docsURL="https://"$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'docs.lttle.aifrim.com' : 'docs-' + env.GITHUB_HEAD_REF + '-lttle-aifrim.eu.lttle.host'"); +typesenseFQDN=$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'docs-search.lttle.aifrim.com' : 'docs-search-' + env.GITHUB_HEAD_REF + '-lttle-aifrim.eu.lttle.host'") + +deployDocs "$namespace" "$tag" "$docsURL" "$typesenseFQDN" +deployTypeSense "$namespace" "$tag" "$docsURL" diff --git a/deploy/utilities.bash b/deploy/utilities.bash new file mode 100644 index 0000000..d7bc40f --- /dev/null +++ b/deploy/utilities.bash @@ -0,0 +1,124 @@ +#!/bin/bash + +deployDocs() { + local ns="$1" + local tag="$2" + local docsURL="$3" + local typesenseFQDN="$4" + + echo "Building the aifrim/lttle-docs:$tag image..." + docker build --build-arg DOCS_URL="$docsURL" --build-arg TYPESENSE_FQDN="$typesenseFQDN" --build-arg TYPESENSE_API_KEY="$TYPESENSE_API_KEY" -f ./docker/dockerfile . -t aifrim/lttle-docs:$tag + + echo "Pushing the aifrim/lttle-docs:$tag image..." + docker push aifrim/lttle-docs:$tag + + echo "Deploying only the nginx-docs" + lttle deploy ./lttle/docs.lttle.yaml + + echo "Restarting the machine in namespace $ns..." + lttle machine restart --ns $ns nginx-docs +} + +deployTypeSense() { + local ns="$1" + local tag="$2" + local docsURL="$3" + + if [[ $ns != 'main' ]]; then + echo "Backing up & patching ./docker/typesense-production.config.json" + + # Need to patch ./docker/typesense-production.config.json to scrape preview environment url + cp ./docker/typesense-scraper.production.config.json ./docker/typesense-scraper.production.config.json.bak + jq --arg url "$docsURL" '.start_urls[0].url = $url' ./docker/typesense-scraper.production.config.json.bak > ./docker/typesense-scraper.production.config.json + fi + + echo "Building the aifrim/typesense-scraper:$tag image..." + + echo "Using config"; + cat ./docker/typesense-scraper.production.config.json + + docker build -f ./docker/typesense-scraper.dockerfile docker -t aifrim/typesense-scraper:$tag + + if [[ $ns != 'main' ]]; then + echo "Restoring ./docker/typesense-scraper.production.config.json" + cp ./docker/typesense-scraper.production.config.json.bak ./docker/typesense-scraper.production.config.json + rm ./docker/typesense-scraper.production.config.json.bak + fi + + echo "Pushing the aifrim/typesense-scraper:$tag image..." + docker push aifrim/typesense-scraper:$tag + + echo "Deploying only the typesense-search" + lttle deploy ./lttle/typesense.lttle.yaml + + restartMachines "$ns" +} + +restartMachines() { + local ns="$1" + + echo "Restarting the machine in namespace $ns..." + + lttle machine restart --ns $ns nginx-docs + lttle machine restart --ns $ns typesense-search + lttle machine restart --ns $ns typesense-scraper +} + +isUp() { + local ns="$1" + local machine="$2" + local url="$3" + local timeout="$4" + local sleepDuration="$5" + + echo "Waiting for $url to be ready..." + + echo "Waiting for machine $machine in namespace $ns to be ready..." + + start=$(date +%s) + + while true; do + set +e + lttle machine get --ns "$ns" "$machine" | grep "suspended" > /dev/null 2>&1 + status=$? + set -e + + if [ "$status" -eq 0 ]; then + now=$(date +%s) + elapsed=$((now - start)) + + echo "✅ Machine $machine in namespace $ns is running after $elapsed seconds" + break + fi + + echo "⏳ Machine in namespace $ns not ready yet. Retrying in $sleepDuration seconds..." + sleep $sleepDuration + done + + start=$(date +%s) + + while true; do + set +e + status=$(curl -s -o /dev/null -w "%{http_code}" "$url") + set -e + + if [ "$status" -eq 200 ]; then + now=$(date +%s) + elapsed=$((now - start)) + + echo "✅ $url is up (HTTP 200) after $elapsed seconds" + return 0 + fi + + now=$(date +%s) + elapsed=$((now - start)) + + if [ "$elapsed" -ge "$timeout" ]; then + echo "❌ Timeout reached ($timeout seconds). $url did not return 200." + return 1 + fi + + echo "⏳ $url not ready yet (status: $status). Retrying in $sleepDuration seconds..." + sleep $sleepDuration + done +} diff --git a/docker/dockerfile b/docker/dockerfile index b4bccfa..56ab6fa 100644 --- a/docker/dockerfile +++ b/docker/dockerfile @@ -3,6 +3,14 @@ FROM node:22.18.0-alpine3.22 AS build WORKDIR /build +ARG DOCS_URL +ARG TYPESENSE_FQDN +ARG TYPESENSE_API_KEY + +ENV DOCS_URL=$DOCS_URL \ + TYPESENSE_FQDN=$TYPESENSE_FQDN \ + TYPESENSE_API_KEY=$TYPESENSE_API_KEY + COPY . . RUN npm install --frozen-lockfile diff --git a/docker/typesense-scraper.config.json b/docker/typesense-scraper.config.json index 5ff156c..c6ff026 100644 --- a/docker/typesense-scraper.config.json +++ b/docker/typesense-scraper.config.json @@ -1,8 +1,6 @@ { "index_name": "lttle-cloud-docs", - "allowed_domains": [ - "host.docker.internal" - ], + "allowed_domains": ["host.docker.internal"], "start_urls": [ { "url": "http://host.docker.internal:3000/" @@ -19,4 +17,4 @@ "text": "p, li" }, "nb_hits": 182 -} \ No newline at end of file +} diff --git a/docusaurus.config.ts b/docusaurus.config.ts index 1192956..eb3eca3 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -1,5 +1,8 @@ +import dotenv from "dotenv"; import { getConfig } from "./docusaurus"; +dotenv.config({ path: ".env" }); + export default getConfig({ url: "http://localhost:3000", typesenseServerConfig: { @@ -10,7 +13,6 @@ export default getConfig({ protocol: "http", }, ], - // FIXME: Get api key from env var - apiKey: "local-typesense-api-key", + apiKey: process.env.TYPESENSE_API_KEY, }, }); diff --git a/docusaurus.production.config.ts b/docusaurus.production.config.ts index c0b008c..b65c700 100644 --- a/docusaurus.production.config.ts +++ b/docusaurus.production.config.ts @@ -1,17 +1,18 @@ +import dotenv from "dotenv"; import { getConfig } from "./docusaurus"; +dotenv.config({ path: ".env.production" }); + export default getConfig({ - url: "https://docs.lttle.aifrim.example.com", + url: process.env.DOCS_URL, typesenseServerConfig: { nodes: [ { - // FIXME: Get this from environment variable - host: "docs-search.lttle.aifrim.com", + host: process.env.TYPESENSE_FQDN, port: 443, protocol: "https", }, ], - // FIXME: Get this from environment variable - apiKey: "uVnR&EtnaLDfhTgLK$~'n#.NX>z", + apiKey: process.env.TYPESENSE_API_KEY, }, }); diff --git a/lttle/certs.lttle.yaml b/lttle/certs.lttle.yaml index b274b8c..d90202c 100644 --- a/lttle/certs.lttle.yaml +++ b/lttle/certs.lttle.yaml @@ -1,6 +1,6 @@ certificate: - namespace: docs - name: cert-docs + namespace: docs-main + name: main domains: - docs.lttle.aifrim.com - docs-search.lttle.aifrim.com diff --git a/lttle/docs.lttle.yaml b/lttle/docs.lttle.yaml index 33687eb..3022f82 100644 --- a/lttle/docs.lttle.yaml +++ b/lttle/docs.lttle.yaml @@ -1,14 +1,15 @@ --- machine: - namespace: docs + namespace: "docs-${{ env.GITHUB_HEAD_REF == 'main' ? 'main' : env.GITHUB_HEAD_REF + '-branch' }}" name: nginx-docs - image: aifrim/lttle-docs:latest + image: "aifrim/lttle-docs:${{ env.GITHUB_HEAD_REF == 'main' ? 'latest' : env.GITHUB_HEAD_REF + '-branch' }}" # IMPORTANT: nginx-docs memory & cpu configuration # For the time being, 1 vCPU and 512 MiB should suffice # To be re-visited later - post-MVP resources: cpu: 1 - memory: 512 + # Production 512MiB, Preview Environments for branches: 64Mib + memory: "${{ env.GITHUB_HEAD_REF == 'main' ? 512 : 64 }}" mode: flash: # NOTE: We only need a timeout when NGINX is initially being setup @@ -18,7 +19,7 @@ machine: listen-on-port: 80 --- service: - namespace: docs + namespace: "docs-${{ env.GITHUB_HEAD_REF == 'main' ? 'main' : env.GITHUB_HEAD_REF + '-branch' }}" name: docs-ingress target: name: nginx-docs @@ -26,6 +27,8 @@ service: protocol: http bind: external: - host: docs.lttle.aifrim.com + # Production is docs.lttle.aifrim.com (for now) where we have dedicated certificate + # Preview Environments are reusing the same wildcard certificate from *.eu.lttle.host + host: "${{ env.GITHUB_HEAD_REF == 'main' ? 'docs.lttle.aifrim.com' : 'docs-' + env.GITHUB_HEAD_REF + '-lttle-aifrim.eu.lttle.host' }}" protocol: https - certificate: cert-docs + certificate: "${{ env.GITHUB_HEAD_REF == 'main' ? 'main' : null }}" diff --git a/lttle/typesense.lttle.yaml b/lttle/typesense.lttle.yaml index dfc4cb0..2a698ba 100644 --- a/lttle/typesense.lttle.yaml +++ b/lttle/typesense.lttle.yaml @@ -2,7 +2,7 @@ # FIXME: Only allow certain domains to call this machine by enabling CORS # TODO: Look for other important security measures for TypeSense machine: - namespace: docs + namespace: "docs-${{ env.GITHUB_HEAD_REF == 'main' ? 'main' : env.GITHUB_HEAD_REF + '-branch' }}" name: typesense-search image: typesense/typesense:29.0 # IMPORTANT: typesense memory & cpu configuration @@ -30,9 +30,9 @@ machine: TYPESENSE_DATA_DIR: /data --- machine: - namespace: docs + namespace: "docs-${{ env.GITHUB_HEAD_REF == 'main' ? 'main' : env.GITHUB_HEAD_REF + '-branch' }}" name: typesense-scraper - image: aifrim/typesense-scraper:latest + image: "aifrim/typesense-scraper:${{ env.GITHUB_HEAD_REF == 'main' ? 'latest' : env.GITHUB_HEAD_REF + '-branch' }}" # TODO: Check memory usage of the TypeSense Scraper and adjust memory resources: cpu: 1 @@ -54,9 +54,9 @@ machine: - name: typesense-search environment: # TODO: Must get this from an environment variable - TYPESENSE_API_KEY: uVnR&EtnaLDfhTgLK$~'n#.NX>z + TYPESENSE_API_KEY: ${{ env.TYPESENSE_API_KEY }} # This is service-name.namespace.svc.lttle.local - TYPESENSE_HOST: typesense-search-internal.docs.svc.lttle.local + TYPESENSE_HOST: "typesense-search-internal.docs-${{ env.GITHUB_HEAD_REF == 'main' ? 'main' : env.GITHUB_HEAD_REF + '-branch' }}.svc.lttle.local" # NOTE: Does this really need to always be a string, can it not be # A number or a boolean, and then we can transform it to a string? TYPESENSE_PORT: "8108" @@ -70,7 +70,7 @@ machine: --- # This makes typesense reachable from the docs search service: - namespace: docs + namespace: "docs-${{ env.GITHUB_HEAD_REF == 'main' ? 'main' : env.GITHUB_HEAD_REF + '-branch' }}" name: typesense-search-ingress target: name: typesense-search @@ -78,14 +78,14 @@ service: protocol: http bind: external: - host: docs-search.lttle.aifrim.com + host: "${{ env.GITHUB_HEAD_REF == 'main' ? 'docs-search.lttle.aifrim.com' : 'docs-search-' + env.GITHUB_HEAD_REF + '-lttle-aifrim.eu.lttle.host' }}" protocol: https - certificate: cert-docs + certificate: "${{ env.GITHUB_HEAD_REF == 'main' ? 'cert-docs' : null }}" --- # This makes typesense reachable internally # We point the typesense-scraper to send scraped data to this internal service service: - namespace: docs + namespace: "docs-${{ env.GITHUB_HEAD_REF == 'main' ? 'main' : env.GITHUB_HEAD_REF + '-branch' }}" name: typesense-search-internal target: name: typesense-search @@ -96,7 +96,7 @@ service: internal: {} --- volume: - namespace: docs + namespace: "docs-${{ env.GITHUB_HEAD_REF == 'main' ? 'main' : env.GITHUB_HEAD_REF + '-branch' }}" mode: writeable name: typesense-search # NOTE: This may be too much for now. Since the size of the docs I would say diff --git a/package-lock.json b/package-lock.json index 7366fc0..0957d74 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7687,9 +7687,9 @@ } }, "node_modules/docusaurus-theme-search-typesense": { - "version": "0.25.0-0", - "resolved": "https://registry.npmjs.org/docusaurus-theme-search-typesense/-/docusaurus-theme-search-typesense-0.25.0-0.tgz", - "integrity": "sha512-QLsbvTxc5tAER0xes0H/8Jkr4sMInYImXjxCBlwizEXujkrbwQnw0gdxo9EqqB2/ieH7xuRsLyUDjdGdEiQ+9Q==", + "version": "0.25.0", + "resolved": "https://registry.npmjs.org/docusaurus-theme-search-typesense/-/docusaurus-theme-search-typesense-0.25.0.tgz", + "integrity": "sha512-1+yJcQ+5faPZNKNH9wzk5ixrOhEeCY08Z/cPEBvv4W1AZMYK9jQnzHpFnUbVElRTbA4KrOpg6TD1ProLECuqrA==", "dev": true, "license": "MIT", "dependencies": { diff --git a/remove.sh b/remove.sh new file mode 100755 index 0000000..5e6a7c8 --- /dev/null +++ b/remove.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +set -e + +source ./deploy/utilities.bash + +if [[ -f .env.production ]]; then + export $(xargs < .env.production) +fi + +if [ -z "${GITHUB_HEAD_REF+x}" ]; then + GITHUB_HEAD_REF=$(git rev-parse --abbrev-ref HEAD) + export GITHUB_HEAD_REF +fi + +namespace="docs-"$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'main' : env.GITHUB_HEAD_REF + '-branch'") + +# if the namespace is docs-main, we stop +if [ "$namespace" == "docs-main" ]; then + echo "We do not remove the main documentation" + exit 0 +fi + +echo "Removing machines for namespace $namespace" +lttle machine rm --ns "$namespace" nginx-docs -y +lttle machine rm --ns "$namespace" typesense-search -y +lttle machine rm --ns "$namespace" typesense-scraper -y + +echo "Removing services for namespace $namespace" +lttle service rm --ns "$namespace" docs-ingress -y +lttle service rm --ns "$namespace" typesense-search-ingress -y +lttle service rm --ns "$namespace" typesense-search-internal -y + +echo "Removing volumes for namespace $namespace" +lttle volume rm --ns "$namespace" typesense-search -y + +lttle cert rm --ns "$namespace" cert-docs -y + +echo "Certificates are not removed" diff --git a/restart.sh b/restart.sh new file mode 100755 index 0000000..3cc6b5d --- /dev/null +++ b/restart.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +set -e + +source ./deploy/utilities.bash + +if [[ -f .env.production ]]; then + export $(xargs < .env.production) +fi + +if [ -z "${GITHUB_HEAD_REF+x}" ]; then + GITHUB_HEAD_REF=$(git rev-parse --abbrev-ref HEAD) + export GITHUB_HEAD_REF +fi + +namespace="docs-"$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'main' : env.GITHUB_HEAD_REF + '-branch'"); + +what="$1" + +if [[ "$what" == "scraper" ]]; then + echo "Restarting typesense-scraper in namespace $namespace" + lttle machine restart --ns $namespace typesense-scraper +elif [[ "$what" == "docs" ]]; then + echo "Restarting nginx-docs in namespace $namespace" + lttle machine restart --ns $namespace nginx-docs +elif [[ "$what" == "search" ]]; then + echo "Restarting typesense-search in namespace $namespace" + lttle machine restart --ns $namespace typesense-search +else + restartMachines "$namespace" +fi \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 920d7a6..27771a1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,5 +4,5 @@ "compilerOptions": { "baseUrl": "." }, - "exclude": [".docusaurus", "build"] + "exclude": [".docusaurus", "build", "node_modules"] } diff --git a/wait-for-app.sh b/wait-for-app.sh new file mode 100755 index 0000000..55cbd89 --- /dev/null +++ b/wait-for-app.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e + +source ./deploy/utilities.bash + +if [[ -f .env.production ]]; then + export $(xargs < .env.production) +fi + +if [ -z "${GITHUB_HEAD_REF+x}" ]; then + GITHUB_HEAD_REF=$(git rev-parse --abbrev-ref HEAD) + export GITHUB_HEAD_REF +fi + +docsURL="https://"$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'docs.lttle.aifrim.com' : 'docs-' + env.GITHUB_HEAD_REF + '-lttle-aifrim.eu.lttle.host'") +namespace="docs-"$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'main' : env.GITHUB_HEAD_REF + '-branch'") + +isUp "$namespace" "nginx-docs" "$docsURL" 300 1 \ No newline at end of file