try to fix deploy issue

This commit is contained in:
Dobromir Popov
2024-02-23 21:47:49 +02:00
parent 9b8fe36155
commit 4f631caef0
2 changed files with 21 additions and 37 deletions

View File

@ -5,56 +5,41 @@ if [ "$UPDATE_CODE_FROM_GIT" = "true" ]; then
apk add git nano rsync
echo "Updating code from git.d-popov.com...(as '$GIT_USERNAME')"
# Check for the current Git commit ID in the local copy
CURRENT_GIT_COMMIT_ID=$(git -C /app rev-parse HEAD 2>/dev/null)
# Remove the previous clone directory to ensure a fresh start
# Create a temporary directory for the new clone
rm -rf /tmp/clone
mkdir /tmp/clone
# Clone the specific branch of the new repository
# Clone the repository
git clone -b ${GIT_BRANCH:-main} --depth 1 https://$GIT_USERNAME:${GIT_PASSWORD//@/%40}@git.d-popov.com/popov/mwhitnessing.git /tmp/clone || exit 1
# Fetch the latest commit ID and message from the cloned repository
GIT_COMMIT_ID=$(git -C /tmp/clone rev-parse HEAD)
LAST_COMMIT_MESSAGE=$(git -C /tmp/clone log -1 --pretty=%B)
echo "Current Git Commit: $LAST_COMMIT_MESSAGE: $GIT_COMMIT_ID"
export GIT_COMMIT_ID
# Check if the current commit ID matches the latest commit ID
if [ "$CURRENT_GIT_COMMIT_ID" != "$GIT_COMMIT_ID" ]; then
echo "Detected changes in the repository, updating /app..."
# Synchronize all files except package.json and package-lock.json to /app
rsync -av --delete --exclude 'package.json' --exclude 'package-lock.json' /tmp/clone/ /app/ || echo "Rsync failed: Issue synchronizing files"
# Use rsync to synchronize the files to /app, including deletion of files not in the source
rsync -av --delete /tmp/clone/ /app/ || echo "Rsync failed: Issue synchronizing files"
# Copy .env files
rsync -av /tmp/clone/.env* /app/ || echo "Rsync failed: Issue copying .env files"
# Copy the entrypoint.sh if exists in the new structure
[ -f /tmp/clone/entrypoint.sh ] && rsync -av /tmp/clone/entrypoint.sh /app/entrypoint.sh || echo "Rsync failed: Issue copying entrypoint.sh"
chmod +x /app/entrypoint.sh
# Determine if package.json or package-lock.json has changed
PACKAGE_CHANGE=0
if ! cmp -s /tmp/clone/package.json /app/package.json || ! cmp -s /tmp/clone/package-lock.json /app/package-lock.json; then
PACKAGE_CHANGE=1
fi
# Delete and reinstall node_modules if there are changes
echo "Deleting and reinstalling node_modules..."
# If package.json or package-lock.json has changed, copy them and reinstall node_modules
if [ "$PACKAGE_CHANGE" -eq 1 ]; then
echo "Package files have changed. Updating packages..."
rsync -av /tmp/clone/package.json /app/package.json || echo "Rsync failed: Issue copying package.json"
rsync -av /tmp/clone/package-lock.json /app/package-lock.json || echo "Rsync failed: Issue copying package-lock.json"
rm -rf /app/node_modules
cd /app
npm install --no-audit --no-fund --no-optional --omit=optional
yes | npx prisma generate
# Uncomment the next line if database migrations are necessary
# npx prisma migrate deploy
else
echo "No changes detected in the repository. Skipping update."
echo "Package files have not changed. Skipping package installation."
fi
# Clean up the temporary clone directory
rm -rf /tmp/clone
echo "Done cloning. Current Git Commit ID: $GIT_COMMIT_ID"
# Uncomment the following lines for production deployment
# npx next build
# npx next start
else
echo "UPDATE_CODE_FROM_GIT is not set to true. Skipping update."
# Clean up
rm -rf /tmp/clone
echo "Update process completed."
fi
echo "Running the main process"
exec "$@"