From ec947bdcff6d579354d6b1d6bf074e0288588f45 Mon Sep 17 00:00:00 2001
From: longfangsong <longfangsong@icloud.com>
Date: Mon, 21 Feb 2022 17:43:15 +0800
Subject: [PATCH] Add docker building toolchain

Signed-off-by: longfangsong <longfangsong@icloud.com>
---
 Dockerfile |  9 +++++++++
 README.md  | 28 +++++++++++++++++++++++++---
 2 files changed, 34 insertions(+), 3 deletions(-)
 create mode 100644 Dockerfile

diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 000000000..43fb9b2ed
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,9 @@
+FROM rust
+WORKDIR /usr/src/tipb-build
+RUN apt update && apt install unzip golang cmake -y
+RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v3.5.1/protoc-3.5.1-linux-x86_64.zip
+RUN unzip protoc-3.5.1-linux-x86_64.zip
+ENV PATH="/usr/src/tipb-build/bin:/root/go/bin:${PATH}"
+WORKDIR /tipb
+ENTRYPOINT ["/usr/bin/make"]
+CMD ["all"]
diff --git a/README.md b/README.md
index de9f88c4a..e56e3e865 100644
--- a/README.md
+++ b/README.md
@@ -2,16 +2,38 @@
 
 TiDB protobuf files
 
-## Requirements
+## Build with local toolchain
 
 ### Install [google/protobuf](https://github.com/google/protobuf)
 
 We use `protoc` 3.5.1, to download: [protobuf/releases/tag/v3.5.1](https://github.com/google/protobuf/releases/tag/v3.5.1)
 
-## Generate the Go and Rust codes
+### Generate the Go and Rust codes
 
 ```sh
 make
 ```
 
-NOTE: Do not forget to update the dependent projects!
+## Build with docker
+
+### Build the docker image
+
+```sh
+docker build . -t tipb-builder
+```
+
+### Generate codes
+
+Basically just use the docker image instead of `make`:
+
+```sh
+# Generate All codes
+docker run -v $(pwd):/tipb tipb-builder 
+# Generate Go codes only
+docker run -v $(pwd):/tipb tipb-builder go
+# Generate Rust codes only
+docker run -v $(pwd):/tipb tipb-builder rust
+```
+
+## Note
+Do not forget to update the dependent projects!