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
10 changes: 10 additions & 0 deletions .github/actions/setup-nodejs/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: 🤖 Setup Nodejs

runs:
using: 'composite'
steps:
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
115 changes: 115 additions & 0 deletions .github/workflows/fleek-deploy-common.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: ⚡️ Deploy site (Common)

on:
workflow_dispatch:
workflow_call:
inputs:
environment:
required: true
type: string

jobs:
deploy-to-fleek:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
env:
DASHBOARD_UNARCHIVED_PATH: "temp/dashboard"
FLEEK_PROJECT_ID: ${{ env.FLEEK_PROJECT_ID }}
FLEEK_SLUG: ${{ env.FLEEK_SLUG }}
FLEEK_TOKEN: ${{ secrets.FLEEK_TOKEN }}
GITHUB_SOURCE_REPO: ${{ github.repository }}
DOPPLER_CONFIG: ${{ env.DOPPLER_CONFIG }}
DOPPLER_PROJECT: ${{ env.DOPPLER_PROJECT }}
DOPPLER_TOKEN: ${{ secrets.DOPPLER_TOKEN }}
TARGET_ENVIRONMENT: ${{ inputs.environment }}
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- uses: ./.github/actions/setup-nodejs

- name: Install Doppler CLI
uses: dopplerhq/cli-action@v3

- name: Setup Doppler
run: |
doppler configure set token "$DOPPLER_TOKEN"
doppler configure set project "$DOPPLER_PROJECT"
doppler configure set config "$DOPPLER_CONFIG"

- name: Env vars health check
run: |
if ! doppler run -- printenv | grep -q 'NEXT_PUBLIC_SDK__AUTHENTICATION_URL'; then
echo "👹 Oops! Missing required environment variable during health check..."
exit 1
fi

echo "🚑 Doppler envVars seem healthy!"

- name: Setup dotenv
run: |
scripts/setup-ci-dotenv

- name: Install Fleek CLI
run: npm i -g @fleek-platform/cli

# TODO: Maybe separate into three steps:
# - Site build
# - Dashboard
# - Deploy
- name: Install Packages
run: npm install

# TODO: It might be wiser to use a regular
# NPM package deployment and copy distribution
# to the local path
- name: Download Dashboard artifact
id: download_dashboard_artifact
run: |
github_token="$GITHUB_TOKEN"
source_repo="$GITHUB_SOURCE_REPO"
dashboard_build_output_filename="build-output-fleek-xyz-$TARGET_ENVIRONMENT"
latest_artifact_file="$dashboard_build_output_filename.zip"

.scripts/download_artifact \
"$github_token" \
"$source_repo" \
"$dashboard_build_output_filename" \
"$latest_artifact_file"

echo "latest_dashboard_artifact=$latest_artifact_file" >> "$GITHUB_OUTPUT"

- name: Prepare Dashboard files
env:
ARTIFACT: ${{ steps.download_dashboard_artifact.outputs.latest_dashboard_artifact }}
OUTPUT_PATH: ${{ env.DASHBOARD_UNARCHIVED_PATH }}
run: |
if ! scripts/unarchive_dashboard_files "$ARTIFACT" "$OUTPUT_PATH"; then
echo "👹 Oops! Failed to unarchive the dashboard files for some reason..."
exit 1
fi

echo "✅ Unarchived the archive file $ARTIFACT, to $OUTPUT_PATH. It's contents are listed below:"
ls -la "$OUTPUT_PATH"

- name: Setup fleek.config.json
run: |
DIST="dist"
BUILD="npm run build && cp -r $DASHBOARD_UNARCHIVED_PATH $DIST"

./scripts/setup-fleek-config \
"$FLEEK_SLUG" \
"$DIST" \
"$BUILD"

- name: Build & deploy
run: |
fleek sites deploy

