Spaces:
Running
Running
| # Docker Build and Push Script | |
| # Generated by DeployMate | |
| set -e | |
| # Configuration | |
| IMAGE_NAME="{{ config.projectName or 'myapp' }}" | |
| REGISTRY="{{ config.registry or 'docker.io' }}" | |
| TAG="{{ config.tag or 'latest' }}" | |
| DOCKERFILE="Dockerfile" | |
| # Colors for output | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[1;33m' | |
| NC='\033[0m' # No Color | |
| echo -e "${GREEN}π³ Docker Build Script${NC}" | |
| echo "================================" | |
| # Check if Docker is installed | |
| if ! command -v docker &> /dev/null; then | |
| echo -e "${RED}Error: Docker is not installed${NC}" | |
| exit 1 | |
| fi | |
| # Build the image | |
| echo -e "${YELLOW}Building Docker image...${NC}" | |
| docker build -t ${IMAGE_NAME}:${TAG} -f ${DOCKERFILE} . | |
| if [ $? -eq 0 ]; then | |
| echo -e "${GREEN}β Build successful${NC}" | |
| else | |
| echo -e "${RED}β Build failed${NC}" | |
| exit 1 | |
| fi | |
| # Tag for registry | |
| if [ "$REGISTRY" != "docker.io" ] || [ "$REGISTRY" != "localhost" ]; then | |
| echo -e "${YELLOW}Tagging image for registry...${NC}" | |
| docker tag ${IMAGE_NAME}:${TAG} ${REGISTRY}/${IMAGE_NAME}:${TAG} | |
| fi | |
| # Ask to push | |
| read -p "Do you want to push to registry? (y/n) " -n 1 -r | |
| echo | |
| if [[ $REPLY =~ ^[Yy]$ ]]; then | |
| echo -e "${YELLOW}Pushing to registry...${NC}" | |
| docker push ${REGISTRY}/${IMAGE_NAME}:${TAG} | |
| if [ $? -eq 0 ]; then | |
| echo -e "${GREEN}β Push successful${NC}" | |
| else | |
| echo -e "${RED}β Push failed${NC}" | |
| exit 1 | |
| fi | |
| fi | |
| echo -e "${GREEN}β All done!${NC}" | |
| echo "" | |
| echo "Run your container with:" | |
| echo " docker run -p {{ config.appPort or '3000' }}:{{ config.appPort or '3000' }} ${IMAGE_NAME}:${TAG}" | |
| echo "" | |
| echo "Or use docker-compose:" | |
| echo " docker-compose up -d" | |