From f001c54c26f3f010a41ea107fd6fd5fbd0e55baa Mon Sep 17 00:00:00 2001 From: diogo464 Date: Sun, 20 Jul 2025 18:59:09 +0100 Subject: added Justfile to replace build.sh --- Justfile | 17 ++++++++ build.sh | 146 --------------------------------------------------------------- 2 files changed, 17 insertions(+), 146 deletions(-) create mode 100644 Justfile delete mode 100755 build.sh diff --git a/Justfile b/Justfile new file mode 100644 index 0000000..75c6e6b --- /dev/null +++ b/Justfile @@ -0,0 +1,17 @@ +image := 'cr.d464.sh/bonsai-web:latest' + +_default: + just --list + +start: stop + docker run --rm -itd --name bonsai-web -p 5000:5000 {{image}} + echo "container started on port 5000" + +stop: + docker stop bonsai-web || true + +build: + docker build -f Containerfile -t {{image}} . + +push: build + docker push {{image}} diff --git a/build.sh b/build.sh deleted file mode 100755 index df3d28a..0000000 --- a/build.sh +++ /dev/null @@ -1,146 +0,0 @@ -#!/bin/bash - -# Container registry configuration -REGISTRY="git.d464.sh" -NAMESPACE="diogo464" -IMAGE_NAME="bonsai-web" -FULL_IMAGE_NAME="${REGISTRY}/${NAMESPACE}/${IMAGE_NAME}" - -# Get version from git tag or use 'latest' -VERSION=$(git describe --tags --exact-match 2>/dev/null || echo "latest") - -# Check if we should push to registry -SHOULD_PUSH=${PUSH:-0} - -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -BLUE='\033[0;34m' -NC='\033[0m' # No Color - -# Logging functions -log_info() { - echo -e "${BLUE}[INFO]${NC} $1" -} - -log_success() { - echo -e "${GREEN}[SUCCESS]${NC} $1" -} - -log_warning() { - echo -e "${YELLOW}[WARNING]${NC} $1" -} - -log_error() { - echo -e "${RED}[ERROR]${NC} $1" -} - -# Error handler -handle_error() { - log_error "Script failed at line $1" - exit 1 -} - -trap 'handle_error $LINENO' ERR -set -e - -if [[ "$SHOULD_PUSH" == "1" ]]; then - log_info "Starting container build and push process..." - log_info "Registry: ${REGISTRY}" - log_info "Image: ${FULL_IMAGE_NAME}" -else - log_info "Starting container build process (local only)..." - log_info "Image: ${IMAGE_NAME}" -fi -log_info "Version: ${VERSION}" - -# Check if podman is available -if ! command -v podman &> /dev/null; then - log_error "podman is not installed or not in PATH" - exit 1 -fi - -# Check if we're in the right directory -if [[ ! -f "Containerfile" ]]; then - log_error "Containerfile not found. Please run this script from the project root." - exit 1 -fi - -# Check if we're logged into the registry (only if pushing) -if [[ "$SHOULD_PUSH" == "1" ]]; then - log_info "Checking registry authentication..." - if ! podman login --get-login "${REGISTRY}" &> /dev/null; then - log_warning "Not logged into ${REGISTRY}. Please login first:" - echo "podman login ${REGISTRY}" - exit 1 - fi -fi - -# Build the container image -log_info "Building container image..." -if [[ "$SHOULD_PUSH" == "1" ]]; then - # Build with registry tags for pushing - podman build \ - -f Containerfile \ - -t "${FULL_IMAGE_NAME}:${VERSION}" \ - -t "${FULL_IMAGE_NAME}:latest" \ - -t "${IMAGE_NAME}:local" \ - . -else - # Build with local tags only - podman build \ - -f Containerfile \ - -t "${IMAGE_NAME}:${VERSION}" \ - -t "${IMAGE_NAME}:latest" \ - -t "${IMAGE_NAME}:local" \ - . -fi - -log_success "Container image built successfully" - -if [[ "$SHOULD_PUSH" == "1" ]]; then - # Push the versioned tag - log_info "Pushing ${FULL_IMAGE_NAME}:${VERSION}..." - podman push "${FULL_IMAGE_NAME}:${VERSION}" - log_success "Pushed ${FULL_IMAGE_NAME}:${VERSION}" - - # Push the latest tag (only if version is not 'latest') - if [[ "${VERSION}" != "latest" ]]; then - log_info "Pushing ${FULL_IMAGE_NAME}:latest..." - podman push "${FULL_IMAGE_NAME}:latest" - log_success "Pushed ${FULL_IMAGE_NAME}:latest" - fi -fi - -# Display final information -echo -if [[ "$SHOULD_PUSH" == "1" ]]; then - log_success "Build and push completed successfully!" - echo - echo "Image details:" - echo " Registry: ${REGISTRY}" - echo " Full name: ${FULL_IMAGE_NAME}" - echo " Version: ${VERSION}" - echo - echo "To run the container:" - echo " podman run -p 5000:5000 ${FULL_IMAGE_NAME}:${VERSION}" - echo - echo "To pull on another machine:" - echo " podman pull ${FULL_IMAGE_NAME}:${VERSION}" -else - log_success "Local build completed!" - echo - echo "Image details:" - echo " Name: ${IMAGE_NAME}" - echo " Version: ${VERSION}" - echo - echo "To run the container:" - echo " podman run -p 5000:5000 ${IMAGE_NAME}:${VERSION}" - echo - echo "To test the container:" - echo " podman run --rm -p 5000:5000 ${IMAGE_NAME}:${VERSION}" - echo - echo "To push to registry:" - echo " PUSH=1 $0" -fi \ No newline at end of file -- cgit