Skip to content

Commit

Permalink
Merge pull request #315 from StampyAI/shared-stampys
Browse files Browse the repository at this point in the history
  • Loading branch information
ProducerMatt committed Jul 3, 2023
2 parents 5f2436e + d9732e5 commit e34f117
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ RUN --mount=type=cache,mode=0755,target=/root/.cache/pip conda env create -f env
RUN echo "conda activate stampy" >> ~/.profile
SHELL ["/bin/bash", "--login", "-c"]
RUN --mount=type=cache,mode=0755,target=/root/.cache/pip conda activate stampy && conda install pytest
RUN conda clean -a

COPY . .
ENV STAMPY_RUN_TESTS=${STAMPY_RUN_TESTS}
Expand Down
64 changes: 64 additions & 0 deletions scripts/update-shared-stampys.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

# This script is for use on the Stampy server managing multiple docker instances.

set -eu

PROJECT_DIR=$HOME
host_list=$(cat ~/served_hosts)

sanity_check() {
local target="${PROJECT_DIR}/$1"
local task="check dir '${target}'exists"
cd "${target}" && echo "$task: $1"
if [ ! -d "${target}/.git" ]; then
echo "Dir ${target}/.git does not exist"
exit 1
fi
}
git_update () {
local task="update and prune git repo"
cd "${PROJECT_DIR}/$1" && echo "$task: $1"
git pull --rebase=true --depth=1 -q
git gc --prune=now -q
}
image_build () {
local task="build image"
cd "${PROJECT_DIR}/$1" && echo "$task: $1"
podman-compose --podman-args '--format=docker --pull=newer -q' build
}
actually_update () {
local task="restart service"
cd "${PROJECT_DIR}/$1" && echo "$task: $1"
podman-compose down
podman-compose up -d
}
post_cleanup () {
echo "prune intermediate images"
podman system prune -af
}

sanity_check "stampy"
for host in $host_list; do
sanity_check $host
done

# Main stampy folder should have been updated by external action,
# as to update this script.
for host in $host_list; do
git_update $host
done

for host in $host_list; do
image_build $host
done

for host in $host_list; do
actually_update $host
done

post_cleanup

echo "Update script successful!"

exit 0

0 comments on commit e34f117

Please sign in to comment.