Skip to content

Commit

Permalink
sync upstream master
Browse files Browse the repository at this point in the history
  • Loading branch information
YiniXu9506 committed Dec 28, 2022
2 parents 6f68cd5 + 5741300 commit b00315e
Show file tree
Hide file tree
Showing 74 changed files with 5,944 additions and 756 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "1.13.5"
go-version: "1.18"
- name: Load go module cache
uses: actions/cache@v3
with:
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
cache-dependency-path: "ui/pnpm-lock.yaml"
- uses: actions/setup-go@v3
with:
go-version: "1.13.5"
go-version: "1.18"
- name: Load go module cache
uses: actions/cache@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/manual-create-pd-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
ref: ${{ matrix.branch }}
- uses: actions/setup-go@v3
with:
go-version: "1.18.1"
go-version: "1.18"
- name: Load go module cache
uses: actions/cache@v3
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
cache-dependency-path: 'ui/pnpm-lock.yaml'
- uses: actions/setup-go@v3
with:
go-version: "1.13.5"
go-version: "1.18"
- name: Load go module cache
uses: actions/cache@v3
with:
Expand Down Expand Up @@ -102,7 +102,7 @@ jobs:
ref: ${{ matrix.branch }}
- uses: actions/setup-go@v3
with:
go-version: "1.18.1"
go-version: "1.18"
- name: Load go module cache
uses: actions/cache@v3
with:
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/test-docker-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Test Docker Image
on:
push:
branches:
- master
pull_request:
branches:
- master
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true
jobs:
test-cross-platform-image:
runs-on: ubuntu-latest
strategy:
fail-fast: true
steps:
- name: Checkout code
uses: actions/checkout@v3
- # Add support for more platforms with QEMU (optional)
# https://github.com/docker/setup-qemu-action
name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Read VERSION file
id: getversion
run: echo "::set-output name=version::$(grep -v '^\#' ./release-version)"
- name: Build
uses: docker/build-push-action@v3
with:
context: .
# Currently github action runner only supports linux/amd64, it take a lot of time to build multi-arch image.
# So we only build amd64 image for now.
platforms: linux/amd64
push: false
tags: pingcap/tidb-dashboard:${{ steps.getversion.outputs.version }}
no-cache: false
pull: false
cache-from: type=gha
cache-to: type=gha,mode=max
22 changes: 8 additions & 14 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "1.13.5"
go-version: "1.18"
- name: Load go module cache
uses: actions/cache@v3
with:
Expand All @@ -37,7 +37,7 @@ jobs:
with:
files: ./coverage/unit_test.txt
fail_ci_if_error: true
flags: be_unit_test
flags: backend_ut
verbose: true

backend_integration:
Expand All @@ -52,7 +52,7 @@ jobs:
uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "1.13.5"
go-version: "1.18"
- name: Load go module cache
uses: actions/cache@v3
with:
Expand All @@ -75,7 +75,7 @@ jobs:
with:
files: ./coverage/integration_${{ matrix.tidb_version }}.txt
fail_ci_if_error: true
flags: be_integration_test_${{ matrix.tidb_version }}
flags: backend_integration
verbose: true

