Skip to content

Commit 1420b3c

Browse files
committed
feat: Serve files with fastify static
This will accomplish two things for us: 1. We only need to restart when we change the fastify/static version 2. Fastify/static will cache things for us better https://harperdb.atlassian.net/browse/STUDIO-423
1 parent 54a13d4 commit 1420b3c

File tree

10 files changed

+5294
-227
lines changed

10 files changed

+5294
-227
lines changed

.github/workflows/deploy-dev.yaml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,14 @@ jobs:
3434
run: pnpm lint
3535
- name: Determine version tag for build
3636
run: |
37-
VERSION_TAG="v${GITHUB_SHA:0:7}"
37+
VERSION_TAG="SHA-${GITHUB_SHA:0:7}"
3838
echo "VITE_STUDIO_VERSION=$VERSION_TAG" >> $GITHUB_ENV
3939
- name: Build dev
4040
run: pnpm build:dev
41-
- name: Install HarperDB
42-
run: npm install -g [email protected]
4341
- name: Deploy to dev
4442
run: |
4543
mkdir deploy
46-
cp config.yaml deploy/
4744
mv web deploy/
45+
cp -R deploy-template/* deploy/
4846
cd deploy
49-
echo "{}" > package.json
50-
CLI_TARGET_USERNAME=${{ secrets.CLI_TARGET_USERNAME_DEV }} CLI_TARGET_PASSWORD='${{ secrets.HARPERDB_CLI_TARGET_PASSWORD_DEV }}' harperdb deploy project='hdbms' target='${{ secrets.CLI_DEPLOY_TARGET_DEV }}' restart=true
47+
CLI_TARGET_USERNAME=${{ secrets.CLI_TARGET_USERNAME_DEV }} CLI_TARGET_PASSWORD='${{ secrets.HARPERDB_CLI_TARGET_PASSWORD_DEV }}' pnpm harperdb deploy_component project=hdbms target='${{ secrets.CLI_DEPLOY_TARGET_DEV }}' restart=rolling

.github/workflows/deploy-prod.yaml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,14 @@ jobs:
3131
run: pnpm test
3232
- name: Run lint
3333
run: pnpm lint
34-
- name: Determine version tag for build
35-
run: |
36-
VERSION_TAG=$(git tag --points-at HEAD | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+' | sort -V | tail -n1)
37-
if [ -z "$VERSION_TAG" ]; then
38-
VERSION_TAG="v0.0.0+${GITHUB_SHA:0:7}"
39-
fi
40-
echo "VITE_STUDIO_VERSION=$VERSION_TAG" >> $GITHUB_ENV
4134
- name: Build prod
4235
run: pnpm build:prod
4336
- name: Install HarperDB
4437
run: npm install -g [email protected]
4538
- name: Deploy to prod
4639
run: |
4740
mkdir deploy
48-
cp config.yaml deploy/
4941
mv web deploy/
42+
cp -R deploy-template/* deploy/
5043
cd deploy
51-
echo "{}" > package.json
52-
CLI_TARGET_USERNAME=${{ secrets.CLI_TARGET_USERNAME_PROD }} CLI_TARGET_PASSWORD='${{ secrets.HARPERDB_CLI_TARGET_PASSWORD_PROD }}' harperdb deploy project='hdbms' target='${{ secrets.CLI_DEPLOY_TARGET_PROD }}' restart=true
44+
CLI_TARGET_USERNAME=${{ secrets.CLI_TARGET_USERNAME_PROD }} CLI_TARGET_PASSWORD='${{ secrets.HARPERDB_CLI_TARGET_PASSWORD_PROD }}' pnpm harperdb deploy_component project=hdbms target='${{ secrets.CLI_DEPLOY_TARGET_PROD }}' restart=rolling

.github/workflows/deploy-stage.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ jobs:
6262
if: ${{ github.event_name == 'push' }}
6363
run: |
6464
mkdir deploy
65-
cp config.yaml deploy/
6665
mv web deploy/
66+
cp -R deploy-template/* deploy/
6767
cd deploy
68-
echo "{}" > package.json
69-
CLI_TARGET_USERNAME=${{ secrets.CLI_TARGET_USERNAME }} CLI_TARGET_PASSWORD='${{ secrets.HARPERDB_CLI_TARGET_PASSWORD }}' harperdb deploy project='hdbms' target='${{ secrets.CLI_DEPLOY_TARGET }}' restart=true
68+
CLI_TARGET_USERNAME=${{ secrets.CLI_TARGET_USERNAME }} CLI_TARGET_PASSWORD='${{ secrets.HARPERDB_CLI_TARGET_PASSWORD }}' pnpm harperdb deploy_component project=hdbms target='${{ secrets.CLI_DEPLOY_TARGET }}' restart=rolling

config.yaml

Lines changed: 0 additions & 4 deletions
This file was deleted.

deploy-template/config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fastifyRoutes:
2+
files: fastify/*.js

deploy-template/fastify/static.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import fastifyStatic from '@fastify/static';
2+
import { join } from 'path';
3+
4+
export default async (fastify, { hdbCore, logger }) => {
5+
fastify.register(fastifyStatic, {
6+
root: join(import.meta.dirname, '../web'),
7+
maxAge: '30d',
8+
immutable: true,
9+
});
10+
11+
fastify.get('/', function(req, reply) {
12+
reply.sendFile('index.html', { maxAge: '1m', immutable: false });
13+
});
14+
};

deploy-template/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"@fastify/static": "^7.0.4"
4+
}
5+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
"eslint-plugin-react-hooks": "^5.0.0",
149149
"eslint-plugin-react-refresh": "^0.4.18",
150150
"globals": "^16.0.0",
151+
"harperdb": "4.7.0-alpha.6",
151152
"husky": "^9.1.7",
152153
"semantic-release": "^24.1.0",
153154
"typescript": "~5.9.0",

0 commit comments

Comments
 (0)