Skip to content

Commit

Permalink
feat: support multi instance (#364)
Browse files Browse the repository at this point in the history
* feat: upgrade Node, add Redis caching & WebSocket via redis-pubsub

* fix: optimize `X-Request-Id` generation rules

* ci: add db-migrate image build and push

---------

Co-authored-by: pengap <[email protected]>
  • Loading branch information
Pengap and Pengap authored Feb 19, 2024
1 parent 21f4b25 commit 9b4f9ea
Show file tree
Hide file tree
Showing 83 changed files with 3,407 additions and 3,266 deletions.
2 changes: 1 addition & 1 deletion .github/actions/playwright-install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ runs:
echo "CACHE_KEY=${{ runner.os }}-playwright-cache-${{ inputs.cache-prefix }}-${{ steps.playwright-config.outputs.CURRENT_VERSION }}" >> $GITHUB_OUTPUT
- name: Restore playwright install
uses: actions/cache@v3
uses: actions/cache@v4
id: playwright-cache
with:
path: |
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/pnpm-install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ runs:
- name: ♻️ Restore pnpm cache
id: pnpm-store-cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.pnpm-config.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_WEEK }}-${{ hashFiles('**/pnpm-lock.yaml') }}
Expand Down
8 changes: 4 additions & 4 deletions .github/actions/yarn-nm-install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ runs:
echo "NPM_GLOBAL_CACHE_FOLDER=$(npm config get cache)" >> $GITHUB_OUTPUT
- name: ♻️ Restore yarn cache
uses: actions/cache@v3
uses: actions/cache@v4
id: yarn-download-cache
with:
path: ${{ steps.yarn-config.outputs.CACHE_FOLDER }}
Expand All @@ -89,23 +89,23 @@ runs:
- name: ♻️ Restore node_modules
if: inputs.cache-node-modules == 'true'
id: yarn-nm-cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ inputs.cwd }}/**/node_modules
key: yarn-nm-cache-${{ inputs.cache-prefix }}-${{ runner.os }}-${{ steps.yarn-config.outputs.CURRENT_NODE_VERSION }}-${{ steps.yarn-config.outputs.CURRENT_BRANCH }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }}

- name: ♻️ Restore global npm cache folder
if: inputs.cache-npm-cache == 'true'
id: npm-global-cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.yarn-config.outputs.NPM_GLOBAL_CACHE_FOLDER }}
key: npm-global-cache-${{ inputs.cache-prefix }}-${{ runner.os }}-${{ steps.yarn-config.outputs.CURRENT_NODE_VERSION }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }}

- name: ♻️ Restore yarn install state
if: inputs.cache-install-state == 'true' && inputs.cache-node-modules == 'true'
id: yarn-install-state-cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ inputs.cwd }}/.yarn/ci-cache
key: yarn-install-state-cache-${{ inputs.cache-prefix }}-${{ runner.os }}-${{ steps.yarn-config.outputs.CURRENT_NODE_VERSION }}-${{ steps.yarn-config.outputs.CURRENT_BRANCH }}-${{ hashFiles(format('{0}/yarn.lock', inputs.cwd), format('{0}/.yarnrc.yml', inputs.cwd)) }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-e2e-nextjs-app.yml.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

Expand All @@ -58,7 +58,7 @@ jobs:

# see https://github.com/vercel/next.js/pull/27362
- name: Restore nextjs build nextjs-app from cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
${{ github.workspace }}/apps/nextjs-app/.next/cache
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-e2e-prisma.yml.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-monorepo-integrity.yml.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-nextjs-app.yml.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

Expand All @@ -50,7 +50,7 @@ jobs:

# see https://github.com/vercel/next.js/pull/27362
- name: Restore nextjs build nextjs-app from cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
${{ github.workspace }}/apps/nextjs-app/.next/cache
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci-packages.yml.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
node-version: [20.x]
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -44,15 +44,15 @@ jobs:
fetch-depth: 0

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: 📥 Monorepo install
uses: ./.github/actions/yarn-nm-install

- name: Restore packages cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
${{ github.workspace }}/.cache
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codesee-arch-diagram.yml.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
# CodeSee Maps Go support uses a static binary so there's no setup step required.

- name: Configure Node.js 14
uses: actions/setup-node@v3
uses: actions/setup-node@v4
if: ${{ fromJSON(steps.detect-languages.outputs.languages).javascript }}
with:
node-version: '14'
Expand Down
14 changes: 12 additions & 2 deletions .github/workflows/docker-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:
jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -47,7 +46,18 @@ jobs:
username: ${{ secrets.ALI_DOCKER_USERNAME }}
password: ${{ secrets.ALI_DOCKER_PASSWORD }}

- name: Build and push
- name: Build and push(Dockerfile.db-migrate)
uses: docker/build-push-action@v5
with:
context: .
file: dockers/teable/Dockerfile.db-migrate
push: true
tags: ${{ steps.meta.outputs.tags }}
# platforms: linux/amd64,linux/arm64
cache-from: type=registry,ref=ghcr.io/teableio/teable-db-migrate:buildcache
cache-to: type=registry,ref=ghcr.io/teableio/teable-db-migrate:buildcache,mode=max

- name: Build and push(Dockerfile)
uses: docker/build-push-action@v5
with:
context: .
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [18.x]
node-version: [20.x]
database-type: [postgres, sqlite]
env:
CI: 1
Expand All @@ -24,7 +24,7 @@ jobs:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ jobs:

strategy:
matrix:
node-version: [18.x]
node-version: [20.x]

steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-or-version-pr.yml.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
fetch-depth: 0

- name: Use Node.js 16.x
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 16.x

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ jobs:

strategy:
matrix:
node-version: [18.x]
node-version: [20.x]

steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.19.0
v20.9.0
35 changes: 30 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
SHELL := /usr/bin/env bash

# define standard colors
ifneq (,$(findstring xterm,${TERM}))
BLACK := $(shell tput -Txterm setaf 0)
RED := $(shell tput -Txterm setaf 1)
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
LIGHTPURPLE := $(shell tput -Txterm setaf 4)
PURPLE := $(shell tput -Txterm setaf 5)
BLUE := $(shell tput -Txterm setaf 6)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)
else
BLACK := ""
RED := ""
GREEN := ""
YELLOW := ""
LIGHTPURPLE := ""
PURPLE := ""
BLUE := ""
WHITE := ""
RESET := ""
endif

