Skip to content
Merged
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
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ RUN make

FROM ubuntu:22.04 as base

RUN apt-get update && apt-get install -y mysql-client && rm -rf /var/lib/apt/lists/*

WORKDIR /metrics-loader
COPY configs /configs
COPY --from=builder /metrics-loader/bin/* /usr/local/bin/
Expand Down
200 changes: 200 additions & 0 deletions build-docker-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
#!/bin/bash

# Function to handle tagging and pushing an image
perform_push_operations() {
local image_to_push="$1"
local current_container_engine="$2"

DEFAULT_REGISTRY_HOST="greptime-registry.cn-hangzhou.cr.aliyuncs.com/tools"
read -p "Please enter the image registry address (default is $DEFAULT_REGISTRY_HOST): " REGISTRY_HOST
if [ -z "$REGISTRY_HOST" ]; then
REGISTRY_HOST="$DEFAULT_REGISTRY_HOST"
echo "Using default image registry address: $REGISTRY_HOST"
fi

REMOTE_IMAGE_NAME="$REGISTRY_HOST/$image_to_push"

echo "Tagging image $image_to_push as $REMOTE_IMAGE_NAME ..."
if ! "$current_container_engine" tag "$image_to_push" "$REMOTE_IMAGE_NAME"; then
echo "Error: Image tagging failed."
return 1
fi
echo "Image tagged successfully."

echo "Pushing image $REMOTE_IMAGE_NAME ..."
if ! "$current_container_engine" push "$REMOTE_IMAGE_NAME"; then
echo "Error: Image push failed."
echo "Please ensure you are logged in to $REGISTRY_HOST ($current_container_engine login $REGISTRY_HOST)"
return 1
fi
echo "Image $REMOTE_IMAGE_NAME pushed successfully."
return 0
}

# Determine script mode
SCRIPT_MODE="default"
if [[ "$1" == "only-push" ]]; then
SCRIPT_MODE="only-push"
fi

# Check if podman is available
if command -v podman &> /dev/null; then
CONTAINER_ENGINE="podman"
# Otherwise, check if docker is available
elif command -v docker &> /dev/null; then
CONTAINER_ENGINE="docker"
else
echo "Error: Neither podman nor docker found. Please install one of them."
exit 1
fi
echo "Will use $CONTAINER_ENGINE."

if [[ "$SCRIPT_MODE" == "only-push" ]]; then
echo "--- Push-Only Mode ---"
echo "Available local images:"
"$CONTAINER_ENGINE" images

read -p "Please enter the name of the local image to push (e.g., repository:tag): " LOCAL_IMAGE_TO_PUSH
if [ -z "$LOCAL_IMAGE_TO_PUSH" ]; then
echo "Error: Image name cannot be empty."
exit 1
fi

# Check if the image exists
if ! "$CONTAINER_ENGINE" image inspect "$LOCAL_IMAGE_TO_PUSH" &> /dev/null; then
echo "Error: Local image $LOCAL_IMAGE_TO_PUSH not found."
exit 1
fi

echo "Preparing to push image: $LOCAL_IMAGE_TO_PUSH"
if perform_push_operations "$LOCAL_IMAGE_TO_PUSH" "$CONTAINER_ENGINE"; then
echo "Image push process completed."
else
echo "Image push process failed."
exit 1
fi
else # Default mode (build and then optionally push)
echo "--- Default Build and Push Mode ---"

# Interactively ask the user for the image tag
read -p "Please enter the image tag (e.g., latest, 1.0): " IMAGE_TAG

# Check if the tag is empty
if [ -z "$IMAGE_TAG" ]; then
echo "Error: Image tag cannot be empty."
exit 1
fi

BUILT_IMAGE_BASENAME="ingester" # As implied by original script
LOCAL_BUILT_IMAGE_NAME="${BUILT_IMAGE_BASENAME}:${IMAGE_TAG}"
DOCKERFILE_PATH="Dockerfile" # Assume Dockerfile is in the current directory

# Check if Dockerfile exists
if [ ! -f "$DOCKERFILE_PATH" ]; then
echo "Error: $DOCKERFILE_PATH not found in the current directory."
echo "Please ensure Dockerfile exists in the directory where the script is executed."
exit 1
fi

echo "Building image $LOCAL_BUILT_IMAGE_NAME ..."

# Build the image
if "$CONTAINER_ENGINE" build -t "$LOCAL_BUILT_IMAGE_NAME" -f "$DOCKERFILE_PATH" .; then
echo "Image $LOCAL_BUILT_IMAGE_NAME built successfully."
else
echo "Error: Image build failed."
exit 1
fi

# Ask whether to push to the image registry
read -p "Do you want to push the image $LOCAL_BUILT_IMAGE_NAME to the image registry? (y/n): " PUSH_CONFIRMATION

if [[ "$PUSH_CONFIRMATION" == "y" || "$PUSH_CONFIRMATION" == "Y" ]]; then
if perform_push_operations "$LOCAL_BUILT_IMAGE_NAME" "$CONTAINER_ENGINE"; then
echo "Image push process completed."
else
echo "Image push process failed."
exit 1
fi
else
echo "Image $LOCAL_BUILT_IMAGE_NAME was not pushed to the registry."
fi
fi

echo "Script execution finished."
exit 0

# Check if podman is available
if command -v podman &> /dev/null; then
CONTAINER_ENGINE="podman"
# Otherwise, check if docker is available
elif command -v docker &> /dev/null; then
CONTAINER_ENGINE="docker"
else
echo "Error: Neither podman nor docker found. Please install one of them."
exit 1
fi

echo "Will use $CONTAINER_ENGINE to build the image."

# Interactively ask the user for the image tag
read -p "Please enter the image tag (e.g., latest, 1.0): " IMAGE_TAG

# Check if the tag is empty
if [ -z "$IMAGE_TAG" ]; then
echo "Error: Image tag cannot be empty."
exit 1
fi

LOCAL_IMAGE_NAME="ingester:$IMAGE_TAG"
DOCKERFILE_PATH="Dockerfile" # Assume Dockerfile is in the current directory

# Check if Dockerfile exists
if [ ! -f "$DOCKERFILE_PATH" ]; then
echo "Error: $DOCKERFILE_PATH not found in the current directory."
echo "Please ensure Dockerfile exists in the directory where the script is executed."
exit 1
fi

echo "Building image $LOCAL_IMAGE_NAME ..."

# Build the image
if "$CONTAINER_ENGINE" build -t "$LOCAL_IMAGE_NAME" -f "$DOCKERFILE_PATH" .; then
echo "Image $LOCAL_IMAGE_NAME built successfully."
else
echo "Error: Image build failed."
exit 1
fi

# Ask whether to push to the image registry
read -p "Do you want to push the image to the image registry? (y/n): " PUSH_TO_REGISTRY

if [[ "$PUSH_TO_REGISTRY" == "y" || "$PUSH_TO_REGISTRY" == "Y" ]]; then
DEFAULT_REGISTRY_HOST="greptime-registry.cn-hangzhou.cr.aliyuncs.com/tools"
read -p "Please enter the image registry address (default is $DEFAULT_REGISTRY_HOST): " REGISTRY_HOST
if [ -z "$REGISTRY_HOST" ]; then
REGISTRY_HOST="$DEFAULT_REGISTRY_HOST"
echo "Using default image registry address: $REGISTRY_HOST"
fi

REMOTE_IMAGE_NAME="$REGISTRY_HOST/$LOCAL_IMAGE_NAME"

echo "Tagging image $LOCAL_IMAGE_NAME as $REMOTE_IMAGE_NAME ..."
if "$CONTAINER_ENGINE" tag "$LOCAL_IMAGE_NAME" "$REMOTE_IMAGE_NAME"; then
echo "Image tagged successfully."
else
echo "Error: Image tagging failed."
exit 1
fi

echo "Pushing image $REMOTE_IMAGE_NAME ..."
if "$CONTAINER_ENGINE" push "$REMOTE_IMAGE_NAME"; then
echo "Image $REMOTE_IMAGE_NAME pushed successfully."
else
echo "Error: Image push failed."
echo "Please ensure you are logged in to $REGISTRY_HOST ($CONTAINER_ENGINE login $REGISTRY_HOST)"
exit 1
fi
else
echo "Image was not pushed to the registry."
fi
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/apache/arrow/go/arrow v0.0.0-20200730104253-651201b0f516 // indirect
github.com/apache/thrift v0.14.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
Expand All @@ -24,6 +25,7 @@ require (

require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/go-sql-driver/mysql v1.9.2
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/gopacket v1.1.19
github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiy
cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos=
cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/apache/arrow/go/arrow v0.0.0-20200730104253-651201b0f516 h1:byKBBF2CKWBjjA4J1ZL2JXttJULvWSl50LegTyRZ728=
Expand All @@ -46,6 +48,8 @@ github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-sql-driver/mysql v1.9.2 h1:4cNKDYQ1I84SXslGddlsrMhc8k4LeDVj6Ad6WRjiHuU=
github.com/go-sql-driver/mysql v1.9.2/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
Expand Down
Loading
Loading