Skip to content

Commit cbd7ca7

Browse files
committed
ci & preview-deployments
resolved LTT-86
1 parent 9b1321b commit cbd7ca7

15 files changed

Lines changed: 277 additions & 55 deletions

.github/workflows/checks.yaml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: ci
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
prepare:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
12+
- uses: actions/cache@v3
13+
with:
14+
path: |
15+
node_modules
16+
key: dependencies-${{ hashFiles('package-lock.json') }}
17+
restore-keys: |
18+
dependencies-${{ hashFiles('package-lock.json') }}
19+
20+
- uses: actions/setup-node@v3
21+
with:
22+
node-version: 22.18.0
23+
24+
- run: npm install --frozen-lockfile 2> >(grep -v warning 1>&2)
25+
26+
typecheck:
27+
needs: [prepare]
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v3
31+
32+
- uses: actions/cache@v3
33+
with:
34+
path: |
35+
node_modules
36+
key: dependencies-${{ hashFiles('package-lock.json') }}
37+
restore-keys: |
38+
dependencies-${{ hashFiles('package-lock.json') }}
39+
40+
- uses: actions/setup-node@v3
41+
with:
42+
node-version: 22.18.0
43+
44+
- run: npm run typecheck
45+
46+
build:
47+
needs: [prepare]
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@v3
51+
52+
- uses: actions/cache@v3
53+
with:
54+
path: |
55+
node_modules
56+
key: dependencies-${{ hashFiles('package-lock.json') }}
57+
restore-keys: |
58+
dependencies-${{ hashFiles('package-lock.json') }}
59+
60+
- uses: actions/cache@v3
61+
with:
62+
path: |
63+
build
64+
key: build-${{ hashFiles('package-lock.json') }}-${{ github.ref }}
65+
restore-keys: |
66+
build-${{ hashFiles('package-lock.json') }}-${{ github.ref }}
67+
build-${{ hashFiles('package-lock.json') }}
68+
69+
- name: "Setting up dummy environment variables into .env.production file"
70+
run: |
71+
echo "DOCS_URL='http://example.com'" >> .env.production
72+
echo "TYPESENSE_FQDN='https://typesense.example.com'" >> .env.production
73+
echo "TYPESENSE_API_KEY='your-typesense-api-key'" >> .env.production
74+
75+
- uses: actions/setup-node@v3
76+
with:
77+
node-version: 22.18.0
78+
79+
- run: npm run build:prod

.github/workflows/ci.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
on:
2+
push:
3+
branches: ["main"]
4+
paths-ignore:
5+
- ".github/workflows/release.yml"
6+
pull_request:
7+
branches: ["main"]
8+
workflow_call:
9+
10+
jobs:
11+
preflight-checks:
12+
uses: ./.github/workflows/checks.yaml
13+
14+
deploy:
15+
needs: [preflight-checks]
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v3
19+
20+
- uses: actions/cache@v3
21+
with:
22+
path: |
23+
node_modules
24+
key: dependencies-${{ hashFiles('package-lock.json') }}
25+
restore-keys: |
26+
dependencies-${{ hashFiles('package-lock.json') }}
27+
28+
- uses: actions/cache@v3
29+
with:
30+
path: |
31+
build
32+
key: build-${{ hashFiles('package-lock.json') }}-${{ github.ref }}
33+
restore-keys: |
34+
build-${{ hashFiles('package-lock.json') }}-${{ github.ref }}
35+
build-${{ hashFiles('package-lock.json') }}
36+
37+
- name: "Installing lttle cli"
38+
run: |
39+
curl -fsSL https://raw.githubusercontent.com/lttle-cloud/ignition/refs/heads/master/get/lttle.sh | bash
40+
41+
- name: "Authenticating with eu.lttle.cloud"
42+
env:
43+
LTTLE_JWT_TOKEN: ${{ secrets.LTTLE_JWT_TOKEN }}
44+
run: |
45+
lttle login --api "http://eu.lttle.cloud:5100" "$LTTLE_JWT_TOKEN"\
46+
47+
- uses: actions/setup-node@v3
48+
with:
49+
node-version: 22.18.0
50+
51+
- run: ./deploy.sh

DEPLOYMENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ For production deployment there are multiple variables needed because we use the
2323

2424
```sh
2525
DOCS_URL=https://path.to.docs.url
26-
TYPESENSE_URL=https://path.to.typesense.url
26+
TYPESENSE_FQDN=https://path.to.typesense.url
2727
TYPESENSE_API_KEY=some-api-key
2828
```
2929

