aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xcode/api/build_and_push.sh4
-rw-r--r--code/app/.dockerignore7
-rw-r--r--code/app/.version1
-rw-r--r--code/app/.version-dev1
-rw-r--r--code/app/Dockerfile14
-rwxr-xr-xcode/app/build_and_push.sh89
6 files changed, 114 insertions, 2 deletions
diff --git a/code/api/build_and_push.sh b/code/api/build_and_push.sh
index 7e4b2d7..8aaff38 100755
--- a/code/api/build_and_push.sh
+++ b/code/api/build_and_push.sh
@@ -7,10 +7,10 @@ CURRENT_DEV_VERSION_INT=${CURRENT_DEV_VERSION//[!0-9]/}
CURRENT_VERSION=$(cat .version)
CURRENT_VERSION_INT=${CURRENT_VERSION//[!0-9]/}
if [ ${1-prod} == "dev" ]; then
- NEW_VERSION="v$((CURRENT_DEV_VERSION_INT + 1))-server-dev"
+ NEW_VERSION="v$((CURRENT_DEV_VERSION_INT + 1))dev"
OLD_VERSION=$CURRENT_DEV_VERSION
else
- NEW_VERSION="v$((CURRENT_VERSION_INT + 1))-server"
+ NEW_VERSION="v$((CURRENT_VERSION_INT + 1))"
OLD_VERSION=$CURRENT_VERSION
fi
IMAGE_NAME="greatoffice/server"
diff --git a/code/app/.dockerignore b/code/app/.dockerignore
new file mode 100644
index 0000000..00774fa
--- /dev/null
+++ b/code/app/.dockerignore
@@ -0,0 +1,7 @@
+.env
+.env-example
+.svelte-kit
+.git
+static
+node_modules
+build \ No newline at end of file
diff --git a/code/app/.version b/code/app/.version
new file mode 100644
index 0000000..c227083
--- /dev/null
+++ b/code/app/.version
@@ -0,0 +1 @@
+0 \ No newline at end of file
diff --git a/code/app/.version-dev b/code/app/.version-dev
new file mode 100644
index 0000000..c227083
--- /dev/null
+++ b/code/app/.version-dev
@@ -0,0 +1 @@
+0 \ No newline at end of file
diff --git a/code/app/Dockerfile b/code/app/Dockerfile
new file mode 100644
index 0000000..a79f35e
--- /dev/null
+++ b/code/app/Dockerfile
@@ -0,0 +1,14 @@
+# syntax=docker/dockerfile:1
+FROM node:18.12.0-alpine3.16 AS builder
+WORKDIR .
+COPY package.json .
+RUN npm i
+COPY . .
+RUN npm run build
+FROM node:18.12.0-alpine3.16
+USER node:node
+WORKDIR .
+COPY --from=builder --chown=node:node build build
+COPY --from=builder --chown=node:node node_modules node_modules
+COPY --chown=node:node package.json .
+CMD ["node","build"] \ No newline at end of file
diff --git a/code/app/build_and_push.sh b/code/app/build_and_push.sh
new file mode 100755
index 0000000..5a73e8a
--- /dev/null
+++ b/code/app/build_and_push.sh
@@ -0,0 +1,89 @@
+#!/usr/bin/env bash
+
+set -Eueo pipefail
+
+CURRENT_DEV_VERSION=$(cat .version-dev)
+CURRENT_DEV_VERSION_INT=${CURRENT_DEV_VERSION//[!0-9]/}
+CURRENT_VERSION=$(cat .version)
+CURRENT_VERSION_INT=${CURRENT_VERSION//[!0-9]/}
+if [ ${1-prod} == "dev" ]; then
+ NEW_VERSION="v$((CURRENT_DEV_VERSION_INT + 1))-dev"
+ OLD_VERSION=$CURRENT_DEV_VERSION
+else
+ NEW_VERSION="v$((CURRENT_VERSION_INT + 1))"
+ OLD_VERSION=$CURRENT_VERSION
+fi
+IMAGE_NAME="greatoffice/app"
+HUB_NAME="dr.ivar.systems/greatoffice/app"
+
+# Check for uncommited changes and optionally commit them
+if [ "$(git status --untracked-files=no --porcelain)" ]; then
+ echo "Unclean git tree! press CTRL+C to exit or press ENTER to commit and push to the default branch"
+ read -n 1
+
+ read -p "Enter commit message: " COMMIT_MESSAGE
+ git add ..
+ git commit --quiet -m "$COMMIT_MESSAGE"
+fi
+
+if [ ${1-prod} == "dev" ]; then
+ echo $NEW_VERSION >|.version-dev
+ git add .version-dev
+else
+ echo $NEW_VERSION >|.version
+ git add .version
+fi
+
+echo "Starting build of $HUB_NAME:$NEW_VERSION at $(date -u)..."
+echo
+
+# Put version.txt inside of server
+pushd src/wwwroot
+echo "$NEW_VERSION" >version.txt
+git add version.txt
+popd
+
+git commit --quiet -m "chore(release): Bump version"
+
+read -p "Do you want to tag this build? (y/n) " -n 1 -r
+echo
+if [[ $REPLY =~ ^[Yy]$ ]]; then
+ read -p "Enter tag message (can be empty): " TAG_MESSAGE
+ git tag -am "$TAG_MESSAGE" $NEW_VERSION
+fi
+
+read -p "Do you want to push the latest commits and tags to origin? (y/n) " -n 1 -r
+echo
+if [[ $REPLY =~ ^[Yy]$ ]]; then
+ echo "Pushing latest changes to remotes..."
+ echo
+ git push --quiet --follow-tags
+fi
+
+# Build docker image
+echo "Building docker image"
+echo
+
+docker build -t $IMAGE_NAME:$NEW_VERSION .
+
+docker tag $IMAGE_NAME:$NEW_VERSION $HUB_NAME:$NEW_VERSION
+
+if [ ${1-prod} == "dev" ]; then
+ docker tag $IMAGE_NAME:$NEW_VERSION $HUB_NAME:latest-dev
+fi
+if [ ${1-prod} == "prod" ]; then
+ docker tag $IMAGE_NAME:$NEW_VERSION $HUB_NAME:latest
+fi
+
+# Optionally push images to docker registry
+echo "Press CTRL+C to exit or press ENTER to push docker image to registry"
+read -n 1
+docker push $HUB_NAME:$NEW_VERSION
+
+if [ ${1-prod} == "dev" ]; then
+ docker push $HUB_NAME:latest-dev
+fi
+
+if [ ${1-prod} == "prod" ]; then
+ docker push $HUB_NAME:latest
+fi