- name: Clear
run: |
rm .env
19 changes: 19 additions & 0 deletions .github/workflows/fleek-deploy-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# TODO: Once satisfied with staging setup uncomment the following workflow

# name: ⚡️ Deploy Dashboard (Production)

# on:
# workflow_dispatch:
# push:
# branches:
# - main
# # The workflow's dispatched on Release by develop hash
# repository_dispatch:
# types: [Release]

# jobs:
# deploy-to-staging:
# uses: ./.github/workflows/fleek-deploy-common.yml
# with:
# environment: production
# secrets: inherit
17 changes: 17 additions & 0 deletions .github/workflows/fleek-deploy-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: ⚡️ Deploy Dashboard (Staging)

on:
workflow_dispatch:
push:
branches:
- develop
# The workflow's dispatched on Release by develop hash
repository_dispatch:
types: [Release]

jobs:
deploy-to-staging:
uses: ./.github/workflows/fleek-deploy-common.yml
with:
environment: staging
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/release-by-develop-hash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ jobs:
- name: Dispatch Event
env:
PAT: ${{ secrets.GITHUB_TOKEN }}
ENDPOINT: 'https://api.github.com/repos/fleek-platform/website/dispatches'
ENDPOINT: 'https://api.github.com/repos/${{ github.repository }}/dispatches'
EVENT_NAME: 'Release'
run: |
if ! curl -H "Accept: application/vnd.github+json" \
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ fleek.*.config.json

#lock files
pnpm-lock.yaml

# dev
dev_*
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ npm run build

Tweak environment settings (src/settings.json), such as the site URL. Declare the `NODE_ENV` with value `prod` or `production` to switch environment target settings.

Alternatively, you can skip build checkups and build assets only:

```
npm run build:static_assets
```

## 🙈 Preview locally

