nested docker container inside of incus
This commit is contained in:
parent
cd93f12bd6
commit
ab15f7f3be
20
README.md
20
README.md
@ -1,6 +1,6 @@
|
|||||||
# Gitea Incus Deployment Script
|
# Gitea Incus Deployment Script
|
||||||
|
|
||||||
This script automates the deployment of Gitea using Incus containers. It provides a simple command-line interface to create a profile, install Gitea and PostgreSQL, and secure the configuration.
|
This script automates the deployment of Gitea using a single Incus container with Docker Compose. It provides a simple command-line interface to create a profile and install Gitea with PostgreSQL.
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ If CPU or RAM is not specified, the default Incus values will be used.
|
|||||||
|
|
||||||
### Install Gitea
|
### Install Gitea
|
||||||
|
|
||||||
Install Gitea and PostgreSQL:
|
Install Gitea and PostgreSQL using Docker Compose:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./gitea.sh install [-p dbpassword]
|
./gitea.sh install [-p dbpassword]
|
||||||
@ -42,28 +42,22 @@ Options:
|
|||||||
|
|
||||||
If no password is provided, a default password will be used.
|
If no password is provided, a default password will be used.
|
||||||
|
|
||||||
### Secure Configuration
|
|
||||||
|
|
||||||
After completing the web installation, secure the Gitea configuration:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
./gitea.sh secure
|
|
||||||
```
|
|
||||||
|
|
||||||
## Script Behavior
|
## Script Behavior
|
||||||
|
|
||||||
1. The script enforces the correct order of operations:
|
1. The script enforces the correct order of operations:
|
||||||
- Profile must be created before installation
|
- Profile must be created before installation
|
||||||
- Gitea must be installed before securing the configuration
|
|
||||||
2. The script will create a network named "incusbr0" if it doesn't exist
|
2. The script will create a network named "incusbr0" if it doesn't exist
|
||||||
3. The root disk size for the Incus container is set to 20GB by default
|
3. The root disk size for the Incus container is set to 20GB by default
|
||||||
4. Gitea will be accessible on port 3000, and SSH access will be on port 2222
|
4. Gitea will be accessible on port 3000, and SSH access will be on port 2222
|
||||||
|
5. The script creates a single Incus container with nesting enabled
|
||||||
|
6. Docker and Docker Compose are installed inside the Incus container
|
||||||
|
7. Gitea and PostgreSQL are deployed using Docker Compose within the Incus container
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
- After installation, access Gitea through the web interface to complete the setup
|
- After installation, access Gitea through the web interface to complete the setup
|
||||||
- The script provides the URL to access Gitea after installation
|
- The script provides the URL to access Gitea after installation
|
||||||
- Make sure to secure the configuration after completing the web setup
|
- The latest versions of Gitea and PostgreSQL Docker images are used
|
||||||
|
|
||||||
## Customization
|
## Customization
|
||||||
|
|
||||||
@ -82,5 +76,5 @@ You can modify the following variables at the top of the script to customize you
|
|||||||
|
|
||||||
If you encounter any issues:
|
If you encounter any issues:
|
||||||
1. Check the Incus container status: `incus list`
|
1. Check the Incus container status: `incus list`
|
||||||
2. View the container logs: `incus exec gitea -- journalctl -u gitea`
|
2. View the container logs: `incus exec gitea -- docker-compose logs`
|
||||||
3. Ensure all required ports are open and not in use by other services
|
3. Ensure all required ports are open and not in use by other services
|
||||||
|
207
gitea.sh
207
gitea.sh
@ -44,7 +44,7 @@ profile_exists() {
|
|||||||
incus profile list | grep -q $PROFILE_NAME
|
incus profile list | grep -q $PROFILE_NAME
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to install Gitea and PostgreSQL
|
# Function to install Gitea and PostgreSQL using Docker Compose
|
||||||
install_gitea() {
|
install_gitea() {
|
||||||
if ! profile_exists; then
|
if ! profile_exists; then
|
||||||
echo "Error: Profile does not exist. Please create a profile first using '$0 profile'."
|
echo "Error: Profile does not exist. Please create a profile first using '$0 profile'."
|
||||||
@ -58,176 +58,75 @@ install_gitea() {
|
|||||||
incus network attach $NETWORK_NAME $CONTAINER_NAME
|
incus network attach $NETWORK_NAME $CONTAINER_NAME
|
||||||
|
|
||||||
echo "Configuring container..."
|
echo "Configuring container..."
|
||||||
incus config set $CONTAINER_NAME security.privileged=true
|
incus config set $CONTAINER_NAME security.nesting=true
|
||||||
incus config set $CONTAINER_NAME linux.kernel_modules=overlay,nf_nat
|
incus config set $CONTAINER_NAME linux.kernel_modules=overlay,nf_nat
|
||||||
incus config device add $CONTAINER_NAME gitea-ssh proxy listen=tcp:0.0.0.0:$SSH_PORT connect=tcp:127.0.0.1:2222
|
incus config device add $CONTAINER_NAME gitea-ssh proxy listen=tcp:0.0.0.0:$SSH_PORT connect=tcp:127.0.0.1:22
|
||||||
incus config device add $CONTAINER_NAME gitea-web proxy listen=tcp:0.0.0.0:$WEB_PORT connect=tcp:127.0.0.1:3000
|
incus config device add $CONTAINER_NAME gitea-web proxy listen=tcp:0.0.0.0:$WEB_PORT connect=tcp:127.0.0.1:3000
|
||||||
|
|
||||||
echo "Waiting for network to be ready..."
|
echo "Waiting for network to be ready..."
|
||||||
sleep 10
|
sleep 10
|
||||||
|
|
||||||
echo "Installing Gitea dependencies..."
|
echo "Installing Docker and Docker Compose..."
|
||||||
incus exec $CONTAINER_NAME -- bash -c "
|
incus exec $CONTAINER_NAME -- bash -c "
|
||||||
apt update
|
apt update
|
||||||
apt install -y wget git postgresql postgresql-contrib
|
apt install -y docker.io docker-compose
|
||||||
"
|
"
|
||||||
|
|
||||||
echo "Setting up PostgreSQL..."
|
echo "Creating Docker Compose file..."
|
||||||
incus exec $CONTAINER_NAME -- bash -c "
|
incus exec $CONTAINER_NAME -- bash -c "cat > /root/docker-compose.yml << EOL
|
||||||
sudo -u postgres psql -c \"CREATE USER $DB_USER WITH PASSWORD '$DB_PASS'\"
|
version: '3'
|
||||||
sudo -u postgres psql -c \"CREATE DATABASE gitea OWNER $DB_USER\"
|
|
||||||
echo \"host all all 0.0.0.0/0 password\" >> /etc/postgresql/14/main/pg_hba.conf
|
|
||||||
echo \"listen_addresses = '*'\" >> /etc/postgresql/14/main/postgresql.conf
|
|
||||||
systemctl restart postgresql
|
|
||||||
"
|
|
||||||
|
|
||||||
echo "Installing Gitea..."
|
networks:
|
||||||
incus exec $CONTAINER_NAME -- bash -c "
|
gitea:
|
||||||
wget -O gitea https://dl.gitea.io/gitea/1.18.0/gitea-1.18.0-linux-amd64
|
external: false
|
||||||
chmod +x gitea
|
|
||||||
mv gitea /usr/local/bin/gitea
|
|
||||||
"
|
|
||||||
|
|
||||||
echo "Creating Gitea user and setting up directories..."
|
services:
|
||||||
incus exec $CONTAINER_NAME -- bash -c "
|
server:
|
||||||
adduser --system --group --disabled-password --home /var/lib/gitea --shell /bin/bash git
|
image: gitea/gitea:latest
|
||||||
mkdir -p /var/lib/gitea/{custom,data,log}
|
container_name: gitea
|
||||||
chown -R git:git /var/lib/gitea/
|
environment:
|
||||||
chmod -R 750 /var/lib/gitea/
|
- USER_UID=1000
|
||||||
mkdir -p /etc/gitea
|
- USER_GID=1000
|
||||||
chown root:git /etc/gitea
|
- DB_TYPE=postgres
|
||||||
chmod 770 /etc/gitea
|
- DB_HOST=db:5432
|
||||||
"
|
- DB_NAME=gitea
|
||||||
|
- DB_USER=$DB_USER
|
||||||
echo "Creating Gitea configuration..."
|
- DB_PASSWD=$DB_PASS
|
||||||
incus exec $CONTAINER_NAME -- bash -c "cat > /etc/gitea/app.ini << EOL
|
restart: always
|
||||||
APP_NAME = Gitea: Git with a cup of tea
|
networks:
|
||||||
RUN_USER = git
|
- gitea
|
||||||
RUN_MODE = prod
|
volumes:
|
||||||
|
- /var/lib/gitea:/data
|
||||||
[database]
|
- /etc/timezone:/etc/timezone:ro
|
||||||
DB_TYPE = postgres
|
- /etc/localtime:/etc/localtime:ro
|
||||||
HOST = 127.0.0.1:5432
|
ports:
|
||||||
NAME = gitea
|
- '3000:3000'
|
||||||
USER = $DB_USER
|
- '22:22'
|
||||||
PASSWD = $DB_PASS
|
depends_on:
|
||||||
|
- db
|
||||||
[repository]
|
|
||||||
ROOT = /var/lib/gitea/data/gitea-repositories
|
db:
|
||||||
|
image: postgres:latest
|
||||||
[server]
|
restart: always
|
||||||
HTTP_PORT = 3000
|
environment:
|
||||||
ROOT_URL = http://$(incus exec $CONTAINER_NAME -- ip addr show eth0 | grep 'inet ' | awk '{print $2}' | cut -d/ -f1):$WEB_PORT/
|
- POSTGRES_USER=$DB_USER
|
||||||
DISABLE_SSH = false
|
- POSTGRES_PASSWORD=$DB_PASS
|
||||||
SSH_PORT = 2222
|
- POSTGRES_DB=gitea
|
||||||
START_SSH_SERVER = true
|
networks:
|
||||||
LFS_START_SERVER = true
|
- gitea
|
||||||
|
volumes:
|
||||||
[security]
|
- /var/lib/postgresql/data:/var/lib/postgresql/data
|
||||||
INSTALL_LOCK = false
|
|
||||||
|
|
||||||
[service]
|
|
||||||
DISABLE_REGISTRATION = false
|
|
||||||
REQUIRE_SIGNIN_VIEW = false
|
|
||||||
|
|
||||||
[indexer]
|
|
||||||
ISSUE_INDEXER_PATH = /var/lib/gitea/indexers/issues.bleve
|
|
||||||
|
|
||||||
[session]
|
|
||||||
PROVIDER_CONFIG = /var/lib/gitea/data/sessions
|
|
||||||
|
|
||||||
[picture]
|
|
||||||
AVATAR_UPLOAD_PATH = /var/lib/gitea/data/avatars
|
|
||||||
REPOSITORY_AVATAR_UPLOAD_PATH = /var/lib/gitea/data/repo-avatars
|
|
||||||
|
|
||||||
[attachment]
|
|
||||||
PATH = /var/lib/gitea/data/attachments
|
|
||||||
|
|
||||||
[log]
|
|
||||||
ROOT_PATH = /var/lib/gitea/log
|
|
||||||
|
|
||||||
[mailer]
|
|
||||||
ENABLED = false
|
|
||||||
|
|
||||||
[service]
|
|
||||||
DISABLE_REGISTRATION = false
|
|
||||||
REQUIRE_SIGNIN_VIEW = false
|
|
||||||
REGISTER_EMAIL_CONFIRM = false
|
|
||||||
ENABLE_NOTIFY_MAIL = false
|
|
||||||
ALLOW_ONLY_EXTERNAL_REGISTRATION = false
|
|
||||||
ENABLE_CAPTCHA = false
|
|
||||||
DEFAULT_KEEP_EMAIL_PRIVATE = false
|
|
||||||
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
|
|
||||||
DEFAULT_ENABLE_TIMETRACKING = true
|
|
||||||
NO_REPLY_ADDRESS = noreply.example.org
|
|
||||||
|
|
||||||
[openid]
|
|
||||||
ENABLE_OPENID_SIGNIN = true
|
|
||||||
ENABLE_OPENID_SIGNUP = true
|
|
||||||
EOL"
|
EOL"
|
||||||
|
|
||||||
echo "Setting initial permissions for Gitea config file..."
|
echo "Starting Gitea and PostgreSQL with Docker Compose..."
|
||||||
incus exec $CONTAINER_NAME -- bash -c "
|
incus exec $CONTAINER_NAME -- bash -c "
|
||||||
chown root:git /etc/gitea/app.ini
|
cd /root
|
||||||
chmod 770 /etc/gitea
|
docker-compose up -d
|
||||||
chmod 660 /etc/gitea/app.ini
|
|
||||||
"
|
|
||||||
|
|
||||||
echo "Creating Gitea service..."
|
|
||||||
incus exec $CONTAINER_NAME -- bash -c "cat > /etc/systemd/system/gitea.service << EOL
|
|
||||||
[Unit]
|
|
||||||
Description=Gitea (Git with a cup of tea)
|
|
||||||
After=syslog.target
|
|
||||||
After=network.target
|
|
||||||
After=postgresql.service
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
RestartSec=2s
|
|
||||||
Type=simple
|
|
||||||
User=git
|
|
||||||
Group=git
|
|
||||||
WorkingDirectory=/var/lib/gitea/
|
|
||||||
ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
|
|
||||||
Restart=always
|
|
||||||
Environment=USER=git HOME=/var/lib/gitea GITEA_WORK_DIR=/var/lib/gitea
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
||||||
EOL"
|
|
||||||
|
|
||||||
echo "Ensuring PostgreSQL is running and accessible..."
|
|
||||||
incus exec $CONTAINER_NAME -- bash -c "
|
|
||||||
systemctl restart postgresql
|
|
||||||
sleep 5
|
|
||||||
sudo -u git psql -h 127.0.0.1 -U gitea -d gitea -c 'SELECT 1'
|
|
||||||
"
|
|
||||||
|
|
||||||
echo "Starting Gitea..."
|
|
||||||
incus exec $CONTAINER_NAME -- bash -c "
|
|
||||||
systemctl daemon-reload
|
|
||||||
systemctl enable gitea
|
|
||||||
systemctl restart gitea
|
|
||||||
sleep 5
|
|
||||||
systemctl status gitea
|
|
||||||
"
|
"
|
||||||
|
|
||||||
echo "Gitea setup complete!"
|
echo "Gitea setup complete!"
|
||||||
echo "Access Gitea at http://$(incus exec $CONTAINER_NAME -- ip addr show eth0 | grep 'inet ' | awk '{print $2}' | cut -d/ -f1):$WEB_PORT"
|
echo "Access Gitea at http://$(incus exec $CONTAINER_NAME -- ip addr show eth0 | grep 'inet ' | awk '{print $2}' | cut -d/ -f1):$WEB_PORT"
|
||||||
echo "SSH access available on port $SSH_PORT"
|
echo "SSH access available on port $SSH_PORT"
|
||||||
echo ""
|
|
||||||
echo "After completing the web installation, run '$0 secure' to secure the configuration."
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function to secure Gitea configuration
|
|
||||||
secure_gitea() {
|
|
||||||
if ! incus list | grep -q $CONTAINER_NAME; then
|
|
||||||
echo "Error: Gitea is not installed. Please install Gitea first using '$0 install'."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Securing Gitea configuration..."
|
|
||||||
incus exec $CONTAINER_NAME -- bash -c 'chmod 750 /etc/gitea && chmod 640 /etc/gitea/app.ini'
|
|
||||||
echo "Gitea configuration secured."
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to display usage
|
# Function to display usage
|
||||||
@ -238,9 +137,6 @@ usage() {
|
|||||||
echo ""
|
echo ""
|
||||||
echo "Install Gitea and PostgreSQL:"
|
echo "Install Gitea and PostgreSQL:"
|
||||||
echo "$0 install [-p dbpassword]"
|
echo "$0 install [-p dbpassword]"
|
||||||
echo ""
|
|
||||||
echo "Secure the configurations:"
|
|
||||||
echo "$0 secure"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Main script logic
|
# Main script logic
|
||||||
@ -292,9 +188,6 @@ case "$1" in
|
|||||||
done
|
done
|
||||||
install_gitea
|
install_gitea
|
||||||
;;
|
;;
|
||||||
secure)
|
|
||||||
secure_gitea
|
|
||||||
;;
|
|
||||||
*)
|
*)
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
|
Loading…
Reference in New Issue
Block a user