|
| 1 | +#!/bin/bash |
| 2 | +############################################################################### |
| 3 | +# |
| 4 | +# Copyright (C) 2025 Tom Kralidis |
| 5 | +# |
| 6 | +# This program is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU General Public License as published by |
| 8 | +# the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# This program is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU General Public License |
| 17 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | +# |
| 19 | +############################################################################### |
| 20 | + |
| 21 | +# Configuration |
| 22 | +BASEDIR="/data/web/msc-wis2node-nightly" |
| 23 | +MSC_WIS2NODE="https://github.com/ECCC-MSC/msc-wis2node.git" |
| 24 | +DAYSTOKEEP=7 |
| 25 | + |
| 26 | +# Derived variables |
| 27 | +DATETIME=$(date +%Y%m%d) |
| 28 | +TIMESTAMP=$(date +%Y%m%d.%H%M) |
| 29 | +NIGHTLYDIR="msc-wis2node-$TIMESTAMP" |
| 30 | + |
| 31 | +echo "### Deleting nightly builds older than $DAYSTOKEEP days ###" |
| 32 | + |
| 33 | +# Ensure base directory exists |
| 34 | +if [[ ! -d $BASEDIR ]]; then |
| 35 | + echo "Error: Base directory $BASEDIR does not exist." |
| 36 | + exit 1 |
| 37 | +fi |
| 38 | + |
| 39 | +cd "$BASEDIR" || exit |
| 40 | + |
| 41 | +# Find and delete old directories |
| 42 | +find . -type d -name "msc-wis2node-20*" -mtime +$DAYSTOKEEP -exec rm -rf {} \; \ |
| 43 | + && echo "Deleted directories older than $DAYSTOKEEP days." |
| 44 | + |
| 45 | +# Remove the `latest` symlink |
| 46 | +if [[ -L latest ]]; then |
| 47 | + rm -f latest && echo "Removed old 'latest' symlink." |
| 48 | +fi |
| 49 | + |
| 50 | +echo "### Generating nightly build for $TIMESTAMP ###" |
| 51 | + |
| 52 | +# Create and navigate to the new nightly build directory |
| 53 | +mkdir "$NIGHTLYDIR" && cd "$NIGHTLYDIR" || exit |
| 54 | + |
| 55 | +# Clone the repository |
| 56 | +echo "Cloning Git repository from $MSC_WIS2NODE..." |
| 57 | +if git clone "$MSC_WIS2NODE" --depth=1; then |
| 58 | + echo "Git repository cloned successfully." |
| 59 | +else |
| 60 | + echo "Error: Failed to clone repository." |
| 61 | + exit 1 |
| 62 | +fi |
| 63 | + |
| 64 | +# cd into cloned repository directory |
| 65 | +cd "$(basename "$MSC_WIS2NODE" .git)" || exit |
| 66 | + |
| 67 | +cp $BASEDIR/msc-wis2node.env . |
| 68 | +chmod 400 msc-wis2node.env |
| 69 | + |
| 70 | +# Docker operations |
| 71 | +echo "Stopping, building, and starting Docker setup..." |
| 72 | +make force-build |
| 73 | +make down |
| 74 | +make up |
| 75 | + |
| 76 | +# Navigate back to base directory |
| 77 | +cd "$BASEDIR" || exit |
| 78 | + |
| 79 | +# Create the 'latest' symlink |
| 80 | +ln -s "$NIGHTLYDIR" latest && echo "Symlink 'latest' created for $NIGHTLYDIR." |
| 81 | + |
| 82 | +echo "### Nightly build process completed successfully ###" |
0 commit comments