mirror of
https://github.com/YuzuZensai/Minikura.git
synced 2026-01-31 14:57:49 +00:00
📦 build: Add devcontainer for local Kubernetes development
This commit is contained in:
78
.devcontainer/Dockerfile
Normal file
78
.devcontainer/Dockerfile
Normal file
@@ -0,0 +1,78 @@
|
||||
FROM ubuntu:24.04
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Install base packages
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
openssh-server \
|
||||
passwd \
|
||||
sudo \
|
||||
curl \
|
||||
wget \
|
||||
git \
|
||||
jq \
|
||||
unzip \
|
||||
ca-certificates \
|
||||
gnupg \
|
||||
lsb-release \
|
||||
iptables \
|
||||
iproute2 \
|
||||
postgresql-client \
|
||||
apt-transport-https \
|
||||
software-properties-common \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install Node.js 24
|
||||
RUN curl -fsSL https://deb.nodesource.com/setup_24.x | bash - \
|
||||
&& apt-get install -y --no-install-recommends nodejs \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install Bun
|
||||
RUN curl -fsSL https://bun.sh/install | bash \
|
||||
&& mv /root/.bun/bin/bun /usr/local/bin/ \
|
||||
&& ln -s /usr/local/bin/bun /usr/local/bin/bunx
|
||||
|
||||
# Install Docker
|
||||
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg \
|
||||
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list \
|
||||
&& apt-get update \
|
||||
&& apt-get install -y --no-install-recommends docker-ce docker-ce-cli containerd.io docker-compose-plugin \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install kubectl
|
||||
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/$(dpkg --print-architecture)/kubectl" \
|
||||
&& install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl \
|
||||
&& rm kubectl
|
||||
|
||||
# Install Helm
|
||||
RUN curl -fsSL https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
|
||||
|
||||
# Enable systemd
|
||||
RUN find /lib/systemd/system/sysinit.target.wants -mindepth 1 -not -name "systemd-tmpfiles-setup.service" -delete; \
|
||||
find /lib/systemd/system/multi-user.target.wants -mindepth 1 -not -name "systemd-user-sessions.service" -delete; \
|
||||
rm -f /etc/systemd/system/*.wants/*; \
|
||||
rm -f /lib/systemd/system/local-fs.target.wants/*; \
|
||||
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
|
||||
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
|
||||
rm -f /lib/systemd/system/basic.target.wants/*; \
|
||||
rm -f /lib/systemd/system/anaconda.target.wants/*;
|
||||
|
||||
# Create dev user with host UID/GID for seamless file permissions
|
||||
ARG HOST_UID=1000
|
||||
ARG HOST_GID=1000
|
||||
RUN userdel -r $(getent passwd ${HOST_UID} | cut -d: -f1) 2>/dev/null || true && \
|
||||
groupdel $(getent group ${HOST_GID} | cut -d: -f1) 2>/dev/null || true && \
|
||||
groupadd -g ${HOST_GID} dev && \
|
||||
useradd -m -s /bin/bash -u ${HOST_UID} -g ${HOST_GID} dev && \
|
||||
echo "dev:dev" | chpasswd && \
|
||||
echo 'dev ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/dev && \
|
||||
chmod 440 /etc/sudoers.d/dev && \
|
||||
usermod -aG docker dev
|
||||
|
||||
# Setup directories
|
||||
RUN mkdir -p /home/dev/.kube && chown -R dev:dev /home/dev
|
||||
|
||||
WORKDIR /workspace
|
||||
|
||||
VOLUME [ "/sys/fs/cgroup" ]
|
||||
CMD ["/usr/sbin/init"]
|
||||
31
.devcontainer/devcontainer.json
Normal file
31
.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "Minikura Development",
|
||||
"dockerComposeFile": "./docker-compose.yml",
|
||||
"service": "devcontainer",
|
||||
"workspaceFolder": "/workspace",
|
||||
"remoteUser": "dev",
|
||||
|
||||
"postCreateCommand": "bash /workspace/.devcontainer/post-create.sh",
|
||||
|
||||
"forwardPorts": [3000, 3001, 5432, 6443, 25565, 25577],
|
||||
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"biomejs.biome",
|
||||
"Prisma.prisma",
|
||||
"ms-kubernetes-tools.vscode-kubernetes-tools",
|
||||
"ms-azuretools.vscode-docker",
|
||||
"bradlc.vscode-tailwindcss",
|
||||
"redhat.vscode-yaml"
|
||||
],
|
||||
"settings": {
|
||||
"editor.defaultFormatter": "biomejs.biome",
|
||||
"editor.formatOnSave": true,
|
||||
"[prisma]": {
|
||||
"editor.defaultFormatter": "Prisma.prisma"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
55
.devcontainer/docker-compose.yml
Normal file
55
.devcontainer/docker-compose.yml
Normal file
@@ -0,0 +1,55 @@
|
||||
name: "minikura-devcontainer"
|
||||
services:
|
||||
devcontainer:
|
||||
tty: true
|
||||
privileged: true
|
||||
cgroup: host
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
args:
|
||||
HOST_UID: ${HOST_UID:-1000}
|
||||
HOST_GID: ${HOST_GID:-1000}
|
||||
tmpfs:
|
||||
- /var/lib/docker:mode=0777,dev,size=15g,suid,exec
|
||||
- /var/lib/rancher:mode=0777,dev,size=15g,suid,exec
|
||||
- /run
|
||||
ports:
|
||||
- "3000:3000" # backend API
|
||||
- "3001:3001" # web frontend
|
||||
- "6443:6443" # k3s API
|
||||
- "25565:25565" # minecraft
|
||||
- "25577:25577" # velocity
|
||||
volumes:
|
||||
- "../:/workspace"
|
||||
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
|
||||
working_dir: "/workspace"
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
- KUBECONFIG=/home/dev/.kube/config
|
||||
- DATABASE_URL=postgresql://postgres:postgres@db:5432/minikura?sslmode=disable
|
||||
- KUBERNETES_NAMESPACE=minikura
|
||||
- KUBERNETES_SKIP_TLS_VERIFY=true
|
||||
- ENABLE_CRD_REFLECTION=true
|
||||
|
||||
db:
|
||||
image: postgres:17
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: postgres
|
||||
POSTGRES_DB: minikura
|
||||
volumes:
|
||||
- postgres-data:/var/lib/postgresql/data
|
||||
ports:
|
||||
- "5433:5432"
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
volumes:
|
||||
postgres-data:
|
||||
57
.devcontainer/post-create.sh
Executable file
57
.devcontainer/post-create.sh
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "=============================================="
|
||||
echo " Minikura Development Environment Setup"
|
||||
echo "=============================================="
|
||||
|
||||
# Start Docker
|
||||
echo "==> Starting Docker..."
|
||||
sudo service docker start
|
||||
sleep 2
|
||||
sudo chmod 666 /var/run/docker.sock
|
||||
|
||||
# Install and start k3s via install script (sets up systemd service)
|
||||
echo "==> Installing k3s..."
|
||||
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--write-kubeconfig-mode 644 --disable traefik" sh -
|
||||
|
||||
# Wait for k3s to be ready
|
||||
echo "==> Waiting for k3s..."
|
||||
sleep 5
|
||||
|
||||
# Configure kubectl
|
||||
echo "==> Configuring kubectl..."
|
||||
mkdir -p /home/dev/.kube
|
||||
until [ -f /etc/rancher/k3s/k3s.yaml ]; do sleep 1; done
|
||||
sudo cp /etc/rancher/k3s/k3s.yaml /home/dev/.kube/config
|
||||
sudo chown dev:dev /home/dev/.kube/config
|
||||
|
||||
# Wait for node
|
||||
echo "==> Waiting for node..."
|
||||
for i in {1..30}; do
|
||||
kubectl get nodes 2>/dev/null | grep -q " Ready" && break
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Create namespace
|
||||
kubectl create namespace minikura --dry-run=client -o yaml | kubectl apply -f - 2>/dev/null || true
|
||||
|
||||
# Install dependencies
|
||||
echo "==> Installing dependencies..."
|
||||
cd /workspace
|
||||
sudo rm -rf node_modules apps/*/node_modules packages/*/node_modules 2>/dev/null || true
|
||||
sudo chown -R dev:dev /workspace
|
||||
bun install
|
||||
|
||||
# Setup database
|
||||
echo "==> Setting up database..."
|
||||
bun run db:generate
|
||||
bun run db:push
|
||||
|
||||
echo ""
|
||||
echo "=============================================="
|
||||
echo " Ready! Commands:"
|
||||
echo " bun run dev - Start backend + web"
|
||||
echo " bun run k8s:dev - Start K8s operator"
|
||||
echo " kubectl get nodes"
|
||||
echo "=============================================="
|
||||
Reference in New Issue
Block a user