more stuff done wow amazing
This commit is contained in:
parent
7dbcb516a3
commit
bdc051c53f
|
@ -34,3 +34,5 @@
|
|||
- Most of the project is done but undocumented
|
||||
- Overdose on Caffeine and Write Documentation
|
||||
|
||||
## 2024-06-29
|
||||
- Regarding sleep as overrated and continued working through the night and day to finish this
|
||||
|
|
10
README.md
10
README.md
|
@ -25,9 +25,9 @@ An LXC Container in Proxmox VE is a lighteweight virtualization method that allo
|
|||
- Linux Computer
|
||||
- Incase you wish to publicly offer your services a virtual router
|
||||
|
||||
### How to use image_builder.sh
|
||||
image_builder.sh is a bash script written by me that helps making custom proxmox container templates.
|
||||
### How to use image_builder.sh
|
||||
TLDR : image_builder.sh is a bash script I wrote to poorly compete with Dockerfiles in a "Proxmox Fashion"
|
||||
See [Image Builder Readme](image_builder/README.md)
|
||||
|
||||
A preconofigured version can be found in /image_builder in this repo
|
||||
|
||||
# Todo document this (its 5am and i want to sleep rn)
|
||||
### Project specific image_builder files
|
||||
All Project files that achieved the goals listen in the [JOURNAL.md](JOURNAL.md) are found here :
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
# M169 - Container Deployment
|
||||
|
||||
## Journal
|
||||
See here : [JOURNAL.md](JOURNAL.md)
|
||||
|
||||
## What this Project covers?
|
||||
- Making Custom LXQ Container
|
||||
- Managing a Proxmox VE Environement
|
||||
- Demonstrating example services
|
||||
|
||||
## The Basics
|
||||
Covers the basics neede to know to make sense of this
|
||||
|
||||
### What is Proxmox VE
|
||||
Proxmox VE is an open-source server management platform designed for enterprise virtualisation.
|
||||
It allows you to create and manage virtual machines and containers using a pretty UI either on a single server over over a cluster of servers.
|
||||
|
||||
### What is an LXC Container?
|
||||
An LXC Container in Proxmox VE is a lighteweight virtualization method that allow you to run multiple isolated Linux Systems (Containers) on a single Host using the shared Linux Kernel.
|
||||
|
||||
## Getting started
|
||||
|
||||
### What you will need
|
||||
- 1x or more Proxmox Node(s)
|
||||
- Linux Computer
|
||||
- Incase you wish to publicly offer your services a virtual router
|
||||
|
||||
### How to use image_builder.sh
|
||||
image_builder.sh is a bash script written by me that helps making custom proxmox container templates.
|
||||
|
||||
A preconfigured version can be found in /image_builder in this repo
|
||||
|
||||
# Todo document this (its 5am and i want to sleep rn)
|
|
@ -0,0 +1,33 @@
|
|||
# Deploying Services requiered by Journal using image_builder
|
||||
|
||||
## Nginx Proxy manager
|
||||
Requirements :
|
||||
- Nginx WebUI : https://github.com/0xJacky/nginx-ui/tree/dev
|
||||
- Configs and Websites Stored on seperate Mountpoint for easy reassignement
|
||||
|
||||
Distro of Choice : Debian
|
||||
- Why ? : Eases installation of Nginx Plugins if needed and more up to date Nginx versions available compared to alpine
|
||||
|
||||
### Making Installation script :
|
||||
The easiest way to do this is to manually install and configure things how you want them. Then figure out how to automate that after which you can provide set in place updatable images.
|
||||
|
||||
1. Making our Temporary Debian VM, adding the data directory and starting it : `pct create 201 adastor:vztmpl/debian-12-standard_12.2-1_amd64.tar.zst --rootfs local-btrfs:8 --cores 2 --memory 1024 --swap 512 --net0 name=eth0,bridge=vmbr0,ip=dhcp --hostname debian-nginx-temp && pct set 201 -mp0 local-btrfs:8,mp=/data,size=8G && pct start 201`
|
||||
2. Entering our container : `pct enter 201`
|
||||
3. Completing a Manual Installation :
|
||||
```
|
||||
apt update
|
||||
apt upgrade
|
||||
apt autoremove
|
||||
apt clean
|
||||
apt install nginx-full curl -y
|
||||
systemctl enable --now nginx
|
||||
bash <(curl -L -s https://raw.githubusercontent.com/0xJacky/nginx-ui/master/install.sh) install
|
||||
systemctl enable --now nginx-ui
|
||||
sed -i '/include \/etc\/nginx\/sites-enabled\/\*;/a include \/data\/configs\/\*conf;' /etc/nginx/nginx.conf
|
||||
```
|
||||
4. Making it a bash script :
|
||||
See debian-nginx.sh
|
||||
5. Building the Container Image : `./image_builder.sh --param-file debian-nginx.conf`
|
||||
6. Move to your CT Template dir of choice :`mv ./vzdump-lxc-202-2024_06_29-10_52_05.tar.gz /mnt/pve/adastor/template/cache/debian-nginx-2024-06-29.tar.gz`
|
||||
7. Enjoy our success and Deploy where needed with our configs in a mountpoint
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
|
||||
TEMPLATE=adastor:vztmpl/debian-12-standard_12.2-1_amd64.tar.zst
|
||||
# Set your Baseimage here
|
||||
|
||||
RAM=1024
|
||||
# Define RAM during setup
|
||||
|
||||
SWAP=512
|
||||
# Define SWAP during setup
|
||||
|
||||
CORES=2
|
||||
# Define Cores during setup
|
||||
|
||||
BRIDGE=vmbr0
|
||||
# Define Network interface during Installation
|
||||
|
||||
IP=dhcp
|
||||
# Define IP During installation (use DHCP, proper static V4 not implemented)
|
||||
|
||||
CTID=
|
||||
# Manually Override CTID, not needed usually
|
||||
|
||||
HOSTNAME=debian-nginx
|
||||
# Set Temporary Hostname
|
||||
|
||||
EXPORT_NAME=debian-nginx-image
|
||||
# Doesnt work anyways so yea
|
||||
|
||||
EXPORT_PATH=
|
||||
# Leave this empty to use the current directory
|
||||
|
||||
SCRIPT=debian-nginx.sh
|
||||
# Leave this empty to use script.sh in the current directory
|
||||
|
||||
MIN_ID=200
|
||||
# Define minimum ID for CT to avoid conflicts with other nodes if in a cluster
|
||||
|
||||
STORAGE=local-btrfs
|
||||
# Set what storage pool to use
|
||||
|
||||
DISK_SIZE=8
|
||||
# Set the default disk size for the container
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Ensure the locale environment variables are set correctly
|
||||
export LANGUAGE=en_US.UTF-8
|
||||
export LANG=en_US.UTF-8
|
||||
export LC_ALL=en_US.UTF-8
|
||||
|
||||
# Install locales and configure locale settings
|
||||
apt-get update
|
||||
apt-get install -y locales
|
||||
locale-gen en_US.UTF-8
|
||||
|
||||
apt update
|
||||
apt upgrade -y
|
||||
apt autoremove -y
|
||||
apt clean
|
||||
apt install nginx-full curl -y
|
||||
systemctl enable --now nginx
|
||||
bash <(curl -L -s https://raw.githubusercontent.com/0xJacky/nginx-ui/master/install.sh) install
|
||||
systemctl enable --now nginx-ui
|
||||
sed -i '/include \/etc\/nginx\/sites-enabled\/\*;/a include \/data\/configs\/\*conf;' /etc/nginx/nginx.conf
|
|
@ -0,0 +1,131 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Default parameter file
|
||||
DEFAULT_PARAM_FILE="settings.conf"
|
||||
|
||||
# Function to load parameters from a file
|
||||
load_params() {
|
||||
local param_file=$1
|
||||
if [ -f "$param_file" ]; then
|
||||
source "$param_file"
|
||||
else
|
||||
echo "Parameter file $param_file does not exist."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to find the lowest free container ID starting from MIN_ID
|
||||
find_lowest_free_id() {
|
||||
local id=$MIN_ID
|
||||
while pct status $id &>/dev/null || qm status $id &>/dev/null; do
|
||||
((id++))
|
||||
done
|
||||
echo $id
|
||||
}
|
||||
|
||||
# Parse command line arguments
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
case $1 in
|
||||
--param-file) PARAM_FILE="$2"; shift ;;
|
||||
--template) TEMPLATE="$2"; shift ;;
|
||||
--ram) RAM="$2"; shift ;;
|
||||
--swap) SWAP="$2"; shift ;;
|
||||
--cores) CORES="$2"; shift ;;
|
||||
--bridge) BRIDGE="$2"; shift ;;
|
||||
--ip) IP="$2"; shift ;;
|
||||
--ctid) CTID="$2"; shift ;;
|
||||
--hostname) HOSTNAME="$2"; shift ;;
|
||||
--export-name) EXPORT_NAME="$2"; shift ;;
|
||||
--export-path) EXPORT_PATH="$2"; shift ;;
|
||||
--script) SCRIPT="$2"; shift ;;
|
||||
--min-id) MIN_ID="$2"; shift ;;
|
||||
--storage) STORAGE="$2"; shift ;;
|
||||
--disk-size) DISK_SIZE="$2"; shift ;;
|
||||
--mount-point) MOUNT_POINT="$2"; shift ;;
|
||||
*) echo "Unknown parameter passed: $1"; exit 1 ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
|
||||
# Load parameters from the parameter file if specified, otherwise use default
|
||||
PARAM_FILE=${PARAM_FILE:-$DEFAULT_PARAM_FILE}
|
||||
load_params "$PARAM_FILE"
|
||||
|
||||
# Set defaults for parameters if not provided by the parameter file or command line
|
||||
TEMPLATE=${TEMPLATE:-"adastor:vztmpl/debian-12-standard_12.2-1_amd64.tar.zst"}
|
||||
RAM=${RAM:-1024}
|
||||
SWAP=${SWAP:-512}
|
||||
CORES=${CORES:-2}
|
||||
BRIDGE=${BRIDGE:-vmbr0}
|
||||
IP=${IP:-dhcp}
|
||||
CTID=${CTID:-$(find_lowest_free_id)}
|
||||
HOSTNAME=${HOSTNAME:-nginx-debian}
|
||||
EXPORT_NAME=${EXPORT_NAME:-mycontainer_backup}
|
||||
CURRENT_DIR=$(pwd)
|
||||
EXPORT_PATH=${EXPORT_PATH:-$CURRENT_DIR}
|
||||
SCRIPT=${SCRIPT:-$CURRENT_DIR/script.sh}
|
||||
MIN_ID=${MIN_ID:-200}
|
||||
STORAGE=${STORAGE:-local-btrfs}
|
||||
DISK_SIZE=${DISK_SIZE:-8}
|
||||
ROOTFS="${STORAGE}:${DISK_SIZE}"
|
||||
SCRIPT=${SCRIPT:-$CURRENT_DIR/script.sh}
|
||||
MOUNT_POINT=${MOUNT_POINT:-}
|
||||
|
||||
|
||||
|
||||
# Check if the script file exists
|
||||
if [ ! -f "$SCRIPT" ]; then
|
||||
echo "Script file $SCRIPT does not exist."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the container already exists on the local node
|
||||
if pct status $CTID &>/dev/null; then
|
||||
echo "VM $CTID already exists on this node."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create the container with the correct storage format
|
||||
if ! pct create $CTID $TEMPLATE --rootfs $ROOTFS --cores $CORES --memory $RAM --swap $SWAP --net0 name=eth0,bridge=$BRIDGE,ip=$IP --hostname $HOSTNAME; then
|
||||
echo "Failed to create the container."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Set the mount point if specified
|
||||
if [ -n "$MOUNT_POINT" ]; then
|
||||
if ! pct set $CTID -mp0 $MOUNT_POINT; then
|
||||
echo "Failed to set the mount point."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# Start the container
|
||||
if ! pct start $CTID; then
|
||||
echo "Failed to start the container."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Run the shell script in the container
|
||||
if ! pct exec $CTID -- /bin/bash -c "$(cat $SCRIPT)"; then
|
||||
echo "Failed to run the script inside the container."
|
||||
pct stop $CTID
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Stop the container
|
||||
if ! pct stop $CTID; then
|
||||
echo "Failed to stop the container."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Export the container as a tar.gz file
|
||||
BACKUP_FILE=$EXPORT_PATH/$EXPORT_NAME.tar.gz
|
||||
if ! vzdump $CTID --dumpdir $EXPORT_PATH --compress gzip; then
|
||||
echo "Failed to export the container."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Container $CTID has been created, configured, and exported to $BACKUP_FILE"
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Ensure the locale environment variables are set correctly
|
||||
export LANGUAGE=en_US.UTF-8
|
||||
export LANG=en_US.UTF-8
|
||||
export LC_ALL=en_US.UTF-8
|
||||
|
||||
# Install locales and configure locale settings
|
||||
apt-get update
|
||||
apt-get install -y locales
|
||||
locale-gen en_US.UTF-8
|
||||
|
||||
# Update and install packages for Debian
|
||||
apt-get update
|
||||
apt-get upgrade -y
|
||||
apt-get install -y nginx
|
||||
|
||||
# Enable nginx service
|
||||
systemctl enable nginx
|
||||
|
||||
# Clean up
|
||||
apt-get clean
|
|
@ -40,3 +40,7 @@ STORAGE=local-btrfs
|
|||
|
||||
DISK_SIZE=8
|
||||
# Set the default disk size for the container
|
||||
|
||||
SCRIPT=
|
||||
# Specify your script file here or leave empty to use script.sh in the current directory
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
# PVE Image Builder
|
||||
|
||||
## What is this?
|
||||
This is a little bash script that aids in making custom proxmox container images. Automating the process of making them instead of having to create them manually
|
||||
|
||||
## How do I use it?
|
||||
1. Copy the image-builder directory to your proxmox servers root users home directory
|
||||
2. Download the CT templates you wish to base your images on
|
||||
3. Copy settings.conf to for example debian-nginx-settings.conf
|
||||
4. Adjust values in it to match that of what you need for the image generation
|
||||
5. Either copy or make a new script.sh (to a name that you can associate with the image were going to genereate) for example debian-nginx-script.sh
|
||||
- This script should contain all the steps needed to set up your Container Template
|
||||
6. Run ./image_builder.sh --param-file debian-nginx-settings.conf
|
||||
7. Watch as your image gets built into the current directory
|
||||
8. Enjoy and Deploy
|
||||
|
||||
## Isn't this overkill ?
|
||||
Yes it is. I spent way too much time on this for no real reason and in the end its far from as good as I wanted it to be.
|
|
@ -1,7 +1,18 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Load parameters from params.conf
|
||||
source params.conf
|
||||
# Default parameter file
|
||||
DEFAULT_PARAM_FILE="settings.conf"
|
||||
|
||||
# Function to load parameters from a file
|
||||
load_params() {
|
||||
local param_file=$1
|
||||
if [ -f "$param_file" ]; then
|
||||
source "$param_file"
|
||||
else
|
||||
echo "Parameter file $param_file does not exist."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to find the lowest free container ID starting from MIN_ID
|
||||
find_lowest_free_id() {
|
||||
|
@ -12,25 +23,56 @@ find_lowest_free_id() {
|
|||
echo $id
|
||||
}
|
||||
|
||||
# Get the container ID
|
||||
if [ -z "$CTID" ]; then
|
||||
CTID=$(find_lowest_free_id)
|
||||
fi
|
||||
# Parse command line arguments
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
case $1 in
|
||||
--param-file) PARAM_FILE="$2"; shift ;;
|
||||
--template) TEMPLATE="$2"; shift ;;
|
||||
--ram) RAM="$2"; shift ;;
|
||||
--swap) SWAP="$2"; shift ;;
|
||||
--cores) CORES="$2"; shift ;;
|
||||
--bridge) BRIDGE="$2"; shift ;;
|
||||
--ip) IP="$2"; shift ;;
|
||||
--ctid) CTID="$2"; shift ;;
|
||||
--hostname) HOSTNAME="$2"; shift ;;
|
||||
--export-name) EXPORT_NAME="$2"; shift ;;
|
||||
--export-path) EXPORT_PATH="$2"; shift ;;
|
||||
--script) SCRIPT="$2"; shift ;;
|
||||
--min-id) MIN_ID="$2"; shift ;;
|
||||
--storage) STORAGE="$2"; shift ;;
|
||||
--disk-size) DISK_SIZE="$2"; shift ;;
|
||||
--mount-point) MOUNT_POINT="$2"; shift ;;
|
||||
*) echo "Unknown parameter passed: $1"; exit 1 ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# Generate disk name
|
||||
DISK_NAME="vm-${CTID}-disk-0"
|
||||
|
||||
# Determine the current directory
|
||||
# Load parameters from the parameter file if specified, otherwise use default
|
||||
PARAM_FILE=${PARAM_FILE:-$DEFAULT_PARAM_FILE}
|
||||
load_params "$PARAM_FILE"
|
||||
|
||||
# Set defaults for parameters if not provided by the parameter file or command line
|
||||
TEMPLATE=${TEMPLATE:-"adastor:vztmpl/debian-12-standard_12.2-1_amd64.tar.zst"}
|
||||
RAM=${RAM:-1024}
|
||||
SWAP=${SWAP:-512}
|
||||
CORES=${CORES:-2}
|
||||
BRIDGE=${BRIDGE:-vmbr0}
|
||||
IP=${IP:-dhcp}
|
||||
CTID=${CTID:-$(find_lowest_free_id)}
|
||||
HOSTNAME=${HOSTNAME:-nginx-debian}
|
||||
EXPORT_NAME=${EXPORT_NAME:-mycontainer_backup}
|
||||
CURRENT_DIR=$(pwd)
|
||||
|
||||
# Set default values for EXPORT_PATH and SCRIPT if not set in params.conf
|
||||
EXPORT_PATH=${EXPORT_PATH:-$CURRENT_DIR}
|
||||
SCRIPT=${SCRIPT:-$CURRENT_DIR/script.sh}
|
||||
MIN_ID=${MIN_ID:-200}
|
||||
STORAGE=${STORAGE:-local-btrfs}
|
||||
DISK_SIZE=${DISK_SIZE:-8}
|
||||
|
||||
# Full rootfs parameter
|
||||
ROOTFS="${STORAGE}:${DISK_SIZE}"
|
||||
SCRIPT=${SCRIPT:-$CURRENT_DIR/script.sh}
|
||||
MOUNT_POINT=${MOUNT_POINT:-}
|
||||
|
||||
|
||||
|
||||
# Check if the script file exists
|
||||
if [ ! -f "$SCRIPT" ]; then
|
||||
|
@ -50,6 +92,15 @@ if ! pct create $CTID $TEMPLATE --rootfs $ROOTFS --cores $CORES --memory $RAM --
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# Set the mount point if specified
|
||||
if [ -n "$MOUNT_POINT" ]; then
|
||||
if ! pct set $CTID -mp0 $MOUNT_POINT; then
|
||||
echo "Failed to set the mount point."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# Start the container
|
||||
if ! pct start $CTID; then
|
||||
echo "Failed to start the container."
|
||||
|
@ -70,7 +121,6 @@ if ! pct stop $CTID; then
|
|||
fi
|
||||
|
||||
# Export the container as a tar.gz file
|
||||
EXPORT_NAME=${EXPORT_NAME:-vzdump-lxc-$CTID}
|
||||
BACKUP_FILE=$EXPORT_PATH/$EXPORT_NAME.tar.gz
|
||||
if ! vzdump $CTID --dumpdir $EXPORT_PATH --compress gzip; then
|
||||
echo "Failed to export the container."
|
||||
|
@ -78,3 +128,4 @@ if ! vzdump $CTID --dumpdir $EXPORT_PATH --compress gzip; then
|
|||
fi
|
||||
|
||||
echo "Container $CTID has been created, configured, and exported to $BACKUP_FILE"
|
||||
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
TEMPLATE=adastor:vztmpl/debian-12-standard_12.2-1_amd64.tar.zst
|
||||
# Set your Baseimage here
|
||||
|
||||
RAM=1024
|
||||
# Define RAM during setup
|
||||
|
||||
SWAP=512
|
||||
# Define SWAP during setup
|
||||
|
||||
CORES=2
|
||||
# Define Cores during setup
|
||||
|
||||
BRIDGE=vmbr0
|
||||
# Define Network interface during Installation
|
||||
|
||||
IP=dhcp
|
||||
# Define IP During installation (use DHCP, proper static V4 not implemented)
|
||||
|
||||
CTID=
|
||||
# Manually Override CTID, not needed usually
|
||||
|
||||
HOSTNAME=nginx-debian
|
||||
# Set Temporary Hostname
|
||||
|
||||
EXPORT_NAME=mycontainer_backup
|
||||
# Doesnt work anyways so yea
|
||||
|
||||
EXPORT_PATH=
|
||||
# Leave this empty to use the current directory
|
||||
|
||||
SCRIPT=
|
||||
# Leave this empty to use script.sh in the current directory
|
||||
|
||||
MIN_ID=200
|
||||
# Define minimum ID for CT to avoid conflicts with other nodes if in a cluster
|
||||
|
||||
STORAGE=local-btrfs
|
||||
# Set what storage pool to use
|
||||
|
||||
DISK_SIZE=8
|
||||
# Set the default disk size for the container
|
||||
|
||||
SCRIPT=
|
||||
# Specify your script file here or leave empty to use script.sh in the current directory
|
||||
|
||||
MOUNT_POINT=
|
||||
# Specify your mount point here
|
Loading…
Reference in New Issue