deploy-docs.sh

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
set -e
44

5-
echo "Building the lttle-docs image..."
6-
docker build -f ./docker/dockerfile . -t aifrim/lttle-docs:latest
5+
source ./deploy/utilities.bash
76

8-
echo "Pushing the images to Docker Hub..."
9-
docker push aifrim/lttle-docs:latest
7+
if [[ -f .env.production ]]; then
8+
export $(xargs < .env.production)
9+
fi
1010

11-
echo "Deploying only the nginx-docs"
12-
lttle deploy ./lttle/docs.lttle.yaml
1311

14-
exec "Restarting the machine to apply changes"
15-
lttle machine restart --ns docs nginx-docs
12+
namespace="docs-"$(lttle deploy --eval "git.ref == 'main' ? 'main' : git.ref + '-branch'");
13+
tag=$(lttle deploy --eval "git.ref == 'main' ? 'latest' : git.ref + '-branch'")
14+
typesenseFQDN=$(lttle deploy --eval "git.ref == 'main' ? 'docs-search.lttle.aifrim.com' : 'docs-search-' + git.ref + '-lttle-aifrim.eu.lttle.host'")
15+
16+
deployDocs "$namespace" "$tag" "$typesenseFQDN"

deploy-typesense.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
source ./deploy/utilities.bash
6+
7+
if [[ -f .env.production ]]; then
8+
export $(xargs < .env.production)
9+
fi
10+
11+
namespace="docs-"$(lttle deploy --eval "git.ref == 'main' ? 'main' : git.ref + '-branch'");
12+
tag=$(lttle deploy --eval "git.ref == 'main' ? 'latest' : git.ref + '-branch'")
13+
14+
docsUrl="https://"$(lttle deploy --eval "git.ref == 'main' ? 'docs.lttle.aifrim.com' : 'docs-' + git.ref + '-lttle-aifrim.eu.lttle.host'");
15+
typesenseFQDN=$(lttle deploy --eval "git.ref == 'main' ? 'docs-search.lttle.aifrim.com' : 'docs-search-' + git.ref + '-lttle-aifrim.eu.lttle.host'")
16+
17+
deployTypeSense "$namespace" "$tag" "$docsUrl" "$typesenseFQDN"

deploy.sh

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,19 @@
22

33
set -e
44

5-
echo "Building the lttle-docs image..."
6-
docker build -f ./docker/dockerfile . -t aifrim/lttle-docs:latest
5+
source ./deploy/utilities.bash
76

8-
echo "Pushing the images to Docker Hub..."
9-
docker push aifrim/lttle-docs:latest
7+
if [[ -f .env.production ]]; then
8+
export $(xargs < .env.production)
9+
fi
1010

11-
echo "Building the Typesense Scraper image..."
12-
docker build -f ./docker/typesense-scraper.dockerfile docker -t aifrim/typesense-scraper:latest
11+
lttle --deploy --eval "" --debug-context
1312

14-
docker push aifrim/typesense-scraper:latest
13+
namespace="docs-"$(lttle deploy --eval "git.ref == 'main' ? 'main' : git.ref + '-branch'");
14+
tag=$(lttle deploy --eval "git.ref == 'main' ? 'latest' : git.ref + '-branch'")
1515

16-
echo "Deploying to lttle.cloud..."
17-
lttle deploy ./lttle
16+
docsUrl="https://"$(lttle deploy --eval "git.ref == 'main' ? 'docs.lttle.aifrim.com' : 'docs-' + git.ref + '-lttle-aifrim.eu.lttle.host'");
17+
typesenseFQDN=$(lttle deploy --eval "git.ref == 'main' ? 'docs-search.lttle.aifrim.com' : 'docs-search-' + git.ref + '-lttle-aifrim.eu.lttle.host'")
1818

19-
# Restarting the machines to always make sure that new changes are picked up (e.g. env vars)
20-
# TODO: Check wether this is still the case with @laurci
21-
echo "Restarting the machines..."
22-
lttle machine restart --ns docs nginx-docs
23-
lttle machine restart --ns docs typesense-search
24-
lttle machine restart --ns docs typesense-scraper
19+
deployDocs "$namespace" "$tag" "$typesenseFQDN"
20+
deployTypeSense "$namespace" "$tag" "$docsUrl"

