diff options
| author | diogo464 <[email protected]> | 2025-07-20 18:59:09 +0100 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2025-07-20 18:59:09 +0100 |
| commit | f001c54c26f3f010a41ea107fd6fd5fbd0e55baa (patch) | |
| tree | 780e301cd31c36e1290e455a9b5b8e19e7394597 /build.sh | |
| parent | 059f767d00bbe7ca569d658b1cb14fcb17105bcd (diff) | |
added Justfile to replace build.sh
Diffstat (limited to 'build.sh')
| -rwxr-xr-x | build.sh | 146 |
1 files changed, 0 insertions, 146 deletions
diff --git a/build.sh b/build.sh deleted file mode 100755 index df3d28a..0000000 --- a/build.sh +++ /dev/null | |||
| @@ -1,146 +0,0 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | # Container registry configuration | ||
| 4 | REGISTRY="git.d464.sh" | ||
| 5 | NAMESPACE="diogo464" | ||
| 6 | IMAGE_NAME="bonsai-web" | ||
| 7 | FULL_IMAGE_NAME="${REGISTRY}/${NAMESPACE}/${IMAGE_NAME}" | ||
| 8 | |||
| 9 | # Get version from git tag or use 'latest' | ||
| 10 | VERSION=$(git describe --tags --exact-match 2>/dev/null || echo "latest") | ||
| 11 | |||
| 12 | # Check if we should push to registry | ||
| 13 | SHOULD_PUSH=${PUSH:-0} | ||
| 14 | |||
| 15 | # Colors for output | ||
| 16 | RED='\033[0;31m' | ||
| 17 | GREEN='\033[0;32m' | ||
| 18 | YELLOW='\033[1;33m' | ||
| 19 | BLUE='\033[0;34m' | ||
| 20 | NC='\033[0m' # No Color | ||
| 21 | |||
| 22 | # Logging functions | ||
| 23 | log_info() { | ||
| 24 | echo -e "${BLUE}[INFO]${NC} $1" | ||
| 25 | } | ||
| 26 | |||
| 27 | log_success() { | ||
| 28 | echo -e "${GREEN}[SUCCESS]${NC} $1" | ||
| 29 | } | ||
| 30 | |||
| 31 | log_warning() { | ||
| 32 | echo -e "${YELLOW}[WARNING]${NC} $1" | ||
| 33 | } | ||
| 34 | |||
| 35 | log_error() { | ||
| 36 | echo -e "${RED}[ERROR]${NC} $1" | ||
| 37 | } | ||
| 38 | |||
| 39 | # Error handler | ||
| 40 | handle_error() { | ||
| 41 | log_error "Script failed at line $1" | ||
| 42 | exit 1 | ||
| 43 | } | ||
| 44 | |||
| 45 | trap 'handle_error $LINENO' ERR | ||
| 46 | set -e | ||
| 47 | |||
| 48 | if [[ "$SHOULD_PUSH" == "1" ]]; then | ||
| 49 | log_info "Starting container build and push process..." | ||
| 50 | log_info "Registry: ${REGISTRY}" | ||
| 51 | log_info "Image: ${FULL_IMAGE_NAME}" | ||
| 52 | else | ||
| 53 | log_info "Starting container build process (local only)..." | ||
| 54 | log_info "Image: ${IMAGE_NAME}" | ||
| 55 | fi | ||
| 56 | log_info "Version: ${VERSION}" | ||
| 57 | |||
| 58 | # Check if podman is available | ||
| 59 | if ! command -v podman &> /dev/null; then | ||
| 60 | log_error "podman is not installed or not in PATH" | ||
| 61 | exit 1 | ||
| 62 | fi | ||
| 63 | |||
| 64 | # Check if we're in the right directory | ||
| 65 | if [[ ! -f "Containerfile" ]]; then | ||
| 66 | log_error "Containerfile not found. Please run this script from the project root." | ||
| 67 | exit 1 | ||
| 68 | fi | ||
| 69 | |||
| 70 | # Check if we're logged into the registry (only if pushing) | ||
| 71 | if [[ "$SHOULD_PUSH" == "1" ]]; then | ||
| 72 | log_info "Checking registry authentication..." | ||
| 73 | if ! podman login --get-login "${REGISTRY}" &> /dev/null; then | ||
| 74 | log_warning "Not logged into ${REGISTRY}. Please login first:" | ||
| 75 | echo "podman login ${REGISTRY}" | ||
| 76 | exit 1 | ||
| 77 | fi | ||
| 78 | fi | ||
| 79 | |||
| 80 | # Build the container image | ||
| 81 | log_info "Building container image..." | ||
| 82 | if [[ "$SHOULD_PUSH" == "1" ]]; then | ||
| 83 | # Build with registry tags for pushing | ||
| 84 | podman build \ | ||
| 85 | -f Containerfile \ | ||
| 86 | -t "${FULL_IMAGE_NAME}:${VERSION}" \ | ||
| 87 | -t "${FULL_IMAGE_NAME}:latest" \ | ||
| 88 | -t "${IMAGE_NAME}:local" \ | ||
| 89 | . | ||
| 90 | else | ||
| 91 | # Build with local tags only | ||
| 92 | podman build \ | ||
| 93 | -f Containerfile \ | ||
| 94 | -t "${IMAGE_NAME}:${VERSION}" \ | ||
| 95 | -t "${IMAGE_NAME}:latest" \ | ||
| 96 | -t "${IMAGE_NAME}:local" \ | ||
| 97 | . | ||
| 98 | fi | ||
| 99 | |||
| 100 | log_success "Container image built successfully" | ||
| 101 | |||
| 102 | if [[ "$SHOULD_PUSH" == "1" ]]; then | ||
| 103 | # Push the versioned tag | ||
| 104 | log_info "Pushing ${FULL_IMAGE_NAME}:${VERSION}..." | ||
| 105 | podman push "${FULL_IMAGE_NAME}:${VERSION}" | ||
| 106 | log_success "Pushed ${FULL_IMAGE_NAME}:${VERSION}" | ||
| 107 | |||
| 108 | # Push the latest tag (only if version is not 'latest') | ||
| 109 | if [[ "${VERSION}" != "latest" ]]; then | ||
| 110 | log_info "Pushing ${FULL_IMAGE_NAME}:latest..." | ||
| 111 | podman push "${FULL_IMAGE_NAME}:latest" | ||
| 112 | log_success "Pushed ${FULL_IMAGE_NAME}:latest" | ||
| 113 | fi | ||
| 114 | fi | ||
| 115 | |||
| 116 | # Display final information | ||
| 117 | echo | ||
| 118 | if [[ "$SHOULD_PUSH" == "1" ]]; then | ||
| 119 | log_success "Build and push completed successfully!" | ||
| 120 | echo | ||
| 121 | echo "Image details:" | ||
| 122 | echo " Registry: ${REGISTRY}" | ||
| 123 | echo " Full name: ${FULL_IMAGE_NAME}" | ||
| 124 | echo " Version: ${VERSION}" | ||
| 125 | echo | ||
| 126 | echo "To run the container:" | ||
| 127 | echo " podman run -p 5000:5000 ${FULL_IMAGE_NAME}:${VERSION}" | ||
| 128 | echo | ||
| 129 | echo "To pull on another machine:" | ||
| 130 | echo " podman pull ${FULL_IMAGE_NAME}:${VERSION}" | ||
| 131 | else | ||
| 132 | log_success "Local build completed!" | ||
| 133 | echo | ||
| 134 | echo "Image details:" | ||
| 135 | echo " Name: ${IMAGE_NAME}" | ||
| 136 | echo " Version: ${VERSION}" | ||
| 137 | echo | ||
| 138 | echo "To run the container:" | ||
| 139 | echo " podman run -p 5000:5000 ${IMAGE_NAME}:${VERSION}" | ||
| 140 | echo | ||
| 141 | echo "To test the container:" | ||
| 142 | echo " podman run --rm -p 5000:5000 ${IMAGE_NAME}:${VERSION}" | ||
| 143 | echo | ||
| 144 | echo "To push to registry:" | ||
| 145 | echo " PUSH=1 $0" | ||
| 146 | fi \ No newline at end of file | ||
