feat(deploy): add Docker image, static server, and CI workflows
One build artifact serves both a self-hosted subpath deploy and GitHub Pages. CI runs the tests, typechecks, builds, and smoke-tests the image. server.ts's traversal guard uses a separator-aware check (resolved === root || resolved.startsWith(root + path.sep)) instead of a bare startsWith(root), which would let a request resolving to "/app/dist-evil/x" pass a check against root "/app/dist".
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: oven-sh/setup-bun@v2
|
||||
with:
|
||||
bun-version: latest
|
||||
- run: bun install --frozen-lockfile
|
||||
- run: bun test
|
||||
- run: bunx tsc --noEmit
|
||||
- run: bun run build
|
||||
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: docker build -t budget2 .
|
||||
- name: Serve the image and check it responds
|
||||
run: |
|
||||
docker run -d --rm -p 3000:3000 --name budget2 budget2
|
||||
for i in $(seq 1 30); do
|
||||
if curl -fsS http://localhost:3000/ > /dev/null; then break; fi
|
||||
sleep 1
|
||||
done
|
||||
curl -fsS http://localhost:3000/ | grep -q "Budget"
|
||||
curl -fsS http://localhost:3000/sw.js > /dev/null
|
||||
curl -fsS http://localhost:3000/manifest.webmanifest > /dev/null
|
||||
docker stop budget2
|
||||
@@ -0,0 +1,46 @@
|
||||
name: Deploy to GitHub Pages
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pages: write
|
||||
id-token: write
|
||||
|
||||
concurrency:
|
||||
group: pages
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: oven-sh/setup-bun@v2
|
||||
with:
|
||||
bun-version: latest
|
||||
- run: bun install --frozen-lockfile
|
||||
- run: bun test
|
||||
- name: Build for the Pages subpath
|
||||
env:
|
||||
BUN_PUBLIC_BASE_PATH: /${{ github.event.repository.name }}/
|
||||
BUILD_VERSION: ${{ github.sha }}
|
||||
run: bun run build
|
||||
- name: Stop Pages from running the output through Jekyll
|
||||
run: touch dist/.nojekyll
|
||||
- uses: actions/upload-pages-artifact@v3
|
||||
with:
|
||||
path: dist
|
||||
|
||||
deploy:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
environment:
|
||||
name: github-pages
|
||||
url: ${{ steps.deployment.outputs.page_url }}
|
||||
steps:
|
||||
- id: deployment
|
||||
uses: actions/deploy-pages@v4
|
||||
Reference in New Issue
Block a user