Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions .dockerignore.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Development .dockerignore - includes _output for pre-compiled binaries
# Only exclude what we don't need
manifests
examples
1 change: 1 addition & 0 deletions .github/licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ header:
- manifests/**
- .gitignore
- .dockerignore
- .dockerignore.dev
- .golangci.yml
- LICENSES/
- '**/*.md'
Expand Down
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,48 @@ build/%:
.PHONY: image
image: $(addprefix image/,$(ALL_CMD))
image/%:
ifeq ($(DEV_MODE),true)
@echo "Building dev image for $*..."
@$(MAKE) dev-prepare-output
@if [ ! -f "$(BIN_DIR)/$*" ]; then \
echo "Binary $(BIN_DIR)/$* not found, building..."; \
$(ROOT)/hack/build.sh $*; \
fi
$(ROOT)/hack/image.sh $* --dockerfile=Dockerfile.dev --dockerignore=.dockerignore.dev
else
$(ROOT)/hack/image.sh $*
endif

.PHONY: push
push: $(addprefix push/,$(ALL_CMD))
push/%:
ifeq ($(DEV_MODE),true)
@echo "Building and pushing dev image for $*..."
@$(MAKE) dev-prepare-output
@if [ ! -f "$(BIN_DIR)/$*" ]; then \
echo "Binary $(BIN_DIR)/$* not found, building..."; \
$(ROOT)/hack/build.sh $*; \
fi
$(ROOT)/hack/image.sh $* --dockerfile=Dockerfile.dev --dockerignore=.dockerignore.dev --push
else
$(ROOT)/hack/image.sh $* --push
endif

