Skip to content

Commit 0852d9b

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

21 files changed

Lines changed: 493 additions & 59 deletions

.dockerignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
node_modules
55
build
66

7-
README.md
7+
*.md
88

9-
lttle.yaml
9+
*.yaml
1010

1111
.nvmrc

.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: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
preflight-checks:
16+
uses: ./.github/workflows/checks.yaml
17+
18+
deploy:
19+
needs: [preflight-checks]
20+
runs-on: ubuntu-latest
21+
environment:
22+
name: ${{ github.head_ref }}
23+
url: ${{ steps.deploymentUrl.outputs.url }}
24+
steps:
25+
- uses: actions/checkout@v3
26+
27+
- uses: actions/cache@v3
28+
with:
29+
path: |
30+
node_modules
31+
key: dependencies-${{ hashFiles('package-lock.json') }}
32+
restore-keys: |
33+
dependencies-${{ hashFiles('package-lock.json') }}
34+
35+
- uses: actions/cache@v3
36+
with:
37+
path: |
38+
build
39+
key: build-${{ hashFiles('package-lock.json') }}-${{ github.ref }}
40+
restore-keys: |
41+
build-${{ hashFiles('package-lock.json') }}-${{ github.ref }}
42+
build-${{ hashFiles('package-lock.json') }}
43+
44+
- name: Login to Docker Hub
45+
uses: docker/login-action@v3
46+
with:
47+
username: ${{ vars.DOCKERHUB_USERNAME }}
48+
password: ${{ secrets.DOCKERHUB_TOKEN }}
49+
50+
- name: "Installing lttle cli"
51+
run: |
52+
curl -fsSL https://raw.githubusercontent.com/lttle-cloud/ignition/refs/heads/master/get/lttle.sh | bash
53+
54+
- name: "Authenticating with eu.lttle.cloud"
55+
env:
56+
LTTLE_JWT_TOKEN: ${{ secrets.LTTLE_JWT_TOKEN }}
57+
run: |
58+
lttle login --api "http://eu.lttle.cloud:5100" "$LTTLE_JWT_TOKEN"\
59+
60+
- uses: actions/setup-node@v3
61+
with:
62+
node-version: 22.18.0
63+
- name: "Setting up environment variables into .env.production file"
64+
run: |
65+
echo "TYPESENSE_API_KEY='$TYPESENSE_API_KEY'" >> .env.production
66+
67+
- name: "Setting deployment url"
68+
id: deploymentUrl
69+
run: |
70+
url="https://"$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'docs.lttle.aifrim.com' : 'docs-' + env.GITHUB_HEAD_REF + '-lttle-aifrim.eu.lttle.host'")
71+
echo "url=$url" >> $GITHUB_OUTPUT
72+
73+
# TODO: Split this into several bash functions so that we can use the dedicated docker build actions
74+
# To facilitate caching so that rebuilding will be faster
75+
# https://docs.docker.com/build/ci/github-actions/
76+
- name: "Deploying the application"
77+
run: ./deploy.sh
78+
79+
# NOTE: This has been added because we need to wait for the application to be fully up before proceeding
80+
# The status of the machine does not reflect the readiness of the service + machine to receive traffic
81+
# And we want the scraper to actually scrape the documentation post-deployment & readiness
82+
- name: "Waiting for the application to be ready"
83+
run: ./wait-for-app.sh
84+
85+
- name: "Restarting the application"
86+
run: ./restart.sh scraper
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
on:
2+
pull_request:
3+
branches:
4+
- main
5+
types:
6+
- closed
7+
8+
jobs:
9+
remove:
10+
if: github.event.pull_request.merged == true
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: "Remove Preview Deployment"
14+
run: |
15+
./remove.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: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@
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
11+
if [ -z "${GITHUB_HEAD_REF+x}" ]; then
12+
GITHUB_HEAD_REF=$(git rev-parse --abbrev-ref HEAD)
13+
export GITHUB_HEAD_REF
14+
fi
1315

14-
exec "Restarting the machine to apply changes"
15-
lttle machine restart --ns docs nginx-docs
16+
namespace="docs-"$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'main' : env.GITHUB_HEAD_REF + '-branch'")
17+
tag=$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'latest' : env.GITHUB_HEAD_REF + '-branch'")
18+
19+
docsURL="https://"$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'docs.lttle.aifrim.com' : 'docs-' + env.GITHUB_HEAD_REF + '-lttle-aifrim.eu.lttle.host'")
20+
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'")
21+
22+
deployDocs "$namespace" "$tag" "$docsURL" "$typesenseFQDN"

deploy-typesense.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
if [ -z "${GITHUB_HEAD_REF+x}" ]; then
12+
GITHUB_HEAD_REF=$(git rev-parse --abbrev-ref HEAD)
13+
export GITHUB_HEAD_REF
14+
fi
15+
16+
namespace="docs-"$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'main' : env.GITHUB_HEAD_REF + '-branch'");
17+
tag=$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'latest' : env.GITHUB_HEAD_REF + '-branch'")
18+
19+
docsURL="https://"$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'docs.lttle.aifrim.com' : 'docs-' + env.GITHUB_HEAD_REF + '-lttle-aifrim.eu.lttle.host'")
20+
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'")
21+
22+
deployTypeSense "$namespace" "$tag" "$docsURL" "$typesenseFQDN"

deploy.sh

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
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+
if [ -z "${GITHUB_HEAD_REF+x}" ]; then
12+
GITHUB_HEAD_REF=$(git rev-parse --abbrev-ref HEAD)
13+
export GITHUB_HEAD_REF
14+
fi
1315

14-
docker push aifrim/typesense-scraper:latest
1516

16-
echo "Deploying to lttle.cloud..."
17-
lttle deploy ./lttle
17+
namespace="docs-"$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'main' : env.GITHUB_HEAD_REF + '-branch'");
18+
tag=$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'latest' : env.GITHUB_HEAD_REF + '-branch'")
1819

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
20+
docsURL="https://"$(lttle deploy --eval "env.GITHUB_HEAD_REF == 'main' ? 'docs.lttle.aifrim.com' : 'docs-' + env.GITHUB_HEAD_REF + '-lttle-aifrim.eu.lttle.host'");
21+
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'")
22+
23+
deployDocs "$namespace" "$tag" "$docsURL" "$typesenseFQDN"
24+
deployTypeSense "$namespace" "$tag" "$docsURL"

0 commit comments

Comments
 (0)