simple-http-file-api/build.docker.image.sh

59 lines
1.5 KiB
Bash

#!/bin/bash
# --- Configuration ---
IMAGE_NAME="172.22.102.100:40016/team-mmkb/simple-http-upload"
PACKAGE_JSON="package.json"
# --- Functions ---
# Function to get the current version from package.json
get_current_version() {
if [ ! -f "$PACKAGE_JSON" ]; then
echo "Error: $PACKAGE_JSON not found."
exit 1
fi
jq -r '.version' "$PACKAGE_JSON"
}
# Function to increment the major version
increment_major_version() {
local current_version="$1"
local major=$(echo "$current_version" | cut -d'.' -f1)
local minor=$(echo "$current_version" | cut -d'.' -f2)
local patch=$(echo "$current_version" | cut -d'.' -f3)
minor=$((minor + 1))
echo "$major.$minor.$patch"
}
# Function to update the package.json with the new version
update_package_json() {
local new_version="$1"
jq ".version = \"$new_version\"" "$PACKAGE_JSON" > temp.json && mv temp.json "$PACKAGE_JSON"
}
# --- Main Script ---
# Get the current version
current_version=$(get_current_version)
echo "Current version: $current_version"
# Increment the major version
new_version=$(increment_major_version "$current_version")
echo "New version: $new_version"
# Update package.json
update_package_json "$new_version"
echo "Updated $PACKAGE_JSON with version: $new_version"
# Build the Docker image with the new version
docker build -t "$IMAGE_NAME:$new_version" .
if [ $? -eq 0 ]; then
echo "Docker image built successfully: $IMAGE_NAME:$new_version"
else
echo "Error building docker image"
exit 1
fi
echo "Done!"