[#17] Wrote dockerfiles; moved everything to Docker
This commit is contained in:
parent
7243be302c
commit
93ec27bb02
6 changed files with 112 additions and 63 deletions
66
build
66
build
|
|
@ -1,10 +1,21 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Simple guard to check input args
|
||||
[[ $# -eq 1 ]] || [[ $# -eq 2 ]] || {
|
||||
>&2 echo "Usage: ./build IMAGE [ACTION]"
|
||||
exit 1
|
||||
}
|
||||
image="chewingbever/fej"
|
||||
# Should be either dev or rel
|
||||
mode="dev"
|
||||
action=""
|
||||
attach="--detach"
|
||||
|
||||
while getopts ":i:m:a:l" c; do
|
||||
case $c in
|
||||
i ) image="$OPTARG" ;;
|
||||
m ) mode="$OPTARG" ;;
|
||||
a ) action="$OPTARG" ;;
|
||||
l ) attach="" ;;
|
||||
? ) exit 1 ;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND-1))
|
||||
|
||||
# Extract current version from Cargo.toml & get current branch
|
||||
patch_version="$(grep -Po '(?<=version = ").*(?=")' Cargo.toml | head -n1)"
|
||||
|
|
@ -25,31 +36,58 @@ else
|
|||
|
||||
fi
|
||||
|
||||
# Run the actual build command
|
||||
DOCKER_BUILDKIT=1 docker build -t "$1:$tags" .
|
||||
# First, we build the builder
|
||||
DOCKER_BUILDKIT=1 docker build -f docker/Dockerfile.builder -t "$image-builder:latest" .
|
||||
|
||||
if [[ "$2" = push ]]; then
|
||||
# Run the actual build command
|
||||
if [ "$mode" = "rel" ]; then
|
||||
DOCKER_BUILDKIT=1 docker build -t "$image:$tags" -f docker/Dockerfile.rel .
|
||||
|
||||
elif [[ "$mode" = "dev" ]]; then
|
||||
DOCKER_BUILDKIT=1 docker build -t "$image-dev:$tags" -f docker/Dockerfile.dev .
|
||||
|
||||
else
|
||||
>&2 echo "Invalid mode."
|
||||
exit 1
|
||||
|
||||
fi
|
||||
|
||||
if [[ "$action" = push ]]; then
|
||||
[[ "$branch" =~ ^develop|master$ ]] || {
|
||||
>&2 echo "You can only push from develop or master."
|
||||
exit 2
|
||||
}
|
||||
|
||||
[[ "$mode" = "rel" ]] || {
|
||||
>&2 echo "You can only push release builds."
|
||||
exit 3
|
||||
}
|
||||
|
||||
for tag in "${tags[@]}"; do
|
||||
# Create the tag
|
||||
docker tag "$1:$tags" "$1:$tag"
|
||||
docker tag "$image:$tags" "$image:$tag"
|
||||
|
||||
# Push the tag
|
||||
docker push "$1:$tag"
|
||||
docker push "$image:$tag"
|
||||
|
||||
# Remove the tag again, if it's not the main tag
|
||||
[[ "$tag" != "$tags" ]] && docker rmi "$1:$tag"
|
||||
[[ "$tag" != "$tags" ]] && docker rmi "$image:$tag"
|
||||
done
|
||||
|
||||
elif [[ "$2" = run ]]; then
|
||||
docker run \
|
||||
elif [[ "$action" = run ]]; then
|
||||
if [[ "$mode" = "dev" ]]; then
|
||||
# Create caching volumes if needed (they need to be named)
|
||||
docker volume create fej_build-cache
|
||||
docker volume create fej_registry-cache
|
||||
|
||||
flags="-v fej_build-cache:/usr/src/app/target -v fej_registry-cache:/root/.cargo/registry"
|
||||
fi
|
||||
|
||||
docker run $attach $flags \
|
||||
--rm \
|
||||
--interactive \
|
||||
--tty \
|
||||
--publish 8000:8000 \
|
||||
"$1:$tags"
|
||||
--name fej \
|
||||
"$image$([[ "$mode" != "rel" ]] && echo "-dev"):$tags" "$@"
|
||||
fi
|
||||
|
|
|
|||
Reference in a new issue