mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-10-13 16:35:07 +03:00
Merge ce2b55c5b3
into d0b5352db3
This commit is contained in:
commit
89a05cb1a8
49 changed files with 8599 additions and 27 deletions
70
contrib/docker/devcontainer/Dockerfile
Normal file
70
contrib/docker/devcontainer/Dockerfile
Normal file
|
@ -0,0 +1,70 @@
|
|||
# Development Dockerfile for VS Code Dev Containers
|
||||
FROM golang:1.24-bullseye
|
||||
|
||||
# Install only essential system packages
|
||||
RUN apt-get update && apt-get install -y \
|
||||
git \
|
||||
ca-certificates \
|
||||
sudo \
|
||||
zsh \
|
||||
locales \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install essential Go development tools only
|
||||
RUN go install golang.org/x/tools/gopls@latest \
|
||||
&& go install github.com/go-delve/delve/cmd/dlv@latest \
|
||||
&& go install golang.org/x/tools/cmd/goimports@latest \
|
||||
&& go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
||||
|
||||
# Create a non-root user for development
|
||||
ARG USERNAME=vscode
|
||||
ARG USER_UID=1000
|
||||
ARG USER_GID=$USER_UID
|
||||
|
||||
# Create user and group with proper permissions
|
||||
RUN groupadd --gid $USER_GID $USERNAME \
|
||||
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME -s /bin/zsh \
|
||||
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
|
||||
&& chmod 0440 /etc/sudoers.d/$USERNAME
|
||||
|
||||
# Fix Go module cache permissions
|
||||
RUN chown -R $USERNAME:$USERNAME /go/pkg/mod || true \
|
||||
&& chmod -R 755 /go/pkg/mod || true
|
||||
|
||||
# Create default yggdrasil conf directory
|
||||
RUN mkdir -p /etc/yggdrasil \
|
||||
&& chown -R $USERNAME:$USERNAME /etc/yggdrasil
|
||||
|
||||
# Set up the workspace with proper ownership
|
||||
WORKDIR /workspace
|
||||
RUN chown $USERNAME:$USERNAME /workspace
|
||||
|
||||
# Copy go module files to enable dependency caching
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download && chown -R $USERNAME:$USERNAME /workspace
|
||||
|
||||
# Install Oh My Zsh for better terminal experience
|
||||
RUN sh -c "ZSH=/usr/local/share/zsh/oh-my-zsh $(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" --unattended \
|
||||
&& ZSH_CUSTOM=/usr/local/share/zsh/oh-my-zsh/custom \
|
||||
&& git clone https://github.com/chrissicool/zsh-256color $ZSH_CUSTOM/plugins/zsh-256color \
|
||||
&& git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions \
|
||||
&& git clone https://github.com/popstas/zsh-command-time.git $ZSH_CUSTOM/plugins/command-time
|
||||
|
||||
# Setup zshrc
|
||||
COPY contrib/docker/devcontainer/zshrc /usr/local/share/zsh/.zshrc
|
||||
RUN rm -f /root/.zshrc \
|
||||
&& ln -s /usr/local/share/zsh/.zshrc /root/.zshrc \
|
||||
&& ln -s /usr/local/share/zsh/.zshrc /home/vscode/.zshrc
|
||||
|
||||
# Set up shell environment for vscode user
|
||||
USER $USERNAME
|
||||
|
||||
# Set up shell environment for vscode user
|
||||
ENV SHELL=/bin/zsh
|
||||
|
||||
# Expose common ports that might be used by Yggdrasil
|
||||
EXPOSE 9001 9002 9003
|
||||
|
||||
# Keep container running for dev containers
|
||||
CMD ["sleep", "infinity"]
|
36
contrib/docker/devcontainer/Makefile
Normal file
36
contrib/docker/devcontainer/Makefile
Normal file
|
@ -0,0 +1,36 @@
|
|||
# Development container management
|
||||
|
||||
.PHONY: dev-build dev-run dev-shell dev-stop dev-clean
|
||||
|
||||
# Build development container
|
||||
dev-build:
|
||||
docker build -f Dockerfile -t yggdrasil-dev .
|
||||
|
||||
# Run development container with volume mounts
|
||||
dev-run:
|
||||
docker run -it --rm \
|
||||
--name yggdrasil-dev \
|
||||
-v $(PWD):/workspace \
|
||||
-v ~/.gitconfig:/home/vscode/.gitconfig:ro \
|
||||
-p 9001:9001 \
|
||||
-p 9002:9002 \
|
||||
-p 9003:9003 \
|
||||
--privileged \
|
||||
--cap-add=NET_ADMIN \
|
||||
yggdrasil-dev
|
||||
|
||||
# Get shell access to running container
|
||||
dev-shell:
|
||||
docker exec -it yggdrasil-dev /bin/zsh
|
||||
|
||||
# Stop development container
|
||||
dev-stop:
|
||||
docker stop yggdrasil-dev || true
|
||||
|
||||
# Clean development artifacts
|
||||
dev-clean:
|
||||
docker rmi yggdrasil-dev || true
|
||||
docker system prune -f
|
||||
|
||||
# Build and run in one command
|
||||
dev: dev-build dev-run
|
112
contrib/docker/devcontainer/README.md
Normal file
112
contrib/docker/devcontainer/README.md
Normal file
|
@ -0,0 +1,112 @@
|
|||
# Development Environment Setup
|
||||
|
||||
This document describes how to set up a development environment for Yggdrasil using Docker and VS Code Dev Containers.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Docker installed and running
|
||||
- VS Code with the "Dev Containers" extension installed
|
||||
- Git configured with your user information
|
||||
|
||||
## Option 1: VS Code Dev Containers (Recommended)
|
||||
|
||||
1. Open this project in VS Code
|
||||
2. When prompted, click "Reopen in Container" or:
|
||||
- Press `Ctrl+Shift+P` (or `Cmd+Shift+P` on macOS)
|
||||
- Type "Dev Containers: Reopen in Container"
|
||||
- Select the option
|
||||
|
||||
VS Code will automatically build the development container and set up the environment with:
|
||||
- Go 1.23 with all necessary tools
|
||||
- Language server (gopls)
|
||||
- Linting (golangci-lint)
|
||||
- Debugging support (delve)
|
||||
- Git integration
|
||||
- Zsh shell with Oh My Zsh
|
||||
|
||||
## Option 2: Manual Docker Container
|
||||
|
||||
If you prefer to use Docker directly:
|
||||
|
||||
### Using Makefile commands:
|
||||
|
||||
```bash
|
||||
# Build and run the development container
|
||||
make -f Makefile dev
|
||||
|
||||
# Or build and run separately
|
||||
make -f Makefile dev-build
|
||||
make -f Makefile dev-run
|
||||
|
||||
# Get shell access to running container
|
||||
make -f Makefile dev-shell
|
||||
|
||||
# Stop the container
|
||||
make -f Makefile dev-stop
|
||||
|
||||
# Clean up
|
||||
make -f Makefile dev-clean
|
||||
```
|
||||
|
||||
### Using Docker directly:
|
||||
|
||||
```bash
|
||||
# Build the development image
|
||||
docker build -f Dockerfile -t yggdrasil-dev .
|
||||
|
||||
# Run the container
|
||||
docker run -it --rm \
|
||||
--name yggdrasil-dev \
|
||||
-v $(pwd):/workspace \
|
||||
-v ~/.gitconfig:/home/vscode/.gitconfig:ro \
|
||||
-p 9000:9000 \
|
||||
-p 9001:9001 \
|
||||
-p 9002:9002 \
|
||||
-p 9003:9003 \
|
||||
--privileged \
|
||||
--cap-add=NET_ADMIN \
|
||||
--device=/dev/net/tun \
|
||||
yggdrasil-dev
|
||||
```
|
||||
|
||||
## Development Features
|
||||
|
||||
The development environment includes:
|
||||
|
||||
- **Go Tools**: gopls, delve debugger, goimports, golangci-lint, staticcheck
|
||||
- **Editor Support**: Syntax highlighting, auto-completion, debugging
|
||||
- **Testing**: Go test runner and coverage tools
|
||||
- **Networking**: Privileged access for network interface testing
|
||||
- **Port Forwarding**: Ports 9000-9003 exposed for Yggdrasil services
|
||||
|
||||
## Building and Testing
|
||||
|
||||
Inside the container:
|
||||
|
||||
```bash
|
||||
# Build the project
|
||||
./build
|
||||
|
||||
# Run tests
|
||||
go test ./...
|
||||
|
||||
# Generate configuration
|
||||
./yggdrasil -genconf > yggdrasil.conf
|
||||
|
||||
# Run with configuration
|
||||
./yggdrasil -useconf yggdrasil.conf
|
||||
```
|
||||
|
||||
## Tips
|
||||
|
||||
1. Your local Git configuration is mounted into the container
|
||||
2. The workspace directory (`/workspace`) is mapped to your local project directory
|
||||
3. All changes made to source files are persistent on your host machine
|
||||
4. The container runs as a non-root user (`vscode`) for security
|
||||
5. Network capabilities are enabled for testing network-related features
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
- If the container fails to start, ensure Docker has enough resources allocated
|
||||
- For network-related issues, verify that the container has the necessary privileges
|
||||
- If Go tools are missing, rebuild the container: `make -f Makefile dev-clean dev-build`
|
37
contrib/docker/devcontainer/zshrc
Normal file
37
contrib/docker/devcontainer/zshrc
Normal file
|
@ -0,0 +1,37 @@
|
|||
export ZSH="/usr/local/share/zsh/oh-my-zsh"
|
||||
|
||||
ZSH_THEME="agnoster"
|
||||
CASE_SENSITIVE="true"
|
||||
zstyle ':omz:update' mode disabled # disable automatic updates
|
||||
DISABLE_UNTRACKED_FILES_DIRTY="true"
|
||||
HIST_STAMPS="mm/dd/yyyy"
|
||||
plugins=(git zsh-256color zsh-autosuggestions command-time sudo)
|
||||
|
||||
ZSH_DISABLE_COMPFIX=true
|
||||
ZSH_CACHE_DIR="$HOME/.cache/ohmyzsh"
|
||||
ZSH_COMPDUMP="${ZSH_CACHE_DIR}/.zcompdump-${HOST/.*/}-${ZSH_VERSION}"
|
||||
mkdir -p "$ZSH_CACHE_DIR"
|
||||
|
||||
source $ZSH/oh-my-zsh.sh
|
||||
|
||||
alias zshconfig="mate ~/.zshrc"
|
||||
alias ohmyzsh="mate ~/.oh-my-zsh"
|
||||
|
||||
prompt_context() {
|
||||
_bg=043
|
||||
[[ $UID -eq 0 ]] && _bg=202
|
||||
prompt_segment $_bg $CURRENT_FG "%m"
|
||||
}
|
||||
|
||||
prompt_status() {
|
||||
local -a symbols
|
||||
[[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}✘"
|
||||
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}⚙"
|
||||
[[ -n "$symbols" ]] && prompt_segment black default "$symbols"
|
||||
}
|
||||
|
||||
export PATH=$PATH:$(go env GOPATH 2>/dev/null)/bin
|
||||
export GO111MODULE=on
|
||||
export LANG=C.UTF-8
|
||||
export LC_ALL=C.UTF-8
|
||||
export LC_CTYPE=C.UTF-8
|
Loading…
Add table
Add a link
Reference in a new issue