This commit is contained in:
2025-02-02 21:56:59 +03:00
parent a5398094da
commit 1d6af5204b
21 changed files with 172 additions and 439 deletions

View File

@@ -1,3 +0,0 @@
.bash_history
.openvscode-server/
.cache/

View File

@@ -1,48 +0,0 @@
# Use Ubuntu 24.04 as the base image
FROM ubuntu:24.04
# Set the working directory
WORKDIR /root
# Copy local installation scripts into the container
COPY scripts/install_v.sh /tmp/install_v.sh
COPY scripts/install_herolib.vsh /tmp/install_herolib.vsh
COPY scripts/install_vscode.sh /tmp/install_vscode.sh
COPY scripts/ourinit.sh /usr/local/bin/
# Make the scripts executable
RUN chmod +x /tmp/install_v.sh /tmp/install_herolib.vsh
RUN apt-get update && apt-get install -y \
curl bash sudo mc wget tmux htop openssh-server
RUN bash /tmp/install_v.sh
RUN yes y | bash /tmp/install_v.sh --analyzer
RUN bash /tmp/install_vscode.sh
RUN /tmp/install_herolib.vsh && \
mkdir -p /var/run/sshd && \
echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config && \
echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config && \
chown -R root:root /root/.ssh && \
chmod -R 700 /root/.ssh/ && \
chmod 600 /root/.ssh/authorized_keys && \
service ssh start && \
apt-get clean && \
echo "PS1='HERO: \w \$ '" >> ~/.bashrc \
rm -rf /var/lib/apt/lists/*
#SSH
RUN mkdir -p /var/run/sshd && \
echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config && \
echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config && \
chown -R root:root /root/.ssh && \
chmod -R 700 /root/.ssh/ && \
chmod 600 /root/.ssh/authorized_keys && \
service ssh start
ENTRYPOINT ["/bin/bash"]
CMD ["/bin/bash"]

View File

@@ -1,36 +0,0 @@
#!/bin/bash -e
# Get the directory where the script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"
# Docker image and container names
DOCKER_IMAGE_NAME="docusaurus"
DEBUG_CONTAINER_NAME="herolib"
function cleanup {
if docker ps -aq -f name="$DEBUG_CONTAINER_NAME" &>/dev/null; then
echo "Cleaning up leftover debug container..."
docker rm -f "$DEBUG_CONTAINER_NAME" &>/dev/null || true
fi
}
trap cleanup EXIT
# Attempt to build the Docker image
BUILD_LOG=$(mktemp)
set +e
docker build --name herolib --progress=plain -t "$DOCKER_IMAGE_NAME" .
BUILD_EXIT_CODE=$?
set -e
# Handle build failure
if [ $BUILD_EXIT_CODE -ne 0 ]; then
echo -e "\\n[ERROR] Docker build failed.\n"
echo -e "remove the part which didn't build in the Dockerfile, the run again and to debug do:"
echo docker run --name herolib -it --entrypoint=/bin/bash "herolib"
exit $BUILD_EXIT_CODE
else
echo -e "\\n[INFO] Docker build completed successfully."
fi

View File

@@ -1,19 +0,0 @@
#!/bin/bash -ex
# Get the directory where the script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Remove any existing container named 'debug' (ignore errors)
docker rm -f herolib > /dev/null 2>&1
docker run --name herolib -it \
--entrypoint="/usr/local/bin/ourinit.sh" \
-v "${SCRIPT_DIR}/scripts:/scripts" \
-v "$HOME/code:/root/code" \
-p 4100:8100 \
-p 4101:8101 \
-p 4102:8102 \
-p 4379:6379 \
-p 4022:22 \
-p 4000:3000 herolib

View File

@@ -1,34 +0,0 @@
services:
postgres:
image: postgres:latest
container_name: postgres_service
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: planetfirst
POSTGRES_DB: mydb
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
herolib:
build:
context: .
dockerfile: Dockerfile
image: herolib:latest
container_name: herolib
volumes:
- ~/code:/root/code
stdin_open: true
tty: true
ports:
- "4100:8100"
- "4101:8101"
- "4102:8102"
- "4379:6379"
- "4000:3000"
- "4022:22"
command: ["/usr/local/bin/ourinit.sh"]
volumes:
postgres_data:

View File

@@ -1,98 +0,0 @@
#!/bin/bash -e
# Set version and file variables
OPENVSCODE_SERVER_VERSION="1.97.0"
TMP_DIR="/tmp"
FILENAME="openvscode.tar.gz"
FILE_PATH="$TMP_DIR/$FILENAME"
INSTALL_DIR="/opt/openvscode"
BIN_PATH="/usr/local/bin/openvscode-server"
TMUX_SESSION="openvscode-server"
# Function to detect architecture
get_architecture() {
ARCH=$(uname -m)
case "$ARCH" in
x86_64)
echo "x64"
;;
aarch64)
echo "arm64"
;;
*)
echo "Unsupported architecture: $ARCH" >&2
exit 1
;;
esac
}
# Check if OpenVSCode Server is already installed
if [ -d "$INSTALL_DIR" ] && [ -x "$BIN_PATH" ]; then
echo "OpenVSCode Server is already installed at $INSTALL_DIR. Skipping download and installation."
else
# Determine architecture-specific URL
ARCH=$(get_architecture)
if [ "$ARCH" == "x64" ]; then
DOWNLOAD_URL="https://github.com/gitpod-io/openvscode-server/releases/download/openvscode-server-insiders-v${OPENVSCODE_SERVER_VERSION}/openvscode-server-insiders-v${OPENVSCODE_SERVER_VERSION}-linux-x64.tar.gz"
elif [ "$ARCH" == "arm64" ]; then
DOWNLOAD_URL="https://github.com/gitpod-io/openvscode-server/releases/download/openvscode-server-insiders-v${OPENVSCODE_SERVER_VERSION}/openvscode-server-insiders-v${OPENVSCODE_SERVER_VERSION}-linux-arm64.tar.gz"
fi
# Navigate to temporary directory
cd "$TMP_DIR"
# Remove existing file if it exists
if [ -f "$FILE_PATH" ]; then
rm -f "$FILE_PATH"
fi
# Download file using curl
curl -L "$DOWNLOAD_URL" -o "$FILE_PATH"
# Verify file size is greater than 40 MB (40 * 1024 * 1024 bytes)
FILE_SIZE=$(stat -c%s "$FILE_PATH")
if [ "$FILE_SIZE" -le $((40 * 1024 * 1024)) ]; then
echo "Error: Downloaded file size is less than 40 MB." >&2
exit 1
fi
# Extract the tar.gz file
EXTRACT_DIR="openvscode-server-insiders-v${OPENVSCODE_SERVER_VERSION}-linux-${ARCH}"
tar -xzf "$FILE_PATH"
# Move the extracted directory to the install location
if [ -d "$INSTALL_DIR" ]; then
rm -rf "$INSTALL_DIR"
fi
mv "$EXTRACT_DIR" "$INSTALL_DIR"
# Create a symlink for easy access
ln -sf "$INSTALL_DIR/bin/openvscode-server" "$BIN_PATH"
# Verify installation
if ! command -v openvscode-server >/dev/null 2>&1; then
echo "Error: Failed to create symlink for openvscode-server." >&2
exit 1
fi
# Install default plugins
PLUGINS=("ms-python.python" "esbenp.prettier-vscode" "saoudrizwan.claude-dev" "yzhang.markdown-all-in-one" "ms-vscode-remote.remote-ssh" "ms-vscode.remote-explorer" "charliermarsh.ruff" "qwtel.sqlite-viewer" "vosca.vscode-v-analyzer" "tomoki1207.pdf")
for PLUGIN in "${PLUGINS[@]}"; do
"$INSTALL_DIR/bin/openvscode-server" --install-extension "$PLUGIN"
done
echo "Default plugins installed: ${PLUGINS[*]}"
# Clean up temporary directory
if [ -d "$TMP_DIR" ]; then
find "$TMP_DIR" -maxdepth 1 -type f -name "openvscode*" -exec rm -f {} \;
fi
fi
# Start OpenVSCode Server in a tmux session
if tmux has-session -t "$TMUX_SESSION" 2>/dev/null; then
tmux kill-session -t "$TMUX_SESSION"
fi
tmux new-session -d -s "$TMUX_SESSION" "$INSTALL_DIR/bin/openvscode-server"
echo "OpenVSCode Server is running in a tmux session named '$TMUX_SESSION'."

View File

@@ -1,14 +0,0 @@
#!/bin/bash -e
# redis-server --daemonize yes
# TMUX_SESSION="vscode"
# # Start OpenVSCode Server in a tmux session
# if tmux has-session -t "$TMUX_SESSION" 2>/dev/null; then
# tmux kill-session -t "$TMUX_SESSION"
# fi
# tmux new-session -d -s "$TMUX_SESSION" "/usr/local/bin/openvscode-server --host 0.0.0.0 --without-connection-token"
# service ssh start
exec /bin/bash

View File

@@ -1,61 +0,0 @@
#!/bin/bash -e
# Get the directory where the script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"
CONTAINER_NAME="herolib"
TARGET_PORT=4000
# Function to check if a container is running
is_container_running() {
docker ps --filter "name=$CONTAINER_NAME" --filter "status=running" -q
}
# Function to check if a port is accessible
is_port_accessible() {
nc -zv 127.0.0.1 "$1" &>/dev/null
}
# Check if the container exists and is running
if ! is_container_running; then
echo "Container $CONTAINER_NAME is not running."
# Check if the container exists but is stopped
if docker ps -a --filter "name=$CONTAINER_NAME" -q | grep -q .; then
echo "Starting existing container $CONTAINER_NAME..."
docker start "$CONTAINER_NAME"
else
echo "Container $CONTAINER_NAME does not exist. Attempting to start with start.sh..."
if [[ -f "$SCRIPT_DIR/start.sh" ]]; then
bash "$SCRIPT_DIR/start.sh"
else
echo "Error: start.sh not found in $SCRIPT_DIR."
exit 1
fi
fi
# Wait for the container to be fully up
sleep 5
fi
# Verify the container is running
if ! is_container_running; then
echo "Error: Failed to start container $CONTAINER_NAME."
exit 1
fi
echo "Container $CONTAINER_NAME is running."
# Check if the target port is accessible
if is_port_accessible "$TARGET_PORT"; then
echo "Port $TARGET_PORT is accessible."
else
echo "Port $TARGET_PORT is not accessible. Please check the service inside the container."
fi
# Enter the container
echo
echo " ** WE NOW LOGIN TO THE CONTAINER ** "
echo
docker exec -it herolib bash

View File

@@ -1,3 +0,0 @@
#!/bin/bash -e
ssh root@localhost -p 4022

View File

@@ -1,63 +0,0 @@
#!/bin/bash -e
# Get the directory where the script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"
# Define variables
CONTAINER_NAME="herolib"
CONTAINER_SSH_DIR="/root/.ssh"
AUTHORIZED_KEYS="authorized_keys"
TEMP_AUTH_KEYS="/tmp/authorized_keys"
# Step 1: Create a temporary file to store public keys
> $TEMP_AUTH_KEYS # Clear the file if it exists
# Step 2: Add public keys from ~/.ssh/ if they exist
if ls ~/.ssh/*.pub 1>/dev/null 2>&1; then
cat ~/.ssh/*.pub >> $TEMP_AUTH_KEYS
fi
# Step 3: Check if ssh-agent is running and get public keys from it
if pgrep ssh-agent >/dev/null; then
echo "ssh-agent is running. Fetching keys..."
ssh-add -L >> $TEMP_AUTH_KEYS 2>/dev/null
else
echo "ssh-agent is not running or no keys loaded."
fi
# Step 4: Ensure the temporary file is not empty
if [ ! -s $TEMP_AUTH_KEYS ]; then
echo "No public keys found. Exiting."
exit 1
fi
# Step 5: Ensure the container's SSH directory exists
docker exec -it $CONTAINER_NAME mkdir -p $CONTAINER_SSH_DIR
docker exec -it $CONTAINER_NAME chmod 700 $CONTAINER_SSH_DIR
# Step 6: Copy the public keys into the container's authorized_keys file
docker cp $TEMP_AUTH_KEYS $CONTAINER_NAME:$CONTAINER_SSH_DIR/$AUTHORIZED_KEYS
# Step 7: Set proper permissions for authorized_keys
docker exec -it $CONTAINER_NAME chmod 600 $CONTAINER_SSH_DIR/$AUTHORIZED_KEYS
# Step 8: Install and start the SSH server inside the container
docker exec -it $CONTAINER_NAME bash -c "
apt-get update &&
apt-get install -y openssh-server &&
mkdir -p /var/run/sshd &&
echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config &&
echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config &&
chown -R root:root /root/.ssh &&
chmod -R 700 /root/.ssh/ &&
chmod 600 /root/.ssh/authorized_keys &&
service ssh start
"
# Step 9: Clean up temporary file on the host
rm $TEMP_AUTH_KEYS
echo "SSH keys added and SSH server configured. You can now SSH into the container."
ssh root@localhost -p 4022

View File

@@ -0,0 +1,20 @@
version: '3.9'
services:
db:
image: 'postgres:17.2-alpine3.21'
restart: always
environment:
POSTGRES_PASSWORD: 1234
networks:
- my_network
adminer:
image: adminer
restart: always
ports:
- 8080:8080
networks:
- my_network
networks:
my_network:

View File

@@ -0,0 +1,6 @@
Server (Host): db (because Docker Compose creates an internal network and uses service names as hostnames)
Username: postgres (default PostgreSQL username)
Password: 1234 (as set in your POSTGRES_PASSWORD environment variable)
Database: Leave it empty or enter postgres (default database)

View File

@@ -5,3 +5,5 @@ docker_init
docker_registry
presearch_docker
tf_dashboard
docker_dev
docker_ubuntu

View File

@@ -0,0 +1,61 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.virt.docker
fn build()!{
mut engine := docker.new(prefix: '', localonly: true)!
mut r := engine.recipe_new(name: 'dev_tools', platform: .alpine)
r.add_from(image: 'alpine', tag: 'latest')!
r.add_package(name: 'git,mc,htop')!
r.add_zinit()!
r.add_sshserver()!
r.build(true)!
}
// build()!
mut engine := docker.new(prefix: '', localonly: true)!
// Check if dev_tools image exists
if ! engine.image_exists(repo: 'dev_tools') !{
eprintln("image dev_tools doesn't exist, build it")
build()!
}
engine.container_delete( name: 'dev2') or {}
// Check if container exists and get its status
mut container := engine.container_get(
name: 'dev2'
) or {
// Container doesn't exist, create it
println('Creating dev2 container...')
engine.container_create(
name: 'dev2'
image_repo: 'dev_tools'
remove_when_done: false
forwarded_ports: ["8022:22/tcp"] //this forward 8022 on host to 22 on container
env:{"SSH_KEY":"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIahWiRRm9cWAKktH9dndn3R45grKqzPC3mKX8IjGgH6 kristof@incubaid.com"}
)!
}
// Start container if not running
if container.status != .up {
println('Starting dev2 container...')
container.start()!
}
// Open shell to container
println('Opening shell to dev2 container...')
container.shell()!

View File

@@ -1,35 +0,0 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.virt.docker
mut engine := docker.new(prefix: '', localonly: true)!
// Check if dev_tools image exists
if ! engine.image_exists(repo: 'dev_tools') !{
eprintln("image dev_tools doesn't exist, build it")
exit(1)
}
// Check if container exists and get its status
mut container := engine.container_get(
name: 'dev_tools'
) or {
// Container doesn't exist, create it
println('Creating dev_tools container...')
engine.container_create(
name: 'dev_tools'
image_repo: 'dev_tools'
remove_when_done: false
)!
}
// Start container if not running
if container.status != .up {
println('Starting dev_tools container...')
container.start()!
}
// Open shell to container
println('Opening shell to dev_tools container...')
container.shell()!

View File

@@ -1,17 +0,0 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.virt.docker
mut engine := docker.new(prefix: '', localonly: true)!
mut r := engine.recipe_new(name: 'dev_tools', platform: .alpine)
r.add_from(image: 'alpine', tag: 'latest')!
r.add_package(name: 'git,mc')!
r.add_zinit()!
r.add_sshserver()!
r.build(true)!

View File

@@ -0,0 +1,61 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.virt.docker
fn build()!{
mut engine := docker.new(prefix: '', localonly: true)!
mut r := engine.recipe_new(name: 'dev_ubuntu', platform: .ubuntu)
r.add_from(image: 'ubuntu', tag: '24.10')!
r.add_package(name: 'git,mc,htop')!
r.add_zinit()!
r.add_sshserver()!
r.build(true)!
}
build()!
mut engine := docker.new(prefix: '', localonly: true)!
// Check if dev_ubuntu image exists
if ! engine.image_exists(repo: 'dev_ubuntu') !{
eprintln("image dev_ubuntu doesn't exist, build it")
build()!
}
engine.container_delete( name: 'dev3') or {}
// Check if container exists and get its status
mut container := engine.container_get(
name: 'dev3'
) or {
// Container doesn't exist, create it
println('Creating dev3 container...')
engine.container_create(
name: 'dev3'
image_repo: 'dev_ubuntu'
remove_when_done: false
forwarded_ports: ["8023:22/tcp"] //this forward 8022 on host to 22 on container
env:{"SSH_KEY":"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIahWiRRm9cWAKktH9dndn3R45grKqzPC3mKX8IjGgH6 kristof@incubaid.com"}
)!
}
// Start container if not running
if container.status != .up {
println('Starting dev3 container...')
container.start()!
}
// Open shell to container
println('Opening shell to dev3 container...')
container.shell()!

View File

@@ -16,7 +16,7 @@ pub mut:
remove_when_done bool = true // remove the container when it shuts down
image_repo string
image_tag string
command string = '/bin/bash'
command string
}

View File

@@ -72,6 +72,7 @@ pub fn (mut b DockerBuilderRecipe) add_package(args PackageArgs) ! {
}
}
// lets now check of the package has already not been set before
for package0 in b.items {
if package0 is PackageItem {
@@ -79,12 +80,13 @@ pub fn (mut b DockerBuilderRecipe) add_package(args PackageArgs) ! {
for packagenamecompare in package.names {
if packagenamecompare == packagename {
// we found a double
return error('Cannot add the package again, there is a double. ${packagename} \n${b}')
continue
}
}
}
}
}
// console.print_debug(package)
if package.names.len == 0 {
return error('could not find package names.\n ${b}\nARGS:\n${args}')

View File

@@ -60,30 +60,42 @@ pub fn (mut r DockerBuilderRecipe) add_vbuilder() ! {
// add ssh server and init scripts (note: zinit needs to be installed)
pub fn (mut r DockerBuilderRecipe) add_sshserver() ! {
r.add_package(name: 'openssh-server')!
r.add_package(name: 'openssh-server, bash')!
r.add_zinit_cmd(
name: 'sshd-setup'
oneshot: true
exec: "
rm -rf /etc/ssh
mkdir -p /etc/ssh
mkdir -p /run/sshd
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa
ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key -N '' -t ecdsa -b 521
ssh-keygen -f /etc/ssh/ssh_host_ed25519_key -N '' -t ed25519
cat > /etc/ssh/sshd_config << 'EOF'
HostKey /etc/ssh/ssh_host_ed25519_key
PermitRootLogin prohibit-password
PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM no
X11Forwarding no
AllowTcpForwarding yes
AllowAgentForwarding yes
EOF
"
)!
r.add_zinit_cmd(
name: 'ssh-keys'
after: 'sshd-setup'
oneshot: true
exec: '
if [ ! -d /root/.ssh ]; then
mkdir -m 700 /root/.ssh
fi
echo \$SSH_KEY >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
if [ ! -z "\$SSH_KEY" ]; then
echo \$SSH_KEY >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
fi
'
)!