e2e_test:
Expand All @@ -87,23 +87,17 @@ jobs:
# test latest features and compatibility of lower version
include:
- feature_version: 6.0.0 # You must ensure feature_version and tidb_version is matching!
tidb_version: nightly
without_ngm: false
- feature_version: 6.0.0
tidb_version: nightly
without_ngm: true
- feature_version: 6.0.0
tidb_version: ^6.0
without_ngm: false
- feature_version: 6.0.0
tidb_version: ^6.0
without_ngm: true
- feature_version: 5.4.0
tidb_version: ^5.4
without_ngm: false
without_ngm: true
- feature_version: 5.0.0
tidb_version: ^5.0
without_ngm: false
without_ngm: true
name: E2E - TiDB@${{ matrix.tidb_version }}${{ !matrix.without_ngm && '+ngm' || '' }}
steps:
- name: Checkout code
Expand All @@ -129,7 +123,7 @@ jobs:
${{ runner.os }}-cypress-
- uses: actions/setup-go@v3
with:
go-version: "1.13.5"
go-version: "1.18"
- name: Load go module cache
uses: actions/cache@v3
with:
Expand Down Expand Up @@ -192,6 +186,6 @@ jobs:
uses: codecov/codecov-action@v2
with:
files: ./ui/packages/tidb-dashboard-for-op/.nyc_output/out.json
fail_ci_if_error: true
fail_ci_if_error: false
flags: e2e_test
verbose: true
2 changes: 1 addition & 1 deletion .github/workflows/upload-e2e-snapshots.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
cache-dependency-path: 'ui/pnpm-lock.yaml'
- uses: actions/setup-go@v3
with:
go-version: "1.13.5"
go-version: "1.18"
- name: Load go module cache
uses: actions/cache@v3
with:
Expand Down
56 changes: 53 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ The followings are required for developing TiDB Dashboard:
cd tidb-dashboard
```

1. Build and run TiDB Dashboard back-end server:
2. Build and run TiDB Dashboard back-end server:

```bash
# In tidb-dashboard directory:
make dev && make run
```

1. Build and run front-end server in a new terminal:
3. Build and run front-end server in a new terminal:

```bash
# In tidb-dashboard directory:
Expand All @@ -74,7 +74,19 @@ The followings are required for developing TiDB Dashboard:
pnpm dev
```

1. That's it! You can access TiDB Dashboard now: http://127.0.0.1:3001
4. That's it! You can access TiDB Dashboard now: [http://127.0.0.1:3001](http://127.0.0.1:3001)

5. (Optional) Package frontend and backend into a single binary:

```bash
# In tidb-dashboard directory:
make package

# Run the binary without separate frontend server:
make run
```

You can access TiDB Dashboard now: [http://127.0.0.1:12333/dashboard](http://127.0.0.1:12333/dashboard)

### Step 4. Run E2E Tests (optional)

Expand All @@ -100,6 +112,44 @@ see all TiDB Dashboard API endpoints and specifications, or even send API reques

Swagger UI is available at http://localhost:12333/dashboard/api/swagger after the above Step 3 is finished.

### Build and run docker image locally

If you want to develop docker image locally 🤔.

1. Ensure the Docker Buildx is installed on your local machine.

> Docker Buildx is included in Docker Desktop for Windows, macOS, and Linux.
> Docker Linux packages also include Docker Buildx when installed using the DEB or RPM packages.
2. Build the docker image.

```bash
# On repository root directory (only build locally, no push remote), run:
make docker-build-image-locally-amd64

# Or, if you want to build the image for arm64 platform (only build locally, no push remote), run:
make docker-build-image-locally-arm64

# Or, if you want to build cross-platform image and push it to your dev docker registry, run:
REPOSITORY=your-tidb-dashboard-repository make docker-build-and-push-image