You can preview the distribution build locally by starting the preview HTTP server:
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "rm -rf dist && npm run check:strict && npm run check:json && astro build && ./scripts/build/copy-video-content-src-to-dist",
"build": "rm -rf dist && npm run check:strict && npm run check:json && npm run build:static_assets",
"build:static_assets": "astro build && ./scripts/build/copy-video-content-src-to-dist && cp ./public/_redirects ./dist",
"preview": "astro preview",
"astro": "astro",
"clean": "rm -rf .astro node_modules/.vite",
Expand Down
1 change: 1 addition & 0 deletions public/_redirects
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dashboard/* /dashboard/index.html 200
67 changes: 67 additions & 0 deletions scripts/download_artifact
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash

ghToken="$1"
orgRepo="$2"
targetArtifactFilename="$3"
outputFilename="$4"

if [[ -z "$1" || -z "$2" || -z "$3" || -z "$4" ]]; then
echo "👹 Oops! Missing arguments, e.g. github token, organisation repository, artifact name, etc"
exit 1
fi

result=$(curl -sL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $ghToken" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/$orgRepo/actions/artifacts")

if [[ -z "$result" ]]; then
echo "👹 Oops! The request for artifacts API has an unexpected response $result"
exit 1
fi

countMatchingFilename=$(echo "$result" | jq "[.artifacts[] | select(.name == \"$targetArtifactFilename\")] | length")

if [[ "$countMatchingFilename" -eq 0 ]]; then
echo "👹 Oops! Didn't find any artifacts of name $targetArtifactFilename"
exit 1
fi

echo "✅ Found $countMatchingFilename artifact matches for name $targetArtifactFilename"

filteredByFilename=$(echo "$result" | jq "[.artifacts[] | select(.name == \"$targetArtifactFilename\")]")

if [[ -z "$filteredByFilename" ]]; then
echo "👹 Oops! Failed to get the latest artifact from response $result"
exit 1
fi

latestArtifact=$(echo "$filteredByFilename" | jq 'sort_by(.created_at) | reverse | .[0]')

if [[ -z "$latestArtifact" ]]; then
echo "👹 Oops! Failed to get the latest artifact from response $result"
exit 1
fi

latestArtifactId=$(echo "$latestArtifact" | jq '.id')
latestArtifactName=$(echo "$latestArtifact" | jq '.name')

if [[ -z "$latestArtifactId" ]]; then
echo "👹 Oops! Failed to get the latest artifact id from response $latestArtifact"
exit 1
fi

echo "✅ Got artifact id $latestArtifactId of name $latestArtifactName"

if ! curl -sL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $ghToken" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/$orgRepo/actions/artifacts/$latestArtifactId/zip" \
--output "$outputFilename"; then
echo "👹 Oops! Failed download the artifact id $latestArtifactId"
exit 1
fi

echo "✅ Downloaded artifact $outputFilename"
31 changes: 31 additions & 0 deletions scripts/setup-ci-dotenv
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

targetEnvPath=".env"
# Using dotenv due to `fleek sites deploy`
# failing to authenticate via the host or declared
# fleek env vars for some reason
doppler secrets download \
--no-file \
--format env > "$targetEnvPath"

# The Fleek CLI supports envVars overrides
# for this reason, we should exclude some vars
# originated from doppler
EXCLUDE_CSV=( "UI__APP_URL" "SDK__GRAPHQL_API_URL" "SDK__AUTH_APPS_URL" "SDK__IPFS__STORAGE_API_URL" "SDK__UPLOAD_PROXY_API_URL" "SITE_SLUG_DOMAIN" )

for item in "${EXCLUDE_CSV[@]}"; do
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' "/^${item}=/d" "$targetEnvPath"
else
sed -i "/^${item}=/d" "$targetEnvPath"
fi
done

for item in "${EXCLUDE_CSV[@]}"; do
if grep -q "^${item}=" "$targetEnvPath"; then
echo "👹 Oops! Failed to exclude $item from $targetEnvPath"
exit 1
fi
done

echo "✅ Completed dot env setup!"
33 changes: 33 additions & 0 deletions scripts/setup-fleek-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

if [[ -z "$1" || -z "$2" || -z "$3" ]]; then
echo "👹 Oops! Missing arguments required for slug, distDir and buildCommand."
exit 1
fi

fleekConfigPath="./fleek.config.json"
temp="$fleekConfigPath.tmp"

if ! jq --arg slug "$1" --arg distDir "$2" --arg buildCommand "$3" '
.sites[0].slug = $slug |
.sites[0].distDir = $distDir |
.sites[0].buildCommand = $buildCommand
' "$fleekConfigPath" > "$temp"; then
echo "👹 Oops! Failed to set $fleekConfigPath for some reason..."
exit 1
fi

if ! mv "$temp" "$fleekConfigPath"; then
echo "👹 Oops! Failed to override the $fleekConfigPath"
exit 1
fi

if ! rm "$temp"; then
echo "⚠️ WARNING: Failed to remove $temp file"
fi

echo "🔍 The $fleekConfigPath content is:"
cat "$fleekConfigPath"
echo

echo "✅ Completed fleek config setup!"
31 changes: 31 additions & 0 deletions scripts/unarchive_dashboard_files
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

if [[ -z "$1" || -z "$2" ]]; then
echo "👹 Oops! Missing arguments. Have you provided a filename and output path?"
exit 1
fi

artifact_filename="$1"
output_path="$2"

if ! unzip -q -o "$artifact_filename" -d "$output_path"; then
echo "👹 Oops! Failed to unzip $artifact_filename"
exit 1
fi

echo "✅ Unziped $artifact_filename"

if ! rm "$artifact_filename"; then
echo "👹 Oops! Failed to delete $artifact_filename"
exit 1
fi

echo "✅ Deleted $artifact_filename"

if ! mkdir -p "$output_path"; then
echo "👹 Oops! Failed to create the output path $output_path"
exit 1
fi

echo "🤖 The file content generated the following file tree..."
tree -L 2 "$output_path"
Loading