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 7 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
36 changes: 36 additions & 0 deletions .github/workflows/test-docker-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Test Docker Image
on:
push:
branches:
- master
pull_request:
branches:
- master
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true
jobs:
test-amd64-image:
runs-on: ubuntu-latest
strategy:
fail-fast: true
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.18
- name: Checkout code
uses: actions/checkout@v3
- name: Make
run: make docker-image-amd64
test-arm64-image:
runs-on: ubuntu-latest
strategy:
fail-fast: true
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.18
- name: Checkout code
uses: actions/checkout@v3
- name: Make
run: make docker-image-arm64
16 changes: 8 additions & 8 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,24 @@ jobs:
matrix:
# 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 # You must ensure feature_version and tidb_version is matching!
# tidb_version: nightly
# without_ngm: true
- 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: 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
6 changes: 3 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,7 @@ 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

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

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"]
45 changes: 36 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,24 @@ 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.
IMAGE ?= pingcap/tidb-dashboard:$(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 +100,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 +115,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-image # For locally dev, set IMAGE to your dev docker registry.
docker-image: clean
docker buildx build ${NO_CACHE} --push -t $(IMAGE) --platform $(PLATFORMS) .

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

.PHONY: docker-image-arm64
docker-image-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