Skip to content

Commit

Permalink
Multi platform build (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
noMoreCLI authored Dec 9, 2024
1 parent 90d27ce commit a44d4a5
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 20 deletions.
1 change: 1 addition & 0 deletions .version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v0.0.1
77 changes: 57 additions & 20 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,68 @@
#!/bin/bash
#
# Usage ./build.sh repo/user [push]
#
IMAGE_PREFIX="${1:-app-simulator}"

for DIR in nodes/*;
# Default values for parameters
PUSH=
#MacOSX M architecture: linux/arm64/v8
PLATFORM="linux/amd64"
IMAGE_PREFIX="app-simulator"
VERSION=$(./bumpversion.sh)

# Function to display help
show_help() {
echo "Usage: $(basename "$0") [OPTIONS]"
echo "Options:"
echo " --push Specify whether to push the built images"
echo " --platform=<platform> Specify the build platform (default: linux/amd64), can be multiple platforms comma separated"
echo " --repoprefix=<prefix> Specify the image prefix (default: app-simulator)"
echo " --help Display this help message"
}

# Parse command line options
for ARG in "$@"; do
case $ARG in
--push)
PUSH="--push"
VERSION=$(./bumpversion.sh)
shift
;;
--platform=*)
PLATFORM="${ARG#*=}"
shift
;;
--repoprefix=*)
IMAGE_PREFIX="${ARG#*=}"
shift
;;
--help)
show_help
exit 0
;;
*)
echo "Unknown option: $ARG"
show_help
exit 1
;;
esac
done

for DIR in services/*;
do
if [ -d $DIR ] ; then
echo "Building ${IMAGE_PREFIX}/app-simulator:`basename $DIR`..."
docker build --platform=linux/amd64 -t "${IMAGE_PREFIX}/app-simulator:`basename $DIR`" $DIR;
if [ "$2" == "push" ]; then
echo "Pushing ${IMAGE_PREFIX}/app-simulator:`basename $DIR` to registry ...."
docker push "${IMAGE_PREFIX}/app-simulator:`basename $DIR`"
# Add your commands here
fi
IMAGE_TAG="${IMAGE_PREFIX}/services-$(basename "$DIR"):$VERSION"
echo "Building $IMAGE_TAG..."
echo "Running 'docker buildx build --platform $PLATFORM -t $IMAGE_TAG $DIR $PUSH'"
docker buildx build --platform $PLATFORM -t $IMAGE_TAG $PUSH $DIR
fi
done;

for DIR in loaders/*;
do
if [ -d $DIR ] ; then
echo "Building ${IMAGE_PREFIX}/app-simulator:`basename $DIR`..."
docker build --platform=linux/amd64 -t "${IMAGE_PREFIX}/app-simulator:`basename $DIR`" $DIR;
if [ "$2" == "push" ]; then
echo "Pushing ${IMAGE_PREFIX}/app-simulator:`basename $DIR` to registry ...."
docker push "${IMAGE_PREFIX}/app-simulator:`basename $DIR`"
# Add your commands here
fi
IMAGE_TAG="${IMAGE_PREFIX}/loaders-$(basename "$DIR"):$VERSION"
echo "Building $IMAGE_TAG..."
echo "Building $IMAGE_TAG..."
echo "Running 'docker buildx build --platform $PLATFORM -t $IMAGE_TAG $DIR $PUSH'"
docker buildx build --platform $PLATFORM -t $IMAGE_TAG $PUSH $DIR $PUSH
fi
done;
done;

80 changes: 80 additions & 0 deletions bumpversion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash

# File that stores the version string
VERSION_FILE=".version"

# Function to display help
show_help() {
echo "Usage: bumpversion.sh [OPTION]"
echo "Modify or display the version string in the form of 'v{major}.{minor}.{build}'."
echo "Stores the version in the file '$VERSION_FILE', defaults to v0.0.0 if it does not exist"
echo
echo "Options:"
echo " --build Increase the build number by 1."
echo " --minor Increase the minor number by 1 and the build number by 1."
echo " --major Increase the major number by 1, reset minor to 0, and increase build by 1."
echo " --help Display this help message."
echo " (no option) Display the current version."
}

# Function to read the current version from the file
get_version() {
if [ -f "$VERSION_FILE" ]; then
cat "$VERSION_FILE"
else
echo "v0.0.0" # Default version if the file does not exist
fi
}

# Function to update the version in the file
set_version() {
echo "$1" > "$VERSION_FILE"
}

# Get the current version
current_version=$(get_version)

# Extract major, minor, and build numbers
version_pattern='^v([0-9]+)\.([0-9]+)\.([0-9]+)$'
if [[ $current_version =~ $version_pattern ]]; then
major=${BASH_REMATCH[1]}
minor=${BASH_REMATCH[2]}
build=${BASH_REMATCH[3]}
else
echo "Invalid version format"
exit 1
fi

# Handle command-line arguments
case "$1" in
--build)
((build++))
;;
--minor)
((minor++))
((build++))
;;
--major)
((major++))
minor=0
((build++))
;;
--help)
show_help
exit 0
;;
*)
# No argument, just return the current version
echo "$current_version"
exit 0
;;
esac

# Construct the new version string
new_version="v${major}.${minor}.${build}"

# Update the version file
set_version "$new_version"

# Output the new version
echo "$new_version"

0 comments on commit a44d4a5

Please sign in to comment.