ENV_PATH ?= apps/nextjs-app

DOCKER_COMPOSE ?= docker compose
Expand Down Expand Up @@ -108,12 +131,14 @@ endef

docker.create.network:
ifneq ($(NETWORK_MODE),host)
docker network inspect $(NETWORK_MODE) &> /dev/null || ([ $$? -ne 0 ] && docker network create $(NETWORK_MODE))
@docker network inspect $(NETWORK_MODE) &> /dev/null || ([ $$? -ne 0 ] && docker network create $(NETWORK_MODE))
$(info ${GREEN}network $(NETWORK_MODE) create success${RESET})
endif

docker.rm.network:
ifneq ($(NETWORK_MODE),host)
docker network inspect $(NETWORK_MODE) &> /dev/null && ([ $$? -eq 0 ] && docker network rm $(NETWORK_MODE)) || true
@docker network inspect $(NETWORK_MODE) &> /dev/null && ([ $$? -eq 0 ] && docker network rm $(NETWORK_MODE)) || true
$(warning ${GREEN}network $(NETWORK_MODE) removed${RESET})
endif

docker.build:
Expand All @@ -123,7 +148,7 @@ docker.run: docker.create.network
$(DOCKER_COMPOSE_ARGS) $(DOCKER_COMPOSE) $(COMPOSE_FILE_ARGS) run -T --no-deps --rm $(SERVICE) $(SERVICE_ARGS)

docker.up: docker.create.network
$(DOCKER_COMPOSE_ARGS) $(DOCKER_COMPOSE) $(COMPOSE_FILE_ARGS) up --no-recreate -d $(SERVICE)
@$(DOCKER_COMPOSE_ARGS) $(DOCKER_COMPOSE) $(COMPOSE_FILE_ARGS) up --no-recreate -d $(SERVICE)

docker.down: docker.rm.network
$(DOCKER_COMPOSE_ARGS) $(DOCKER_COMPOSE) $(COMPOSE_FILE_ARGS) down
Expand Down Expand Up @@ -154,12 +179,12 @@ docker.await: ## max timeout of 300
sleep 1; \
time=$$(expr $$time + 1); \
if [ $${time} -gt $(TIMEOUT) ]; then \
echo "Timeout reached waiting for $${i} to become healthy"; \
echo "${YELLOW}Timeout reached waiting for $${i} to become healthy${RESET}"; \
docker logs $${i}; \
exit 1; \
fi; \
done; \
echo "Service $${i} is healthy"; \
echo "${GREEN}Service $${i} is healthy${RESET}"; \
done

docker.status:
Expand Down
Loading

0 comments on commit 9b4f9ea

Please sign in to comment.