mirror of
https://github.com/darksaid98/yolks.git
synced 2026-12-04 06:29:00 +00:00
feat(graalvm): update git code in entrypoint
This commit is contained in:
1 file changed
+61
-44
+61
-44
@@ -33,56 +33,73 @@ export INTERNAL_IP
|
|||||||
# Switch to the container's working directory
|
# Switch to the container's working directory
|
||||||
cd /home/container || exit 1
|
cd /home/container || exit 1
|
||||||
|
|
||||||
# Update repo from git
|
# Auto update server from git.
|
||||||
if [ "${GIT_ENABLED}" == "false" ] || [ "${GIT_ENABLED}" == "0" ]; then
|
if [ "${GIT_ENABLED}" == "true" ] || [ "${GIT_ENABLED}" == "1" ]; then
|
||||||
echo -e "Git enabled."
|
|
||||||
|
|
||||||
## add git ending if it's not on the address
|
# Pre git stuff
|
||||||
if [[ ${GIT_ADDRESS} != *.git ]]; then
|
echo "Wait, preparing to pull or clone from git."
|
||||||
GIT_ADDRESS=${GIT_ADDRESS}.git
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "${GIT_USERNAME}" ] && [ -z "${GIT_ACCESS_TOKEN}" ]; then
|
mkdir -p /home/container
|
||||||
echo -e "Git Username or Git Token was not specified. Proceeding anonymously."
|
cd /home/container
|
||||||
else
|
|
||||||
GIT_ADDRESS="https://${GIT_USERNAME}:${GIT_ACCESS_TOKEN}@$(echo -e ${GIT_ADDRESS} | cut -d/ -f3-)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
# Git stuff
|
||||||
|
if [[ ${GIT_REPOURL} != *.git ]]; then # Add .git at end of URL
|
||||||
|
GIT_REPOURL=${GIT_REPOURL}.git
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$(ls -A /home/container)" ]; then
|
if [ -z "${GIT_USERNAME}" ] && [ -z "${GIT_TOKEN}" ]; then # Check for git username & token
|
||||||
echo -e "/home/container directory is not empty."
|
echo -e "git Username or git Token was not specified."
|
||||||
|
else
|
||||||
|
GIT_REPOURL="https://${GIT_USERNAME}:${GIT_TOKEN}@$(echo -e ${GIT_REPOURL} | cut -d/ -f3-)"
|
||||||
|
fi
|
||||||
|
|
||||||
# Get git origin from /home/container/.git/config
|
if [ "$(ls -A /home/container)" ]; then # Files exist in server folder, pull
|
||||||
if [ -d .git ]; then
|
echo -e "Files exist in /home/container/. Attempting to pull from git repository."
|
||||||
echo -e ".git directory exists"
|
|
||||||
if [ -f .git/config ]; then
|
|
||||||
echo -e "loading info from git config"
|
|
||||||
ORIGIN=$(git config --get remote.origin.url)
|
|
||||||
else
|
|
||||||
echo -e "files found with no git config"
|
|
||||||
echo -e "closing out without touching things to not break anything"
|
|
||||||
exit 10
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If git origin matches the repo specified by user then pull
|
# Get git origin from /home/container/.git/config
|
||||||
if [ "${ORIGIN}" == "${GIT_ADDRESS}" ]; then
|
if [ -d .git ]; then
|
||||||
echo "pulling latest from github"
|
if [ -f .git/config ]; then
|
||||||
git pull && echo "Finished pulling /home/container from Git." || echo "Failed pulling /home/container from Git."
|
GIT_ORIGIN=$(git config --get remote.origin.url)
|
||||||
fi
|
fi
|
||||||
else
|
fi
|
||||||
# No files exist in resources folder, clone
|
|
||||||
echo -e "/home/container is empty.\ncloning files into repo"
|
# Check if we have a shallow clone and need to maintain it
|
||||||
if [ -z ${GIT_BRANCH} ]; then
|
is_shallow=$(git rev-parse --is-shallow-repository 2>/dev/null || echo "false")
|
||||||
echo -e "Cloning default branch into /home/container."
|
|
||||||
git clone ${GIT_ADDRESS} .
|
# If git origin matches the repo specified by user then pull
|
||||||
else
|
if [ "${GIT_ORIGIN}" == "${GIT_REPOURL}" ]; then
|
||||||
echo -e "Cloning ${GIT_BRANCH} branch into /home/container."
|
# Override local changes
|
||||||
git clone --single-branch --branch ${GIT_BRANCH} ${GIT_ADDRESS} . && echo "Finished cloning into /home/container from Git." || echo "Failed cloning into /home/container from Git."
|
echo "Overriding local changes..."
|
||||||
fi
|
git clean -fd
|
||||||
fi
|
|
||||||
else
|
# Fetch latest changes (shallow if original clone was shallow)
|
||||||
echo -e "Git disabled."
|
echo "Fetching latest changes..."
|
||||||
|
if [ "$is_shallow" = "true" ]; then
|
||||||
|
git fetch --depth 1 origin "${GIT_BRANCH}" && echo "Finished fetching /home/container/ from git." || echo "Failed fetching /home/container/ from git."
|
||||||
|
else
|
||||||
|
git fetch origin "${GIT_BRANCH}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Force reset to match remote branch (this will override any local edits)
|
||||||
|
echo "Updating to match remote branch..."
|
||||||
|
git reset --hard "origin/${GIT_BRANCH}" && echo "Finished updating /home/container/ from git." || echo "Failed updating /home/container/ from git."
|
||||||
|
else
|
||||||
|
echo -e "git repository in /home/container/ does not match user provided configuration. Failed pulling /home/container/ from git."
|
||||||
|
fi
|
||||||
|
else # No files exist in server folder, clone
|
||||||
|
echo -e "Server directory is empty. Attempting to clone git repository."
|
||||||
|
|
||||||
|
if [ -z ${GIT_BRANCH} ]; then
|
||||||
|
echo -e "Cloning default branch into /home/container/."
|
||||||
|
git clone --single-branch --depth 1 ${GIT_REPOURL} . && echo "Finished cloning into /home/container/ from git." || echo "Failed cloning into /home/container/ from git."
|
||||||
|
else
|
||||||
|
echo -e "Cloning ${GIT_BRANCH} branch into /home/container/."
|
||||||
|
git clone --single-branch --branch ${GIT_BRANCH} --depth 1 ${GIT_REPOURL} . && echo "Finished cloning into /home/container/ from git." || echo "Failed cloning into /home/container/ from git."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Post git stuff
|
||||||
|
cd /home/container
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Print Java version
|
# Print Java version
|
||||||
|
|||||||
Reference in new issue
Block a user