# Finally, if you update npm modules or go modules, and want to disable docker layer cache to force rebuild, set NO_CACHE="--pull --no-cache" before make command. For example:
NO_CACHE="--pull --no-cache" make docker-build-image-locally-amd64
```

3. Run newly build image with docker-compose.

> Please make sure that `tiup playground` is not running on the background.
```bash
# On repository root directory, run:
docker-compose up
```

4. Access TiDB Dashboard at [http://localhost:12333/dashboard](http://localhost:12333/dashboard).

> Dashboard in PD can be accessed at [http://localhost:2379/dashboard](http://localhost:2379/dashboard).

## Contribution flow

This is a rough outline of what a contributor's workflow looks like:
Expand Down
41 changes: 41 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM golang:1.18-alpine3.16 as builder

RUN apk add --no-cache \
make \
git \
bash \
curl \
findutils \
gcc \
libc-dev \
nodejs \
npm \
openjdk11

RUN npm install -g pnpm

RUN mkdir -p /go/src/github.com/pingcap/tidb-dashboard/ui
WORKDIR /go/src/github.com/pingcap/tidb-dashboard

# Cache go module dependencies.
COPY go.mod .
COPY go.sum .
RUN GO111MODULE=on go mod download

# Cache npm dependencies.
WORKDIR /go/src/github.com/pingcap/tidb-dashboard/ui
COPY ui/pnpm-lock.yaml .
RUN pnpm fetch

# Build.
WORKDIR /go/src/github.com/pingcap/tidb-dashboard
COPY . .
RUN make package PNPM_INSTALL_TAGS=--offline

FROM alpine:3.16

COPY --from=builder /go/src/github.com/pingcap/tidb-dashboard/bin/tidb-dashboard /tidb-dashboard

EXPOSE 12333

ENTRYPOINT ["/tidb-dashboard"]
48 changes: 42 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ DASHBOARD_PKG := github.com/pingcap/tidb-dashboard

BUILD_TAGS ?=

PNPM_INSTALL_TAGS ?=

LDFLAGS ?=

FEATURE_VERSION ?= 6.2.0
Expand All @@ -10,18 +12,27 @@ WITHOUT_NGM ?= false

E2E_SPEC ?=

ifeq ($(UI),1)
BUILD_TAGS += ui_server
endif
UI ?=

RELEASE_VERSION := $(shell grep -v '^\#' ./release-version)

LDFLAGS += -X "$(DASHBOARD_PKG)/pkg/utils/version.InternalVersion=$(shell grep -v '^\#' ./release-version)"
LDFLAGS += -X "$(DASHBOARD_PKG)/pkg/utils/version.InternalVersion=$(RELEASE_VERSION)"
LDFLAGS += -X "$(DASHBOARD_PKG)/pkg/utils/version.Standalone=Yes"
LDFLAGS += -X "$(DASHBOARD_PKG)/pkg/utils/version.PDVersion=N/A"
LDFLAGS += -X "$(DASHBOARD_PKG)/pkg/utils/version.BuildTime=$(shell date -u '+%Y-%m-%d %I:%M:%S')"
LDFLAGS += -X "$(DASHBOARD_PKG)/pkg/utils/version.BuildGitHash=$(shell git rev-parse HEAD)"

TIDB_VERSION ?= latest

# Docker build variables.
REPOSITORY ?= pingcap/tidb-dashboard
IMAGE ?= $(REPOSITORY):$(RELEASE_VERSION)
AMD64 := linux/amd64
ARM64 := linux/arm64
PLATFORMS := $(AMD64),$(ARM64)
# If you want to build with no cache (after update go module, npm module, etc.), set "NO_CACHE=--pull --no-cache".
NO_CACHE ?=

default: server

.PHONY: clean
Expand Down Expand Up @@ -92,7 +103,7 @@ dev: lint default
.PHONY: ui_deps
ui_deps: install_tools
cd ui &&\
pnpm i
pnpm i ${PNPM_INSTALL_TAGS}

.PHONY: ui
ui: ui_deps
Expand All @@ -106,12 +117,37 @@ go_generate:
go generate -x ./...

.PHONY: server
ifeq ($(UI),1)
BUILD_TAGS += ui_server
endif
server: install_tools go_generate
ifeq ($(UI),1)
scripts/embed_ui_assets.sh
endif
go build -o bin/tidb-dashboard -ldflags '$(LDFLAGS)' -tags "${BUILD_TAGS}" cmd/tidb-dashboard/main.go

.PHONY: run
.PHONY: embed_ui_assets
embed_ui_assets: ui
scripts/embed_ui_assets.sh

.PHONY: package # Build frontend and backend server, and then packages them into a single binary.
package: BUILD_TAGS += ui_server
package: embed_ui_assets server

.PHONY: docker-build-and-push-image # For locally dev, set IMAGE to your dev docker registry.
docker-build-and-push-image: clean
docker buildx build ${NO_CACHE} --push -t $(IMAGE) --platform $(PLATFORMS) .

.PHONY: docker-build-image-locally-amd64
docker-build-image-locally-amd64: clean
docker buildx build ${NO_CACHE} --load -t $(IMAGE) --platform $(AMD64) .
docker run --rm $(IMAGE) -v

.PHONY: docker-build-image-locally-arm64
docker-build-image-locally-arm64: clean
docker buildx build ${NO_CACHE} --load -t $(IMAGE) --platform $(ARM64) .
docker run --rm $(IMAGE) -v

.PHONY: run # please ensure that tiup playground is running in the background.
run:
bin/tidb-dashboard --debug --experimental --feature-version "$(FEATURE_VERSION)" --host 0.0.0.0
Loading

0 comments on commit b00315e

Please sign in to comment.