Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker image support and misc. improvements #1439

Merged
merged 20 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 3 additions & 9 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 Down Expand Up @@ -174,7 +168,7 @@ jobs:
head -n 3 /home/runner/.tiup/data/$DATA_PATH/pd-0/pd.log
- name: Build and run backend in the background
run: |
make
make package
make run &
env:
UI: 1
SabaPing marked this conversation as resolved.
Show resolved Hide resolved
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:
baurine marked this conversation as resolved.
Show resolved Hide resolved
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

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](http://127.0.0.1:3001)
SabaPing marked this conversation as resolved.
Show resolved Hide resolved

### 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🤔.

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
SabaPing marked this conversation as resolved.
Show resolved Hide resolved

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"]
46 changes: 37 additions & 9 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,25 @@ WITHOUT_NGM ?= false

E2E_SPEC ?=

ifeq ($(UI),1)
BUILD_TAGS += ui_server
endif
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 +101,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 @@ -107,11 +116,30 @@ go_generate:

.PHONY: server
server: install_tools go_generate
ifeq ($(UI),1)
scripts/embed_ui_assets.sh
shhdgit marked this conversation as resolved.
Show resolved Hide resolved
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
12 changes: 6 additions & 6 deletions cmd/tidb-dashboard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ func NewCLIConfig() *DashboardCLIConfig {

showVersion := flag.BoolP("version", "v", false, "print version information and exit")

clusterCaPath := flag.String("cluster-ca", "", "path of file that contains list of trusted SSL CAs")
clusterCertPath := flag.String("cluster-cert", "", "path of file that contains X509 certificate in PEM format")
clusterKeyPath := flag.String("cluster-key", "", "path of file that contains X509 key in PEM format")
clusterCaPath := flag.String("cluster-ca", "", "(TLS between components of the TiDB cluster) path of file that contains list of trusted SSL CAs")
clusterCertPath := flag.String("cluster-cert", "", "(TLS between components of the TiDB cluster) path of file that contains X509 certificate in PEM format")
clusterKeyPath := flag.String("cluster-key", "", "(TLS between components of the TiDB cluster) path of file that contains X509 key in PEM format")

tidbCaPath := flag.String("tidb-ca", "", "path of file that contains list of trusted SSL CAs")
tidbCertPath := flag.String("tidb-cert", "", "path of file that contains X509 certificate in PEM format")
tidbKeyPath := flag.String("tidb-key", "", "path of file that contains X509 key in PEM format")
tidbCaPath := flag.String("tidb-ca", "", "(TLS for MySQL client) path of file that contains list of trusted SSL CAs")
tidbCertPath := flag.String("tidb-cert", "", "(TLS for MySQL client) path of file that contains X509 certificate in PEM format")
tidbKeyPath := flag.String("tidb-key", "", "(TLS for MySQL client) path of file that contains X509 key in PEM format")

// debug for keyvisual,hide help information
flag.Int64Var(&cfg.KVFileStartTime, "keyviz-file-start", 0, "(debug) start time for file range in file mode")
Expand Down
84 changes: 84 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
version: '2'

services:
tidb-dashboard:
image: pingcap/tidb-dashboard:nightly
ports:
- "12333:12333"
command:
- --pd=http://pd:2379
- --debug
- --experimental
- --feature-version=6.2.0
SabaPing marked this conversation as resolved.
Show resolved Hide resolved
- --host=0.0.0.0
depends_on:
- "pd"
restart: on-failure
pd:
image: pingcap/pd:v6.3.0
ports:
- "2379:2379"
command:
- --name=pd
- --client-urls=http://0.0.0.0:2379
- --peer-urls=http://0.0.0.0:2380
- --advertise-client-urls=http://pd:2379
- --advertise-peer-urls=http://pd:2380
- --initial-cluster=pd=http://pd:2380
restart: on-failure
tikv:
image: pingcap/tikv:v6.3.0
ports:
- "20180:20180"
command:
- --addr=0.0.0.0:20160
- --advertise-addr=tikv:20160
- --status-addr=0.0.0.0:20180
- --pd=pd:2379
depends_on:
- "pd"
restart: on-failure
tidb:
image: pingcap/tidb:v6.3.0
ports:
- "4000:4000"
- "10080:10080"
command:
- --host=0.0.0.0
- --advertise-address=tidb
- --store=tikv
- --path=pd:2379
depends_on:
- "tikv"
restart: on-failure
tiflash:
image: pingcap/tiflash:v6.3.0
volumes:
- ./tiflash.toml:/tiflash.toml:ro
ports:
- "9000:9000"
- "8123:8123"
- "8234:8234"
- "3930:3930"
- "20170:20170"
- "20292:20292"
command:
- --config=/tiflash.toml
depends_on:
- "tikv"
- "tidb"
restart: on-failure
error-metric-trigger:
image: mariadb:10.6.5
command:
- mysql
- -uroot
- -htidb
- -P4000
- -e
- "select * from foo.bar;"
depends_on:
- "tikv"
- "tidb"
- "tiflash"
restart: on-failure