Update docker

This commit is contained in:
david 2025-05-16 18:01:29 +02:00
parent b756df38a9
commit 4c31dbbed0
7 changed files with 441 additions and 230 deletions

70
bin/build Executable file
View file

@ -0,0 +1,70 @@
#!/usr/bin/env bash
server=phela
# Save current stash state
initial_stash_count=$(git stash list | wc -l)
# Check if working directory is clean
if [[ -n $(git status --porcelain) ]]; then
echo "Repository is dirty. Stashing changes..."
git stash push --include-untracked --quiet
stashed=true
else
echo "Repository is clean."
stashed=false
fi
if [[ -n "$1" ]]; then
tag="$1"
else
tag=$(git describe --tags --exact-match 2>/dev/null)
fi
if [[ -n $tag ]]; then
echo "Current Git tag: $tag"
else
branch=$(git rev-parse --abbrev-ref HEAD)
tag=$branch-$(git rev-parse HEAD)
echo "Current commit SHA-1: $tag"
fi
baseimage=code.hohl.cloud/jwa11y/a11yist
image=$baseimage:$tag
echo "Building tag $image"
docker build --progress quiet -t $image --target release .
# Restore the stash if we stashed
if [ "$stashed" = true ]; then
echo "Restoring stashed changes..."
current_stash_count=$(git stash list | wc -l)
if (( current_stash_count > initial_stash_count )); then
git stash pop --quiet
echo "Changes restored."
else
echo "No stash to restore."
fi
else
echo "No changes to restore."
fi
echo "Pushing image $image"
docker push --quiet $image
read -p "Do you want to SSH into $server and run 'deploy'? [y/N] " answer
if [[ "$answer" =~ ^[Yy]$ ]]; then
echo "Connecting to $server and running 'deploy'..."
baseimage_esc=$(echo $baseimage | sed 's/\//\\\//g' | sed 's/\./\\\./g')
tag_esc=$(echo $image | sed 's/\//\\\//g' | sed 's/\./\\\./g')
read -r -d '' remote_script <<REMOTE
cd /usr/local/services/a11yist
sed -i "s/image:.*$baseimage_esc.*/image: $tag_esc/" compose.yml
deploy
echo "$(date) $tag" >> deployments.log
REMOTE
echo "Execute deployment"
echo "$remote_script" | ssh "$server" "bash -s"
fi

View file

@ -1,8 +1,24 @@
#!/bin/bash -e
echo "entrypoint docker: ${@} ${ASSETS_PATH} :: ${@: 1:1} / ${@: 2:1}"
# If running the rails server then create or migrate existing database
if [ "${1}" == "./bin/rails" ] && [ "${2}" == "server" ]; then
if [ "${@: 1:1}" == "./bin/rails" ] && [ "${@: 2:1}" == "server" ]; then
if [ -f ${INSTALL_DIR}/pids/server.pid ]; then
rm ${INSTALL_DIR}/pids/server.pid
fi
echo "Prepare db..."
./bin/rails db:prepare
echo "Copy assets to <$ASSETS_PATH>?"
if [[ -n "$ASSETS_PATH" ]]; then
echo "Copy assets to $ASSETS_PATH"
find "$INSTALL_DIR/public" -mindepth 1 -exec echo "copy " {} \;
find "$INSTALL_DIR/public" -mindepth 1 -exec cp -a {} "$ASSETS_PATH" \;
fi
fi
exec "${@}"