diff --git a/.vscode/settings.json b/.vscode/settings.json index 14e7153..219cf49 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -144,5 +144,8 @@ "components/x-date-pickers/locales" ], "i18n-ally.keystyle": "nested", - "i18n-ally.sourceLanguage": "bg" + "i18n-ally.sourceLanguage": "bg", + "[shellscript]": { + "editor.defaultFormatter": "foxundermoon.shell-format" + } } \ No newline at end of file diff --git a/_deploy/deoloy.azure.production.yml b/_deploy/deoloy.azure.production.yml index 55a11d4..9e3a9af 100644 --- a/_deploy/deoloy.azure.production.yml +++ b/_deploy/deoloy.azure.production.yml @@ -9,6 +9,7 @@ services: # - "3000:3000" volumes: - /mnt/docker_volumes/pw/app/public/content/uploads/:/app/public/content/uploads + - /mnt/docker_volumes/pw/app/logs:/app/logs environment: - NODE_ENV=production - TZ=Europe/Sofia @@ -19,7 +20,7 @@ services: - GIT_USERNAME=deploy - GIT_PASSWORD=L3Kr2R438u4F7 - ADMIN_PASSWORD=changeme - command: sh -c " cd /app && npm install && npm run prod; tail -f /dev/null" + command: sh -c " cd /app && npm install && npx next build && npm run prod; tail -f /dev/null" #command: sh -c " cd /app && tail -f /dev/null" tty: true stdin_open: true @@ -56,15 +57,15 @@ services: networks: - infrastructure_default command: | - apk update && \ + "apk update && \ apk add --no-cache mariadb-client mariadb-connector-c && \ echo '0 2 * * * mysqldump -h $$MYSQL_HOST -P 3306 -u$$MYSQL_USER -p$$MYSQL_PASSWORD $$MYSQL_DATABASE > /backup/$$(date +\\%Y-\\%m-\\%d-\\%H\\%M\\%S)-$$MYSQL_DATABASE.sql' > /etc/crontabs/root && \ - echo '0 7 * * * rclone sync /backup nextcloud:/mwitnessing' >> /etc/crontabs/root && \ - crond -f -d 8 + crond -f -d 8" # wget -q https://github.com/prasmussen/gdrive/releases/download/2.1.0/gdrive-linux-x64 -O /usr/bin/gdrive && \ # chmod +x /usr/bin/gdrive && \ # gdrive about --service-account /root/.gdrive_service_account.json && \ - # echo '0 * * * * /usr/bin/mysqldump -h $$MYSQL_HOST -u$$MYSQL_USER -p$$MYSQL_PASSWORD $$MYSQL_DATABASE | gzip > /backup/$$(date +\\%Y-\\%m-\\%d-\\%H\\%M\\%S)-$$MYSQL_DATABASE.sql.gz && gdrive upload --parent $$GOOGLE_DRIVE_FOLDER_ID --service-account /root/.gdrive_service_account.json /backup/$$(date +\\%Y-\\%m-\\%d-\\%H\\%M\\%S)-$$MYSQL_DATABASE.sql.gz' > /etc/crontabs/root && crond -f -d 8" + # echo '0 * * * * /usr/bin/mysqldump -h $$MYSQL_HOST -u$$MYSQL_USER -p$$MYSQL_PASSWORD $$MYSQL_DATABASE | gzip > /backup/$$(date +\\%Y-\\%m-\\%d-\\%H\\%M\\%S)-$$MYSQL_DATABASE.sql.gz && gdrive upload --parent $$GOOGLE_DRIVE_FOLDER_ID --service-account /root/.gdrive_service_account.json /backup/$$(date +\\%Y-\\%m-\\%d-\\%H\\%M\\%S)-$$MYSQL_DATABASE.sql.gz' > /etc/crontabs/root && crond -f -d 8 \ + # echo '0 7 * * * rclone sync /backup nextcloud:/mwitnessing --delete-excluded ' >> /etc/crontabs/root && \" networks: infrastructure_default: external: true diff --git a/_deploy/entrypoint.sh b/_deploy/entrypoint.sh index db16b09..963c99f 100644 --- a/_deploy/entrypoint.sh +++ b/_deploy/entrypoint.sh @@ -3,18 +3,72 @@ if [ "$UPDATE_CODE_FROM_GIT" = "true" ]; then # Install necessary packages apk add git nano rsync - echo "Updating code from git.d-popov.com...(as '$GIT_USERNAME')" + echo "Updating code from git.d-popov.com...(as '$GIT_USERNAME')" > /app/logs/deploy.txt # Create a temporary directory for the new clone rm -rf /tmp/clone mkdir /tmp/clone + mkdir -p /app/logs + # Clear previous log + echo "Starting sync process at $(date)" > /app/logs/deploy.txt # Clone the repository - git clone -b ${GIT_BRANCH:-main} --depth 1 https://$GIT_USERNAME:${GIT_PASSWORD//@/%40}@git.d-popov.com/popov/mwitnessing.git /tmp/clone || exit 1 + echo "\r\n\r\n Cloning repository..." | tee -a logs/deploy.txt + git clone -b ${GIT_BRANCH:main} --depth 1 https://$GIT_USERNAME:${GIT_PASSWORD//@/%40}@git.d-popov.com/popov/mwitnessing.git /tmp/clone || exit 1 - # 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" + # Synchronize all files except package.json, package-lock.json, and the contents of /public/content + # rsync -av --filter='P /public/content/' --exclude 'package.json' --exclude 'package-lock.json' /tmp/clone/ /app/ || echo "Rsync failed: Issue synchronizing files" + echo "\r\n\r\n Synchronizing files..." + rsync -av /tmp/clone/_deploy/entrypoint.sh /app/entrypoint.sh || echo "Rsync failed: Issue copying entrypoint.sh" + + + # rsync -av --update --exclude '/public/content' --exclude 'package.json' --exclude 'package-lock.json' /tmp/clone/ /app/ || echo "Rsync failed: Issue synchronizing files" | tee -a /app/logs/deploy.txt + + + ######################################################################################## + if [ -d "/app/public/content/permits" ]; then + mv /app/public/content/permits /tmp/content/permits + echo "Permits folder backed up successfully." | tee -a /app/logs/deploy.txt + else + echo "Permits folder not found, skipping backup." | tee -a /app/logs/deploy.txt + fi + + # Run rsync with verbose output and itemize-changes + echo "Running rsync..." | tee -a /app/logs/deploy.txt + rsync -av --itemize-changes \ + --exclude='package.json' \ + --exclude='package-lock.json' \ + /tmp/clone/ /app/ >> /app/logs/deploy.txt 2>&1 + + # Check rsync exit status + if [ $? -ne 0 ]; then + echo "Rsync failed: Issue synchronizing files" | tee -a /app/logs/deploy.txt + cat /app/logs/deploy.txt # Display the log contents + else + echo "Rsync completed successfully" | tee -a /app/logs/deploy.txt + echo "Last few lines of rsync log:" | tee -a /app/logs/deploy.txt + tail -n 20 /app/logs/deploy.txt # Display the last 20 lines of the log + fi + + # Restore permits folder + echo "Restoring permits folder..." | tee -a /app/logs/deploy.txt + if [ -d "/tmp/content/permits" ]; then + # Ensure the destination directory exists + mkdir -p /app/public/content + mv /tmp/content/permits /app/public/content/permits + echo "Permits folder restored successfully." | tee -a /app/logs/deploy.txt + else + echo "No permits folder to restore." | tee -a /app/logs/deploy.txt + fi + + # Check contents after restoration + echo "Contents of /app/public/content after restoration:" >> /app/logs/deploy.txt + ls -la /app/public/content >> /app/logs/deploy.txt 2>&1 + ######################################################################################## + + + echo "\r\n\r\n Checking for changes in package files..." # 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 @@ -37,7 +91,7 @@ if [ "$UPDATE_CODE_FROM_GIT" = "true" ]; then npx next build # Clean up - rm -rf /tmp/clone + # rm -rf /tmp/clone echo "Update process completed." fi diff --git a/_deploy/entrypoint.staging.sh b/_deploy/entrypoint.staging.sh new file mode 100644 index 0000000..c1f53cb --- /dev/null +++ b/_deploy/entrypoint.staging.sh @@ -0,0 +1,43 @@ +# Check if the environment variable to update code from git is set to true +if [ "$UPDATE_CODE_FROM_GIT" = "true" ]; then + # Install necessary packages + apk add git nano rsync + echo "Updating code from git.d-popov.com...(as '$GIT_USERNAME')" + + # Remove the previous clone directory to ensure a fresh start + rm -rf /tmp/clone + mkdir /tmp/clone + + # Clone the specific branch of the new repository + git clone -b ${GIT_BRANCH:-main} --depth 1 https://$GIT_USERNAME:${GIT_PASSWORD//@/%40}@git.d-popov.com/popov/mwitnessing.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 + + # Use rsync to synchronize the files to /app, including deletion of files not in the source + rsync -av --delete --exclude '/public/content' /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 + + # Clean up the temporary clone directory + rm -rf /tmp/clone + + cd /app + echo "Installing packages in /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 + echo "Done cloning. Current Git Commit ID: $GIT_COMMIT_ID" + # Uncomment the following lines for production deployment + # npx next build + # npx next start +fi + +echo "Running the main process" +exec "$@" diff --git a/_deploy/new-lite/Dockerfile b/_deploy/new-lite/Dockerfile new file mode 100644 index 0000000..811d9b1 --- /dev/null +++ b/_deploy/new-lite/Dockerfile @@ -0,0 +1,19 @@ +FROM node:current-alpine + +# Install git and curl +RUN apk add --no-cache git curl + +# Set environment variables for repo and branch +# These will be overridden by docker-compose.yml +ENV REPO="" +ENV BRANCH="" + +# Create a directory for the app +WORKDIR /app + +# Download the entrypoint script +CMD git clone --depth 1 --branch $BRANCH $REPO /tmp/repo && \ + cp /tmp/repo/_deploy/entrypoint.sh /app/entrypoint.sh && \ + chmod +x /app/entrypoint.sh && \ + rm -rf /tmp/repo && \ + /app/entrypoint.sh \ No newline at end of file diff --git a/_doc/ToDo.md b/_doc/ToDo.md index 1bc87ef..8a37727 100644 --- a/_doc/ToDo.md +++ b/_doc/ToDo.md @@ -262,4 +262,12 @@ in schedule admin - if a publisher is always pair & family is not in the shift - [] allow blocking of inputs (different from publishing) TODO: fix to keep previous occurances when repeating evert week [] user - add createdAt field -[] FIX insecure logins \ No newline at end of file +[x] FIX insecure logins + +[] nove push to form, - reorganize pWAManager to have session, role, subscriptions, etc... +[] add shift name in calendar/ show in schedule if no assignments. +[] show unpublished schedule if admin + + + + diff --git a/_doc/notes.mb b/_doc/notes.mb index aab4534..1236258 100644 --- a/_doc/notes.mb +++ b/_doc/notes.mb @@ -25,8 +25,8 @@ apt install nodejs -y ##### ----------------- compose/deploy ----------------- ### # install docker if inside docker (vscode-server)# apt-get update && apt-get install -y docker.io -# .10 > /mnt/apps/DEV/SSS/next-cart-app/next-cart-app/ -#.11 > cd /mnt/storage/DEV/workspace/repos/git.d-popov.com/next-cart-app/next-cart-app +# !!! .10 > /mnt/apps/DEV/SSS/next-cart-app/next-cart-app/ +# !!! .11 > cd /mnt/storage/DEV/workspace/repos/git.d-popov.com/next-cart-app/next-cart-app # using dockerfile and image: docker build -t jwpw:latest -f _deploy/prod.Dockerfile . @@ -46,9 +46,9 @@ docker push docker.d-popov.com/jwpw:test --LATEST/ cd /mnt/storage/DEV/workspace/repos/git.d-popov.com/mwhitnessing docker build -t docker.d-popov.com/jwpw:latest -f _deploy/prod.Dockerfile . -docker tag docker.d-popov.com/jwpw:latest docker.d-popov.com/jwpw:0.9.95 +docker tag docker.d-popov.com/jwpw:latest docker.d-popov.com/jwpw:1.3.5 docker push docker.d-popov.com/jwpw:latest -docker push docker.d-popov.com/jwpw:0.9.95 +docker push docker.d-popov.com/jwpw:1.3.5 #--- @@ -221,7 +221,8 @@ curl https://gist.githubusercontent.com/balazsorban44/09613175e7b37ec03f676dcefb ################### sync folders # nc: WebDAV apk add rclone -rclone config +rclone config +/52 https://cloud.d-popov.com sync syncsyncsyncsyncsyncsyncsync rclone sync /path/to/local/folder yourRemoteName:target-folder # nc sudo add-apt-repository ppa:nextcloud-devs/client @@ -236,9 +237,11 @@ rclone config rclone lsd nextcloud: # {nc=remotename} rclone sync /path/to/local/folder gdrive:target-folder rclone sync /backup nextcloud:/mwitnessing [--dry-run] [--progress] -rclone sync /backup nextcloud:/mwitnessing --dry-run --progress +# pw-mariadb_backup-1 +rclone sync /backup nextcloud:/mwitnessing --dry-run --progress --delete-excluded +rclone sync /mnt/docker_volumes/pw/data/backup nc:/mwitnessing --dry-run --progress crontab -e -0 7 * * * rclone sync /backup nextcloud:/mwitnessing +0 7 * * * rclone sync /backup nextcloud:/mwitnessing --delete-excluded diff --git a/components/ErrorBoundary.tsx b/components/ErrorBoundary.tsx index 2dbbd89..87a148f 100644 --- a/components/ErrorBoundary.tsx +++ b/components/ErrorBoundary.tsx @@ -27,7 +27,7 @@ class ErrorBoundary extends React.Component { render() { if (this.state.hasError) { // Render any custom fallback UI - return