aboutsummaryrefslogtreecommitdiffstats
path: root/build_and_push.sh
diff options
context:
space:
mode:
Diffstat (limited to 'build_and_push.sh')
-rwxr-xr-xbuild_and_push.sh35
1 files changed, 35 insertions, 0 deletions
diff --git a/build_and_push.sh b/build_and_push.sh
new file mode 100755
index 0000000..3cf5241
--- /dev/null
+++ b/build_and_push.sh
@@ -0,0 +1,35 @@
+#!/usr/bin/env bash
+set -Eeuo pipefail
+
+do_push() {
+ IMAGE_NAME="website"
+ HUB_NAME="dr.ivarlovlie.no/vsh/website"
+ COMMIT_HASH=$(git rev-parse --short HEAD)
+
+ pushd src/wwwroot
+ npm run build
+ echo $COMMIT_HASH >version.txt
+ popd
+
+ docker build -t $IMAGE_NAME .
+ docker tag $IMAGE_NAME $HUB_NAME:$COMMIT_HASH
+ docker tag $IMAGE_NAME $HUB_NAME:latest
+
+ echo ""
+ echo "CTRL+C to cancel, anything to push to docker hub"
+ read -n 1
+ docker push $HUB_NAME:$COMMIT_HASH
+ docker push $HUB_NAME:latest
+}
+
+if [ -z "$(git status --untracked-files=no --porcelain)" ]; then
+ do_push
+else
+ echo "unclean git tree! CTRL+C to cancel, anything to commit and push to default branch"
+ read -n 1
+ read -p "Enter commit message: " COMMIT_MESSAGE
+ git add .
+ git commit -m "$COMMIT_MESSAGE"
+ git push
+ do_push
+fi