Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
node_modules
build

README.md
*.md

lttle.yaml
*.yaml

.nvmrc
79 changes: 79 additions & 0 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
@@ -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
86 changes: 86 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions .github/workflows/remove-preview-deployment.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion DEPLOYMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
23 changes: 15 additions & 8 deletions deploy-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
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"
22 changes: 22 additions & 0 deletions deploy-typesense.sh
Original file line number Diff line number Diff line change
@@ -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"
30 changes: 15 additions & 15 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
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"
Loading
Loading