Started build script

master
Jef Roosens 2021-03-23 09:37:18 +01:00
parent 82b2927b33
commit cedcc3fc9f
Signed by: Jef Roosens
GPG Key ID: 955C0660072F691F
2 changed files with 53 additions and 3 deletions

View File

@ -16,11 +16,11 @@ release:
.PHONY: release .PHONY: release
image: Dockerfile image: Dockerfile
@ docker build -t '$(IMAGE):$(TAG)' . @ bash ./build '$(IMAGE)'
.PHONY: image .PHONY: image
push: image push:
@ docker push '$(IMAGE):$(TAG)' @ bash ./build '$(IMAGE)' push
.PHONY: push .PHONY: push
# Run # Run

50
build 100755
View File

@ -0,0 +1,50 @@
#!/usr/bin/env bash
# Simple guard to check input args
[[ $# -eq 1 ]] || [[ $# -eq 2 ]] || {
>&2 echo "Usage: ./build IMAGE [ACTION]"
exit 1
}
# Extract current version from Cargo.toml & get current branch
patch_version="$(grep -Po '(?<=version = ").*(?=")' Cargo.toml | head -n1)"
major_version="$(echo "$patch_version" |
sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+)/\1/')"
minor_version="$(echo "$patch_version" |
sed -E 's/([0-9]+).([0-9]+).([0-9]+)/\1.\2/')"
branch="$(git branch --show-current)"
if [[ "$branch" = "master" ]]; then
tags=("$patch_version" "$minor_version" "$major_version" )
elif [[ "$branch" = "develop" ]]; then
tags=("$patch_version-dev" "$minor_version-dev" "$major_version-dev" )
else
tags=("$branch")
fi
tag_flags=()
for tag in "${tags[@]}"; do
tag_flags+=("-t '$1:$tag'")
done
# Run the actual build command
docker build $tag_flags .
if [[ "$2" = push ]]; then
for tag in "${tags[@]}"; do
docker push "$1:$tag"
done
elif [[ "$2" = run ]]; then
docker run \
--rm \
--interactive \
--tty \
--publish 8000:8000 \
"$1:$tags"
fi