deploy/utilities.bash

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
3+
deployDocs() {
4+
local ns="$1"
5+
local tag="$2"
6+
local typesenseFQDN="$3"
7+
8+
echo "Building the aifrim/lttle-docs:$tag image..."
9+
docker build --build-arg TYPESENSE_FQDN="$typesenseFQDN" --build-arg TYPESENSE_API_KEY="$TYPESENSE_API_KEY" -f ./docker/dockerfile . -t aifrim/lttle-docs:$tag
10+
11+
echo "Pushing the aifrim/lttle-docs:$tag image..."
12+
docker push aifrim/lttle-docs:$tag
13+
14+
echo "Deploying only the nginx-docs"
15+
lttle deploy ./lttle/docs.lttle.yaml
16+
17+
echo "Restarting the machine in namespace $ns..."
18+
lttle machine restart --ns $ns nginx-docs
19+
}
20+
21+
deployTypeSense() {
22+
local ns="$1"
23+
local tag="$2"
24+
local docsUrl="$3"
25+
26+
if [[ $ns != 'main' ]]; then
27+
echo "Backing up & patching ./docker/typesense-production.config.json"
28+
29+
# Need to patch ./docker/typesense-production.config.json to scrape preview environment url
30+
cp ./docker/typesense-scraper.production.config.json ./docker/typesense-scraper.production.config.json.bak
31+
jq --arg url "$docsUrl" '.start_urls[0].url = $url' ./docker/typesense-scraper.production.config.json.bak > ./docker/typesense-scraper.production.config.json
32+
fi
33+
34+
echo "Building the aifrim/typesense-scraper:$tag image..."
35+
36+
echo "Using config";
37+
bat --paging never ./docker/typesense-scraper.production.config.json
38+
39+
docker build -f ./docker/typesense-scraper.dockerfile docker -t aifrim/typesense-scraper:$tag
40+
41+
if [[ $ns != 'main' ]]; then
42+
echo "Restoring ./docker/typesense-scraper.production.config.json"
43+
cp ./docker/typesense-scraper.production.config.json.bak ./docker/typesense-scraper.production.config.json
44+
rm ./docker/typesense-scraper.production.config.json.bak
45+
fi
46+
47+
echo "Pushing the aifrim/typesense-scraper:$tag image..."
48+
docker push aifrim/typesense-scraper:$tag
49+
50+
echo "Deploying only the typesense-search"
51+
lttle deploy ./lttle/typesense.lttle.yaml
52+
53+
echo "Restarting the machine in namespace $ns..."
54+
lttle machine restart --ns $ns typesense-search
55+
lttle machine restart --ns $ns typesense-scraper
56+
}
57+
58+
restartMachines() {
59+
local ns="$1"
60+
61+
echo "Restarting the machine in namespace $ns..."
62+
63+
lttle machine restart --ns $ns nginx-docs
64+
lttle machine restart --ns $ns typesense-search
65+
lttle machine restart --ns $ns typesense-scraper
66+
}

docker/dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ FROM node:22.18.0-alpine3.22 AS build
33

44
WORKDIR /build
55

6+
ARG TYPESENSE_FQDN
7+
ARG TYPESENSE_API_KEY
8+
9+
ENV TYPESENSE_FQDN=$TYPESENSE_FQDN
10+
ENV TYPESENSE_API_KEY=$TYPESENSE_API_KEY
11+
612
COPY . .
713

814
RUN npm install --frozen-lockfile

docker/typesense-scraper.config.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
22
"index_name": "lttle-cloud-docs",
3-
"allowed_domains": [
4-
"host.docker.internal"
5-
],
3+
"allowed_domains": ["host.docker.internal"],
64
"start_urls": [
75
{
86
"url": "http://host.docker.internal:3000/"
@@ -19,4 +17,4 @@
1917
"text": "p, li"
2018
},
2119
"nb_hits": 182
22-
}
20+
}

docusaurus.config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
import dotenv from "dotenv";
12
import { getConfig } from "./docusaurus";
23

4+
dotenv.config({ path: ".env" });
5+
6+
const x = 1;
7+
38
export default getConfig({
49
url: "http://localhost:3000",
510
typesenseServerConfig: {
@@ -10,7 +15,6 @@ export default getConfig({
1015
protocol: "http",
1116
},
1217
],
13-
// FIXME: Get api key from env var
14-
apiKey: "local-typesense-api-key",
18+
apiKey: process.env.TYPESENSE_API_KEY,
1519
},
1620
});

0 commit comments

Comments
 (0)