2021-09-05 17:10:14 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# deploy all needed project files to different servers:
|
|
|
|
# test for local vm for testing
|
|
|
|
# blackhole for local production
|
2021-12-17 09:57:10 +00:00
|
|
|
# unstable to publish intermediate releases
|
|
|
|
# docker to publish regular release
|
2021-09-05 17:10:14 +00:00
|
|
|
|
2021-10-13 12:34:55 +00:00
|
|
|
# create builder:
|
|
|
|
# docker buildx create --name tubearchivist
|
|
|
|
# docker buildx use tubearchivist
|
|
|
|
# docker buildx inspect --bootstrap
|
|
|
|
|
2021-10-17 06:29:22 +00:00
|
|
|
# more details:
|
2022-04-15 15:35:13 +00:00
|
|
|
# https://github.com/tubearchivist/tubearchivist/issues/6
|
2021-10-17 06:29:22 +00:00
|
|
|
|
2021-09-05 17:10:14 +00:00
|
|
|
set -e
|
|
|
|
|
|
|
|
function sync_blackhole {
|
|
|
|
|
|
|
|
host="blackhole.local"
|
|
|
|
|
|
|
|
rsync -a --progress --delete-after \
|
2021-09-10 09:04:46 +00:00
|
|
|
--exclude ".git" \
|
|
|
|
--exclude ".gitignore" \
|
2021-09-05 17:10:14 +00:00
|
|
|
--exclude "**/cache" \
|
|
|
|
--exclude "**/__pycache__/" \
|
2023-07-30 16:22:06 +00:00
|
|
|
--exclude ".venv" \
|
2021-09-05 17:10:14 +00:00
|
|
|
--exclude "db.sqlite3" \
|
2023-04-09 06:59:42 +00:00
|
|
|
--exclude ".mypy_cache" \
|
2021-09-05 17:10:14 +00:00
|
|
|
. -e ssh "$host":tubearchivist
|
|
|
|
|
2022-10-23 03:50:16 +00:00
|
|
|
ssh "$host" 'docker build -t bbilly1/tubearchivist --build-arg TARGETPLATFORM="linux/amd64" tubearchivist'
|
2022-10-22 17:11:03 +00:00
|
|
|
ssh "$host" 'docker compose up -d'
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function sync_test {
|
|
|
|
|
|
|
|
# docker commands don't need sudo in testing vm
|
2021-10-13 12:34:55 +00:00
|
|
|
# pass argument to build for specific platform
|
|
|
|
|
2021-09-05 17:10:14 +00:00
|
|
|
host="tubearchivist.local"
|
2022-03-24 12:54:47 +00:00
|
|
|
# make base folder
|
|
|
|
ssh "$host" "mkdir -p docker"
|
2021-09-05 17:10:14 +00:00
|
|
|
|
2022-03-24 12:54:47 +00:00
|
|
|
# copy project files to build image
|
2021-09-05 17:10:14 +00:00
|
|
|
rsync -a --progress --delete-after \
|
2021-09-10 09:04:46 +00:00
|
|
|
--exclude ".git" \
|
|
|
|
--exclude ".gitignore" \
|
2021-09-05 17:10:14 +00:00
|
|
|
--exclude "**/cache" \
|
|
|
|
--exclude "**/__pycache__/" \
|
2024-05-21 17:08:45 +00:00
|
|
|
--exclude "**/.pytest_cache/" \
|
2023-06-22 16:28:06 +00:00
|
|
|
--exclude ".venv" \
|
2021-09-05 17:10:14 +00:00
|
|
|
--exclude "db.sqlite3" \
|
2023-04-09 06:59:42 +00:00
|
|
|
--exclude ".mypy_cache" \
|
2021-09-05 17:10:14 +00:00
|
|
|
. -e ssh "$host":tubearchivist
|
|
|
|
|
2022-03-24 12:54:47 +00:00
|
|
|
# copy default docker-compose file if not exist
|
|
|
|
rsync --progress --ignore-existing docker-compose.yml -e ssh "$host":docker
|
2021-09-05 17:10:14 +00:00
|
|
|
|
2021-10-13 12:34:55 +00:00
|
|
|
if [[ $1 = "amd64" ]]; then
|
|
|
|
platform="linux/amd64"
|
|
|
|
elif [[ $1 = "arm64" ]]; then
|
|
|
|
platform="linux/arm64"
|
|
|
|
elif [[ $1 = "multi" ]]; then
|
|
|
|
platform="linux/amd64,linux/arm64"
|
|
|
|
else
|
|
|
|
platform="linux/amd64"
|
|
|
|
fi
|
|
|
|
|
2022-03-24 12:54:47 +00:00
|
|
|
ssh "$host" "docker buildx build --build-arg INSTALL_DEBUG=1 --platform $platform -t bbilly1/tubearchivist:latest tubearchivist --load"
|
2022-05-07 11:33:16 +00:00
|
|
|
ssh "$host" 'docker compose -f docker/docker-compose.yml up -d'
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-22 05:03:52 +00:00
|
|
|
# run same tests and checks as with github action but locally
|
|
|
|
# takes filename to validate as optional argument
|
|
|
|
function validate {
|
|
|
|
|
|
|
|
if [[ $1 ]]; then
|
|
|
|
check_path="$1"
|
|
|
|
else
|
|
|
|
check_path="."
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "run validate on $check_path"
|
2022-01-22 10:52:13 +00:00
|
|
|
|
2022-10-26 02:43:58 +00:00
|
|
|
# note: this logic is duplicated in the `./github/workflows/lint_python.yml` config
|
|
|
|
# if you update this file, you should update that as well
|
2021-09-22 05:03:52 +00:00
|
|
|
echo "running black"
|
2023-06-22 16:28:06 +00:00
|
|
|
black --force-exclude "migrations/*" --diff --color --check -l 79 "$check_path"
|
2021-09-22 05:03:52 +00:00
|
|
|
echo "running codespell"
|
2023-06-22 16:28:06 +00:00
|
|
|
codespell --skip="./.git,./.venv,./package.json,./package-lock.json,./node_modules,./.mypy_cache" "$check_path"
|
2021-09-22 05:03:52 +00:00
|
|
|
echo "running flake8"
|
2023-06-22 16:28:06 +00:00
|
|
|
flake8 "$check_path" --exclude "migrations,.venv" --count --max-complexity=10 \
|
2023-02-02 07:19:06 +00:00
|
|
|
--max-line-length=79 --show-source --statistics
|
2021-09-22 05:03:52 +00:00
|
|
|
echo "running isort"
|
2023-06-22 16:28:06 +00:00
|
|
|
isort --skip "migrations" --skip ".venv" --check-only --diff --profile black -l 79 "$check_path"
|
2021-09-22 05:03:52 +00:00
|
|
|
printf " \n> all validations passed\n"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-31 07:47:19 +00:00
|
|
|
# update latest tag compatible es for set and forget
|
|
|
|
function sync_latest_es {
|
|
|
|
|
2022-04-15 10:46:16 +00:00
|
|
|
VERSION=$(grep "bbilly1/tubearchivist-es" docker-compose.yml | awk '{print $NF}')
|
|
|
|
printf "\nsync new ES version %s\nContinue?\n" "$VERSION"
|
|
|
|
read -rn 1
|
2022-03-31 07:47:19 +00:00
|
|
|
|
|
|
|
if [[ $(systemctl is-active docker) != 'active' ]]; then
|
|
|
|
echo "starting docker"
|
|
|
|
sudo systemctl start docker
|
|
|
|
fi
|
|
|
|
|
|
|
|
sudo docker image pull docker.elastic.co/elasticsearch/elasticsearch:"$VERSION"
|
|
|
|
|
|
|
|
sudo docker tag \
|
|
|
|
docker.elastic.co/elasticsearch/elasticsearch:"$VERSION" \
|
|
|
|
bbilly1/tubearchivist-es
|
|
|
|
|
|
|
|
sudo docker tag \
|
|
|
|
docker.elastic.co/elasticsearch/elasticsearch:"$VERSION" \
|
|
|
|
bbilly1/tubearchivist-es:"$VERSION"
|
|
|
|
|
|
|
|
sudo docker push bbilly1/tubearchivist-es
|
|
|
|
sudo docker push bbilly1/tubearchivist-es:"$VERSION"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-17 09:57:10 +00:00
|
|
|
# publish unstable tag to docker
|
2022-01-09 01:38:44 +00:00
|
|
|
function sync_unstable {
|
2021-12-17 09:57:10 +00:00
|
|
|
|
|
|
|
if [[ $(systemctl is-active docker) != 'active' ]]; then
|
|
|
|
echo "starting docker"
|
|
|
|
sudo systemctl start docker
|
|
|
|
fi
|
|
|
|
|
|
|
|
# start amd64 build
|
|
|
|
sudo docker buildx build \
|
|
|
|
--platform linux/amd64 \
|
|
|
|
-t bbilly1/tubearchivist:unstable --push .
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-04 04:16:46 +00:00
|
|
|
# new function, sync only tag, build with build server
|
2021-09-05 17:10:14 +00:00
|
|
|
function sync_docker {
|
|
|
|
|
2021-09-18 10:36:04 +00:00
|
|
|
# check things
|
|
|
|
if [[ $(git branch --show-current) != 'master' ]]; then
|
|
|
|
echo 'you are not on master, dummy!'
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2022-06-04 04:16:46 +00:00
|
|
|
echo "latest tags:"
|
|
|
|
git tag | tail -n 5 | sort -r
|
|
|
|
|
|
|
|
printf "\ncreate new version:\n"
|
|
|
|
read -r VERSION
|
|
|
|
|
|
|
|
echo "push new tag: $VERSION?"
|
|
|
|
read -rn 1
|
|
|
|
|
|
|
|
# create release tag
|
|
|
|
echo "commits since last version:"
|
|
|
|
git log "$(git describe --tags --abbrev=0)"..HEAD --oneline
|
|
|
|
git tag -a "$VERSION" -m "new release version $VERSION"
|
|
|
|
git push origin "$VERSION"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# old builder, sync tag, build and push locally
|
|
|
|
function sync_docker_old {
|
|
|
|
|
|
|
|
# check things
|
|
|
|
if [[ $(git branch --show-current) != 'master' ]]; then
|
|
|
|
echo 'you are not on master, dummy!'
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2021-09-05 17:10:14 +00:00
|
|
|
if [[ $(systemctl is-active docker) != 'active' ]]; then
|
|
|
|
echo "starting docker"
|
|
|
|
sudo systemctl start docker
|
|
|
|
fi
|
|
|
|
|
2021-09-18 10:36:04 +00:00
|
|
|
echo "latest tags:"
|
2022-06-04 04:16:46 +00:00
|
|
|
git tag | tail -n 5 | sort -r
|
2021-09-18 10:36:04 +00:00
|
|
|
|
|
|
|
printf "\ncreate new version:\n"
|
|
|
|
read -r VERSION
|
|
|
|
|
2021-10-17 06:29:22 +00:00
|
|
|
echo "build and push $VERSION?"
|
2021-09-22 11:11:05 +00:00
|
|
|
read -rn 1
|
2021-09-18 10:36:04 +00:00
|
|
|
|
2021-10-17 06:29:22 +00:00
|
|
|
# start build
|
|
|
|
sudo docker buildx build \
|
|
|
|
--platform linux/amd64,linux/arm64 \
|
2022-08-20 08:26:28 +00:00
|
|
|
-t bbilly1/tubearchivist \
|
|
|
|
-t bbilly1/tubearchivist:unstable \
|
2021-10-17 06:29:22 +00:00
|
|
|
-t bbilly1/tubearchivist:"$VERSION" --push .
|
2021-09-18 10:36:04 +00:00
|
|
|
|
|
|
|
# create release tag
|
|
|
|
echo "commits since last version:"
|
|
|
|
git log "$(git describe --tags --abbrev=0)"..HEAD --oneline
|
|
|
|
git tag -a "$VERSION" -m "new release version $VERSION"
|
2022-06-04 04:16:46 +00:00
|
|
|
git push origin "$VERSION"
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-09-18 10:36:04 +00:00
|
|
|
|
2021-09-05 17:10:14 +00:00
|
|
|
if [[ $1 == "blackhole" ]]; then
|
|
|
|
sync_blackhole
|
|
|
|
elif [[ $1 == "test" ]]; then
|
2021-10-13 12:34:55 +00:00
|
|
|
sync_test "$2"
|
2021-09-22 05:03:52 +00:00
|
|
|
elif [[ $1 == "validate" ]]; then
|
|
|
|
validate "$2"
|
2021-09-05 17:10:14 +00:00
|
|
|
elif [[ $1 == "docker" ]]; then
|
|
|
|
sync_docker
|
2021-12-17 09:57:10 +00:00
|
|
|
elif [[ $1 == "unstable" ]]; then
|
2022-01-09 01:38:44 +00:00
|
|
|
sync_unstable
|
2022-03-31 07:47:19 +00:00
|
|
|
elif [[ $1 == "es" ]]; then
|
|
|
|
sync_latest_es
|
2021-09-05 17:10:14 +00:00
|
|
|
else
|
2023-03-01 04:30:55 +00:00
|
|
|
echo "valid options are: blackhole | test | validate | docker | unstable | es"
|
2021-09-05 17:10:14 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
exit 0
|