# Ensure _output directory is a real directory with binaries, not a symlink
.PHONY: dev-prepare-output
dev-prepare-output:
@if [ -L "$(OUTPUT_DIR)" ]; then \
REAL_PATH=$$(readlink "$(OUTPUT_DIR)"); \
echo "Converting $(OUTPUT_DIR) symlink to real directory for Docker build..."; \
rm "$(OUTPUT_DIR)"; \
mkdir -p "$(OUTPUT_DIR)"; \
if [ -d "$$REAL_PATH" ]; then \
cp -r "$$REAL_PATH"/* "$(OUTPUT_DIR)"/; \
fi; \
elif [ ! -d "$(OUTPUT_DIR)" ]; then \
echo "Creating $(OUTPUT_DIR) directory..."; \
mkdir -p "$(OUTPUT_DIR)"; \
fi

.PHONY: deploy
deploy: release
Expand Down
7 changes: 4 additions & 3 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,20 @@ You can see logs of operator by following commands
make logs/operator
```

And if you have some changes but just want to update operator, you can
And if you have some changes but just want to update operator, you can use the fast development build system:

```sh
make push && make reload/operator
make DEV_MODE=true push/tidb-operator && make reload/operator
```

**Development Build System**: The `DEV_MODE=true` option enables optimized builds for rapid iteration during development. It skips Go module downloads and compilation by using pre-compiled local binaries, reducing build time from minutes to ~2 seconds.

You can also deploy and re-deploy manifests by

```sh
make deploy
```


### Step 5: Keep your branch in sync

While on your `myfeature` branch, run the following commands:
Expand Down
35 changes: 33 additions & 2 deletions hack/lib/image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,22 @@ NEED_PREFIX["prestop-checker"]=1
function image::build() {
local targets=()
local with_push=0
local dockerfile="Dockerfile"
local dockerignore=""
while [[ $# -gt 0 ]]; do
case $1 in
--push)
with_push=1
shift
;;
--dockerfile=*)
dockerfile="${1#*=}"
shift
;;
--dockerignore=*)
dockerignore="${1#*=}"
shift
;;
-*|--*)
echo "Unknown option $1"
exit 1
Expand Down Expand Up @@ -73,7 +83,20 @@ function image::build() {
if [[ -n "${NEED_PREFIX[$target]+x}" ]]; then
image=tidb-operator-${image}
fi
echo "build image ${image}"
echo "build image ${image} using ${dockerfile}"

# Handle custom dockerignore file
local dockerignore_backup=""
if [[ -n "$dockerignore" ]]; then
# Backup original .dockerignore if it exists
if [[ -f "$ROOT/.dockerignore" ]]; then
dockerignore_backup="$ROOT/.dockerignore.backup.$$"
Copy link

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using $$ (process ID) for backup filename could cause race conditions if multiple builds run simultaneously. Consider using a more unique identifier like $(date +%s%N) or mktemp to generate unique backup filenames.

Suggested change
dockerignore_backup="$ROOT/.dockerignore.backup.$$"
dockerignore_backup="$(mktemp "$ROOT/.dockerignore.backup.XXXXXX")"

Copilot uses AI. Check for mistakes.
mv "$ROOT/.dockerignore" "$dockerignore_backup"
fi
# Copy custom dockerignore
cp "$ROOT/$dockerignore" "$ROOT/.dockerignore"
fi
Copy link

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cp command could fail if the source dockerignore file doesn't exist, but there's no error handling. Add a check to ensure the source file exists before copying.

Suggested change
fi
if [[ ! -f "$ROOT/$dockerignore" ]]; then
echo "Error: Custom dockerignore file '$ROOT/$dockerignore' does not exist." >&2
# Restore original .dockerignore if it was backed up
if [[ -n "$dockerignore_backup" && -f "$dockerignore_backup" ]]; then
mv "$dockerignore_backup" "$ROOT/.dockerignore"
fi
exit 1
fi
cp "$ROOT/$dockerignore" "$ROOT/.dockerignore"

Copilot uses AI. Check for mistakes.

docker buildx build \
--target $target \
-o type=oci,dest=$IMAGE_DIR/${target}.tar \
Expand All @@ -82,7 +105,15 @@ function image::build() {
--cache-to=type=local,dest=$CACHE_DIR \
--build-arg=TARGET="${target}" \
$args \
-f $ROOT/image/Dockerfile $ROOT
-f $ROOT/image/${dockerfile} $ROOT

# Restore original .dockerignore
if [[ -n "$dockerignore" ]]; then
rm -f "$ROOT/.dockerignore"
if [[ -n "$dockerignore_backup" && -f "$dockerignore_backup" ]]; then
mv "$dockerignore_backup" "$ROOT/.dockerignore"
fi
fi
done

case $V_IMG_HUB in
Expand Down
45 changes: 45 additions & 0 deletions image/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Development Dockerfile for faster builds
# This Dockerfile expects pre-compiled binaries from local build
FROM ghcr.io/pingcap-qe/bases/pingcap-base:v1.9.2 AS tidb-operator

WORKDIR /

# Copy pre-compiled binary from local build (relative to build context root)
COPY _output/bin/tidb-operator tidb-operator

USER 65532:65532

ENTRYPOINT ["/tidb-operator"]

FROM ghcr.io/pingcap-qe/bases/pingcap-base:v1.9.2 AS prestop-checker

WORKDIR /

# Copy pre-compiled binary from local build
COPY _output/bin/prestop-checker prestop-checker

USER 65532:65532

ENTRYPOINT ["/prestop-checker"]

FROM ghcr.io/pingcap-qe/bases/pingcap-base:v1.9.2 AS testing-workload

WORKDIR /

# Copy pre-compiled binary from local build
COPY _output/bin/testing-workload testing-workload

USER 65532:65532

ENTRYPOINT ["/testing-workload"]

FROM ghcr.io/pingcap-qe/bases/pingcap-base:v1.9.2 AS tidb-backup-manager

WORKDIR /

# Copy pre-compiled binary from local build
COPY _output/bin/tidb-backup-manager tidb-backup-manager

USER 65532:65532

ENTRYPOINT ["/tidb-backup-manager"]