Skip to content

Commit

Permalink
Add server deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Sep 11, 2024
1 parent ce01ea9 commit fc7509a
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Initialize Node.js
uses: ./.github/actions/init-node
- name: Run tests
run: pnpm run -r --include-workspace-root '/^test:(?!markdown\b|proxy-coverage\b|loaders\b)/'
run: pnpm run -r --include-workspace-root '/^test:(?!markdown\b|proxy-coverage\b|server-coverage\b|loaders\b)/'
env:
FORCE_COLOR: 1
STAGING: 1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/preview-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ jobs:
projectId: slowreader-421120
region: europe-west1
folder: ./server/
registry: staging/web
service: staging-web
registry: staging/server
service: staging-server
tag: preview-${{ env.PR_NUMBER }}
env: ASSETS=1,DATABASE_URL=memory://,PROXY_ORIGIN=^https:\/\/preview-\d+---staging-web-jfj4bxwwxq-ew\.a\.run\.app$
- name: Update deployment status
Expand Down
96 changes: 96 additions & 0 deletions .github/workflows/server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Server
on:
push:
branches:
- main
paths:
- 'server/*'
- 'server/**/*'
- '!server/*.md'
- 'pnpm-lock.yaml'
- '.github/workflows/server.yml'
- '.github/actions/init-node/action.yml'
- '.github/actions/deploy/action.yml'
pull_request:
paths:
- 'server/*'
- 'server/**/*'
- '!server/*.md'
- 'pnpm-lock.yaml'
- '.github/workflows/server.yml'
- '.github/actions/init-node/action.yml'
- '.github/actions/deploy/action.yml'
jobs:
test:
name: Server Test
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Initialize Node.js
uses: ./.github/actions/init-node
- name: Run tests
run: cd server && pnpm test
- name: Test Docker build
if: github.ref != 'refs/heads/main'
run: cd server && node --run build && docker build .
build:
name: Server Build
if: github.ref == 'refs/heads/main'
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version-file: .node-version
# We don’t use cache for supply chain security
- name: Install dependencies
run: pnpm install -F server -F proxy --production --ignore-scripts
- name: Build server
run: cd server && node --run build:server
- name: Upload server build
uses: actions/upload-artifact@v4
with:
name: server-build-${{ github.sha }}
path: |
server/dist/
retention-days: 1
staging:
name: Server Staging Deploy
needs:
- test
- build
if: github.ref == 'refs/heads/main'
permissions:
contents: read
id-token: write
concurrency:
group: staging-server
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Download web assets from test step
uses: actions/download-artifact@v4
with:
name: server-build-${{ github.sha }}
path: server/dist/
- name: Create empty assets
run: mkdir server/web
- name: Deploy to Google Cloud
uses: ./.github/actions/deploy
with:
projectId: slowreader-421120
region: europe-west1
folder: ./server/
registry: staging/server
service: staging-server
env: DATABASE_URL=memory://
6 changes: 4 additions & 2 deletions scripts/prepare-google-cloud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ WORKFLOWS=(
".github/actions/deploy/action.yml"
".github/workflows/main.yml"
".github/workflows/proxy.yml"
".github/workflows/server.yml"
".github/workflows/preview-deploy.yml"
)

Expand Down Expand Up @@ -84,5 +85,6 @@ echo -e "3. Click on \033[1mManage Custom Domains\033[0m"
echo -e "4. Click on \033[1mAdd Mapping\033[0m"
echo -e "5. Add \033[1mdev.slowreader.app\033[0m tostaging-web"
echo -e "5. Add \033[1mdev-proxy.slowreader.app\033[0m to staging-proxy"
echo -e "6. Check Cloud Run service internal URL like \033[1*.run.app\033[0m"
echo -e "7. Set it domain in \033[1m.github/workflows/preview-deploy.yml\033[0m"
echo -e "6. Add \033[1mdev-server.slowreader.app\033[0m to staging-server"
echo -e "7. Check Cloud Run service internal URL like \033[1*.run.app\033[0m"
echo -e "8. Set it domain in \033[1m.github/workflows/preview-deploy.yml\033[0m"
4 changes: 2 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"build": "node --run clean:build && pnpm run /^build:/",
"production": "node --run build && ./scripts/run-image.sh",
"build:server": "pnpm --filter server --prod deploy dist",
"build:assets": "mkdir -p web/ && cp -r ../web/dist web/ && cp ../web/routes.regexp web/",
"test:coverage": "c8 bnt",
"build:assets": "mkdir -p web/ && cp -fr ../web/dist web/ && cp ../web/routes.regexp web/",
"test:server-coverage": "c8 bnt",
"clean:coverage": "rm -rf coverage",
"clean:build": "rm -rf dist/ web/"
},
Expand Down

0 comments on commit fc7509a

Please sign in to comment.