...
This commit is contained in:
71
docker/docker_ubuntu_install.sh
Normal file
71
docker/docker_ubuntu_install.sh
Normal file
@@ -0,0 +1,71 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Exit immediately if a command exits with a non-zero status
|
||||
set -e
|
||||
|
||||
# Function to display an error message and exit
|
||||
error_exit() {
|
||||
echo "Error: $1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Update package index and upgrade system
|
||||
echo "Updating system packages..."
|
||||
sudo apt update && sudo apt upgrade -y || error_exit "Failed to update system packages."
|
||||
|
||||
# Install required packages for repository setup
|
||||
echo "Installing prerequisites..."
|
||||
sudo apt install -y ca-certificates curl gnupg || error_exit "Failed to install prerequisites."
|
||||
|
||||
# Create directory for Docker GPG key
|
||||
echo "Setting up GPG keyring..."
|
||||
sudo mkdir -p /etc/apt/keyrings || error_exit "Failed to create keyring directory."
|
||||
|
||||
# Add Docker's official GPG key
|
||||
DOCKER_GPG_KEY=/etc/apt/keyrings/docker.gpg
|
||||
echo "Adding Docker GPG key..."
|
||||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o $DOCKER_GPG_KEY || error_exit "Failed to add Docker GPG key."
|
||||
sudo chmod a+r $DOCKER_GPG_KEY
|
||||
|
||||
# Set up Docker repository
|
||||
echo "Adding Docker repository..."
|
||||
REPO_ENTRY="deb [arch=$(dpkg --print-architecture) signed-by=$DOCKER_GPG_KEY] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
|
||||
if ! grep -Fxq "$REPO_ENTRY" /etc/apt/sources.list.d/docker.list; then
|
||||
echo "$REPO_ENTRY" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null || error_exit "Failed to add Docker repository."
|
||||
fi
|
||||
|
||||
# Update package index
|
||||
echo "Updating package index..."
|
||||
sudo apt update || error_exit "Failed to update package index."
|
||||
|
||||
# Install Docker Engine, CLI, and dependencies
|
||||
echo "Installing Docker Engine and dependencies..."
|
||||
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin || error_exit "Failed to install Docker packages."
|
||||
|
||||
# Verify Docker installation
|
||||
echo "Verifying Docker installation..."
|
||||
if ! docker --version; then
|
||||
error_exit "Docker installation verification failed."
|
||||
fi
|
||||
|
||||
# Run a test container
|
||||
echo "Running Docker test container..."
|
||||
if ! sudo docker run --rm hello-world; then
|
||||
error_exit "Docker test container failed to run."
|
||||
fi
|
||||
|
||||
# Add current user to Docker group (if not already added)
|
||||
echo "Configuring Docker group..."
|
||||
if ! groups $USER | grep -q '\bdocker\b'; then
|
||||
sudo usermod -aG docker $USER || error_exit "Failed to add user to Docker group."
|
||||
echo "User added to Docker group. Please log out and back in for this change to take effect."
|
||||
else
|
||||
echo "User is already in the Docker group."
|
||||
fi
|
||||
|
||||
# Enable Docker service on boot
|
||||
echo "Enabling Docker service on boot..."
|
||||
sudo systemctl enable docker || error_exit "Failed to enable Docker service."
|
||||
|
||||
# Success message
|
||||
echo "Docker installation completed successfully!"
|
||||
@@ -40,6 +40,7 @@ RUN mkdir -p /var/run/sshd && \
|
||||
echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config && \
|
||||
chown -R root:root /root/.ssh && \
|
||||
chmod -R 700 /root/.ssh/ && \
|
||||
touch /root/.ssh/authorized_keys \
|
||||
chmod 600 /root/.ssh/authorized_keys && \
|
||||
service ssh start
|
||||
|
||||
|
||||
113
docker/herolib/README.md
Normal file
113
docker/herolib/README.md
Normal file
@@ -0,0 +1,113 @@
|
||||
# HeroLib Docker Environment
|
||||
|
||||
This directory contains the Docker configuration and scripts for setting up and managing the HeroLib development environment. The environment includes a containerized setup with VSCode server, SSH access, and PostgreSQL database.
|
||||
|
||||
## Key Components
|
||||
|
||||
### Docker Configuration Files
|
||||
|
||||
- `Dockerfile`: Defines the container image based on Ubuntu 24.04, installing necessary dependencies including:
|
||||
- V language and its analyzer
|
||||
- VSCode server
|
||||
- SSH server
|
||||
- Development tools (curl, tmux, htop, etc.)
|
||||
- HeroLib installation
|
||||
|
||||
- `docker-compose.yml`: Orchestrates the multi-container setup with:
|
||||
- PostgreSQL database service
|
||||
- HeroLib development environment
|
||||
- Port mappings for various services
|
||||
- Volume mounting for code persistence
|
||||
|
||||
## Scripts
|
||||
|
||||
### Container Management
|
||||
|
||||
- `shell.sh`: Interactive shell access script that:
|
||||
- Checks if the container is running
|
||||
- Starts the container if it's stopped
|
||||
- Verifies port accessibility (default: 4000)
|
||||
- Provides interactive bash session inside the container
|
||||
|
||||
- `debug.sh`: Launches the container in debug mode with:
|
||||
- Interactive terminal
|
||||
- Volume mounts for scripts and code
|
||||
- Port mappings for various services (4000-4379)
|
||||
- Custom entrypoint using ourinit.sh
|
||||
|
||||
- `export.sh`: Creates a compressed export of the container:
|
||||
- Stops any running instances
|
||||
- Launches a temporary container
|
||||
- Runs cleanup script
|
||||
- Exports and compresses the container to ~/Downloads/herolib.tar.gz
|
||||
|
||||
### SSH Access
|
||||
|
||||
- `ssh.sh`: Simple SSH connection script to access the container via port 4022
|
||||
|
||||
- `ssh_init.sh`: Configures SSH access by:
|
||||
- Collecting public keys from local ~/.ssh directory
|
||||
- Setting up authorized_keys in the container
|
||||
- Installing and configuring SSH server
|
||||
- Setting appropriate permissions
|
||||
- Enabling root login with key authentication
|
||||
|
||||
### Internal Scripts (in scripts/)
|
||||
|
||||
- `cleanup.sh`: Comprehensive system cleanup script that:
|
||||
- Removes unused packages and dependencies
|
||||
- Cleans APT cache
|
||||
- Removes old log files
|
||||
- Clears temporary files and caches
|
||||
- Performs system maintenance tasks
|
||||
|
||||
- `install_herolib.vsh`: V script for HeroLib installation:
|
||||
- Sets up necessary symlinks
|
||||
- Configures V module structure
|
||||
- Adds useful shell aliases (e.g., vtest)
|
||||
|
||||
- `ourinit.sh`: Container initialization script that:
|
||||
- Starts Redis server in daemon mode
|
||||
- Launches VSCode server in a tmux session
|
||||
- Starts SSH service
|
||||
- Provides interactive bash shell
|
||||
|
||||
## Port Mappings
|
||||
|
||||
- 4000:3000 - Main application port
|
||||
- 4022:22 - SSH access
|
||||
- 4100:8100 - Additional service port
|
||||
- 4101:8101 - Additional service port
|
||||
- 4102:8102 - Additional service port
|
||||
- 4379:6379 - Redis port
|
||||
|
||||
## Usage
|
||||
|
||||
1. Build and start the environment:
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
2. Access the container shell:
|
||||
```bash
|
||||
./shell.sh
|
||||
```
|
||||
|
||||
3. Connect via SSH:
|
||||
```bash
|
||||
./ssh.sh
|
||||
```
|
||||
|
||||
4. Debug mode (interactive with direct terminal):
|
||||
```bash
|
||||
./debug.sh
|
||||
```
|
||||
|
||||
5. Create container export:
|
||||
```bash
|
||||
./export.sh
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
The environment mounts your local `~/code` directory to `/root/code` inside the container, allowing for seamless development between host and container. The PostgreSQL database persists data using a named volume.
|
||||
Reference in New Issue
Block a user