From 6f64838b554b8737d14ac70e6eb1cdca59ca9ba0 Mon Sep 17 00:00:00 2001 From: Arunavo Ray Date: Wed, 21 May 2025 13:49:41 +0530 Subject: [PATCH] Add LXC container support with single-command installer --- scripts/README-lxc.md | 129 ++++++++++++++++++ scripts/gitea-mirror-lxc-installer.sh | 183 ++++++++++++++++++++++++++ 2 files changed, 312 insertions(+) create mode 100644 scripts/README-lxc.md create mode 100755 scripts/gitea-mirror-lxc-installer.sh diff --git a/scripts/README-lxc.md b/scripts/README-lxc.md new file mode 100644 index 0000000..0914589 --- /dev/null +++ b/scripts/README-lxc.md @@ -0,0 +1,129 @@ +# LXC Container Deployment Guide + +This guide explains how to deploy the Gitea Mirror application on Proxmox LXC containers while keeping your existing Docker containers. + +## Prerequisites + +- Proxmox VE installed and configured +- Basic knowledge of LXC containers and Proxmox +- Access to Proxmox web interface or CLI + +## Creating an LXC Container + +1. In Proxmox web interface, create a new LXC container: + - Choose Ubuntu 22.04 as the template + - Allocate appropriate resources (2GB RAM, 2 CPU cores recommended) + - At least 10GB of disk space + - Configure networking as needed + +2. Start the container and get a shell (either via Proxmox web console or SSH) + +## Deploying Gitea Mirror + +### Option 1: One-Command Installation (Recommended) + +This method allows you to install Gitea Mirror with a single command, without having to copy files manually: + +1. SSH into your LXC container: + ```bash + ssh root@lxc-container-ip + ``` + +2. Run the installer script directly: + ```bash + curl -fsSL https://raw.githubusercontent.com/arunavo4/gitea-mirror/main/scripts/gitea-mirror-lxc-installer.sh | bash + ``` + +3. The installer will: + - Download the Gitea Mirror repository + - Install all dependencies including Bun + - Build the application + - Set up a systemd service + - Start the application + - Display access information + +### Option 2: Manual Setup + +If you prefer to set up manually or the automatic script doesn't work for your environment: + +1. Install dependencies: + ```bash + apt update + apt install -y curl git sqlite3 build-essential + ``` + +2. Install Bun: + ```bash + curl -fsSL https://bun.sh/install | bash + export BUN_INSTALL="/root/.bun" + export PATH="$BUN_INSTALL/bin:$PATH" + ``` + +3. Clone or copy your project: + ```bash + git clone https://github.com/yourusername/gitea-mirror.git /opt/gitea-mirror + cd /opt/gitea-mirror + ``` + +4. Build and initialize: + ```bash + bun install + bun run build + bun run manage-db init + ``` + +5. Create a systemd service manually: + ```bash + nano /etc/systemd/system/gitea-mirror.service + # Add the service configuration as shown in the setup-lxc.sh script + + systemctl daemon-reload + systemctl enable gitea-mirror.service + systemctl start gitea-mirror.service + ``` + +## Connecting LXC and Docker Containers + +If you need your LXC container to communicate with Docker containers: + +1. On your host machine, create a bridge network: + ```bash + docker network create gitea-network + ``` + +2. Find the bridge interface created by Docker: + ```bash + ip a | grep docker + # Look for something like docker0 or br-xxxxxxxx + ``` + +3. In Proxmox, edit the LXC container's network configuration to use this bridge. + +## Accessing the Application + +Once deployed, you can access the Gitea Mirror application at: +``` +http://lxc-container-ip:4321 +``` + +## Troubleshooting + +- Check service status: + ```bash + systemctl status gitea-mirror + ``` + +- View logs: + ```bash + journalctl -u gitea-mirror -f + ``` + +- If the service fails to start, check permissions on the data directory: + ```bash + chown -R gitea-mirror:gitea-mirror /opt/gitea-mirror/data + ``` + +- Verify Bun is installed correctly: + ```bash + bun --version + ``` diff --git a/scripts/gitea-mirror-lxc-installer.sh b/scripts/gitea-mirror-lxc-installer.sh new file mode 100755 index 0000000..7625148 --- /dev/null +++ b/scripts/gitea-mirror-lxc-installer.sh @@ -0,0 +1,183 @@ +#!/bin/bash +# Gitea Mirror LXC Container Installer +# This is a self-contained script to install Gitea Mirror in an LXC container +# Usage: curl -fsSL https://raw.githubusercontent.com/arunavo4/gitea-mirror/main/scripts/gitea-mirror-lxc-installer.sh | bash + +set -e + +# Configuration variables - change these as needed +INSTALL_DIR="/opt/gitea-mirror" +REPO_URL="https://github.com/arunavo4/gitea-mirror.git" +SERVICE_USER="gitea-mirror" +PORT=4321 + +# Color codes for better readability +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Print banner +echo -e "${BLUE}" +echo "╔════════════════════════════════════════════════════════════╗" +echo "║ ║" +echo "║ Gitea Mirror LXC Container Installer ║" +echo "║ ║" +echo "╚════════════════════════════════════════════════════════════╝" +echo -e "${NC}" + +# Ensure script is run as root +if [ "$(id -u)" -ne 0 ]; then + echo -e "${RED}This script must be run as root${NC}" >&2 + exit 1 +fi + +echo -e "${GREEN}Starting Gitea Mirror installation...${NC}" + +# Check if we're in an LXC container +if [ -d /proc/vz ] && [ ! -d /proc/bc ]; then + echo -e "${YELLOW}Running in an OpenVZ container. Some features may not work.${NC}" +elif [ -f /proc/1/environ ] && grep -q container=lxc /proc/1/environ; then + echo -e "${GREEN}Running in an LXC container. Good!${NC}" +else + echo -e "${YELLOW}Not running in a container. This script is designed for LXC containers.${NC}" + read -p "Continue anyway? (y/n) " -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + echo -e "${RED}Installation aborted.${NC}" + exit 1 + fi +fi + +# Install dependencies +echo -e "${BLUE}Step 1/7: Installing dependencies...${NC}" +apt update +apt install -y curl git sqlite3 build-essential openssl + +# Create service user +echo -e "${BLUE}Step 2/7: Creating service user...${NC}" +if id "$SERVICE_USER" &>/dev/null; then + echo -e "${YELLOW}User $SERVICE_USER already exists${NC}" +else + useradd -m -s /bin/bash "$SERVICE_USER" + echo -e "${GREEN}Created user $SERVICE_USER${NC}" +fi + +# Install Bun +echo -e "${BLUE}Step 3/7: Installing Bun runtime...${NC}" +if command -v bun >/dev/null 2>&1; then + echo -e "${YELLOW}Bun is already installed${NC}" + bun --version +else + echo -e "${GREEN}Installing Bun...${NC}" + curl -fsSL https://bun.sh/install | bash + export BUN_INSTALL=${BUN_INSTALL:-"/root/.bun"} + export PATH="$BUN_INSTALL/bin:$PATH" + echo -e "${GREEN}Bun installed successfully${NC}" + bun --version +fi + +# Clone repository +echo -e "${BLUE}Step 4/7: Downloading Gitea Mirror...${NC}" +if [ -d "$INSTALL_DIR" ]; then + echo -e "${YELLOW}Directory $INSTALL_DIR already exists${NC}" + read -p "Update existing installation? (y/n) " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + cd "$INSTALL_DIR" + git pull + echo -e "${GREEN}Repository updated${NC}" + else + echo -e "${YELLOW}Using existing installation${NC}" + fi +else + echo -e "${GREEN}Cloning repository...${NC}" + git clone "$REPO_URL" "$INSTALL_DIR" + echo -e "${GREEN}Repository cloned to $INSTALL_DIR${NC}" +fi + +# Set up application +echo -e "${BLUE}Step 5/7: Setting up application...${NC}" +cd "$INSTALL_DIR" + +# Create data directory with proper permissions +mkdir -p data +chown -R "$SERVICE_USER:$SERVICE_USER" data + +# Install dependencies and build +echo -e "${GREEN}Installing dependencies and building application...${NC}" +bun install +bun run build + +# Initialize database if it doesn't exist +echo -e "${GREEN}Initializing database...${NC}" +if [ ! -f "data/gitea-mirror.db" ]; then + bun run manage-db init + chown "$SERVICE_USER:$SERVICE_USER" data/gitea-mirror.db +fi + +# Generate a random JWT secret if not provided +JWT_SECRET=${JWT_SECRET:-$(openssl rand -hex 32)} + +# Create systemd service +echo -e "${BLUE}Step 6/7: Creating systemd service...${NC}" +cat >/etc/systemd/system/gitea-mirror.service <