aboutsummaryrefslogtreecommitdiff
path: root/build.sh
diff options
context:
space:
mode:
Diffstat (limited to 'build.sh')
-rwxr-xr-xbuild.sh146
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
4REGISTRY="git.d464.sh"
5NAMESPACE="diogo464"
6IMAGE_NAME="bonsai-web"
7FULL_IMAGE_NAME="${REGISTRY}/${NAMESPACE}/${IMAGE_NAME}"
8
9# Get version from git tag or use 'latest'
10VERSION=$(git describe --tags --exact-match 2>/dev/null || echo "latest")
11
12# Check if we should push to registry
13SHOULD_PUSH=${PUSH:-0}
14
15# Colors for output
16RED='\033[0;31m'
17GREEN='\033[0;32m'
18YELLOW='\033[1;33m'
19BLUE='\033[0;34m'
20NC='\033[0m' # No Color
21
22# Logging functions
23log_info() {
24 echo -e "${BLUE}[INFO]${NC} $1"
25}
26
27log_success() {
28 echo -e "${GREEN}[SUCCESS]${NC} $1"
29}
30
31log_warning() {
32 echo -e "${YELLOW}[WARNING]${NC} $1"
33}
34
35log_error() {
36 echo -e "${RED}[ERROR]${NC} $1"
37}
38
39# Error handler
40handle_error() {
41 log_error "Script failed at line $1"
42 exit 1
43}
44
45trap 'handle_error $LINENO' ERR
46set -e
47
48if [[ "$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}"
52else
53 log_info "Starting container build process (local only)..."
54 log_info "Image: ${IMAGE_NAME}"
55fi
56log_info "Version: ${VERSION}"
57
58# Check if podman is available
59if ! command -v podman &> /dev/null; then
60 log_error "podman is not installed or not in PATH"
61 exit 1
62fi
63
64# Check if we're in the right directory
65if [[ ! -f "Containerfile" ]]; then
66 log_error "Containerfile not found. Please run this script from the project root."
67 exit 1
68fi
69
70# Check if we're logged into the registry (only if pushing)
71if [[ "$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
78fi
79
80# Build the container image
81log_info "Building container image..."
82if [[ "$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 .
90else
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 .
98fi
99
100log_success "Container image built successfully"
101
102if [[ "$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
114fi
115
116# Display final information
117echo
118if [[ "$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}"
131else
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"
146fi \ No newline at end of file