add more complete examples
This commit is contained in:
parent
b98c99fe72
commit
a19ce85dfe
|
@ -1,13 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# These environment variables are set by the caller
|
|
||||||
my_envs='GIT_REF_NAME
|
|
||||||
GIT_REF_TYPE
|
|
||||||
GIT_REPO_ID
|
|
||||||
GIT_REPO_OWNER
|
|
||||||
GIT_REPO_NAME
|
|
||||||
GIT_CLONE_URL'
|
|
||||||
|
|
||||||
# The directory of this bash script
|
# The directory of this bash script
|
||||||
base_dir="$(dirname "$(readlink -f "$0")")"
|
base_dir="$(dirname "$(readlink -f "$0")")"
|
||||||
|
|
||||||
|
@ -15,10 +7,33 @@ if [[ -f "${base_dir}/${GIT_REPO_ID}/deploy.sh" ]]
|
||||||
then
|
then
|
||||||
echo "Running deplay script for ${GIT_REPO_ID}"
|
echo "Running deplay script for ${GIT_REPO_ID}"
|
||||||
bash "${base_dir}/${GIT_REPO_ID}/deploy.sh"
|
bash "${base_dir}/${GIT_REPO_ID}/deploy.sh"
|
||||||
else
|
exit 0
|
||||||
echo "Nothing to do for ${GIT_REPO_ID}"
|
|
||||||
for x in $my_envs; do
|
|
||||||
echo "$x=${!x}"
|
|
||||||
done
|
|
||||||
sleep 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Nothing to do for ${GIT_REPO_ID}"
|
||||||
|
echo ""
|
||||||
|
echo "Want to set it up? Try this:"
|
||||||
|
echo " mkdir -p ${base_dir}/${GIT_REPO_ID}"
|
||||||
|
echo " rsync -av ${base_dir}/git.example.com/org/project/ ${base_dir}/${GIT_REPO_ID}/"
|
||||||
|
echo ""
|
||||||
|
echo "Then edit the example deploy.sh to do what you need."
|
||||||
|
echo " vim ${base_dir}/${GIT_REPO_ID}/deploy.sh"
|
||||||
|
echo ""
|
||||||
|
echo "You may also like to take a look at the Go, Node.js, and other starter templates:"
|
||||||
|
echo " ls ${base_dir}/git.example.com/org/"
|
||||||
|
echo ""
|
||||||
|
echo "You can use any of these ENVs in your deploy script:"
|
||||||
|
|
||||||
|
# These environment variables are set by the caller
|
||||||
|
my_envs='GIT_REF_NAME
|
||||||
|
GIT_REF_TYPE
|
||||||
|
GIT_REPO_ID
|
||||||
|
GIT_REPO_OWNER
|
||||||
|
GIT_REPO_NAME
|
||||||
|
GIT_CLONE_URL'
|
||||||
|
for x in $my_envs; do
|
||||||
|
echo "$x=${!x}"
|
||||||
|
done
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -u
|
||||||
|
|
||||||
|
if [[ "${GIT_REF_NAME}" != "master" ]]
|
||||||
|
then
|
||||||
|
echo "Nothing to do for ${GIT_REPO_ID}#${GIT_REF_NAME}"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Deploying ${GIT_REPO_ID}#${GIT_REF_NAME} ..."
|
||||||
|
|
||||||
|
# See the Git Credentials Cheat Sheet
|
||||||
|
# https://coolaj86.com/articles/vanilla-devops-git-credentials-cheatsheet/
|
||||||
|
my_tmp="$(mktemp -d -t "tmp.XXXXXXXXXX")"
|
||||||
|
git clone --depth=1 "${GIT_CLONE_URL}" -b "${GIT_REF_NAME}" "${my_tmp}/${GIT_REPO_NAME}"
|
||||||
|
pushd "${my_tmp}/${GIT_REPO_NAME}/"
|
||||||
|
go generate -mod=vendor ./...
|
||||||
|
go build -mod=vendor .
|
||||||
|
|
||||||
|
mkdir -p ~/.local/bin/
|
||||||
|
rsync -av ./${GIT_REPO_NAME} ~/.local/bin/
|
||||||
|
|
||||||
|
sudo systemctl restart ${GIT_REPO_NAME}
|
||||||
|
popd
|
||||||
|
|
||||||
|
rm -rf "${my_tmp}/${GIT_REPO_NAME}/"
|
|
@ -0,0 +1,31 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -u
|
||||||
|
|
||||||
|
if [[ "${GIT_REF_NAME}" != "master" ]]
|
||||||
|
then
|
||||||
|
echo "Nothing to do for ${GIT_REPO_ID}#${GIT_REF_NAME}"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Deploying ${GIT_REPO_ID}#${GIT_REF_NAME} ..."
|
||||||
|
|
||||||
|
# See the Git Credentials Cheat Sheet
|
||||||
|
# https://coolaj86.com/articles/vanilla-devops-git-credentials-cheatsheet/
|
||||||
|
my_tmp="$(mktemp -d -t "tmp.XXXXXXXXXX")"
|
||||||
|
git clone --depth=1 "${GIT_CLONE_URL}" -b "${GIT_REF_NAME}" "${my_tmp}/${GIT_REPO_NAME}"
|
||||||
|
pushd "${my_tmp}/${GIT_REPO_NAME}"
|
||||||
|
# Uncomment this if you have git submodules:
|
||||||
|
#git submodule init
|
||||||
|
#git submodule update
|
||||||
|
|
||||||
|
npm ci
|
||||||
|
npm run build
|
||||||
|
|
||||||
|
rsync -avP ./ ~/srv/${GIT_REPO_NAME}/
|
||||||
|
|
||||||
|
# See the Serviceman Cheat Sheet for how to set up a system service
|
||||||
|
# https://webinstall.dev/serviceman
|
||||||
|
sudo systemctl restart ${GIT_REPO_NAME}
|
||||||
|
popd
|
||||||
|
|
||||||
|
rm -rf "${my_tmp}/${GIT_REPO_NAME}/"
|
Loading…
Reference in New Issue