From 26abc4a9d888b7e492b8f3ded853dd40db84fe5e Mon Sep 17 00:00:00 2001 From: Oliver Braun Date: Thu, 23 Oct 2025 20:16:13 +0200 Subject: [PATCH] feat: expand env for viper --- .devcontainer/Dockerfile | 57 +++++++++++++++++++++++++ .devcontainer/devcontainer.json | 74 +++++++++++++++++++++++++++++++++ cmd/root.go | 6 ++- 3 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..5680ab3 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,57 @@ +FROM ubuntu:24.04 + +# Umgebungsvariablen setzen +ENV DEBIAN_FRONTEND=noninteractive +ENV TZ=Europe/Berlin + +# System-Updates und grundlegende Tools installieren +RUN apt-get update && apt-get install -y \ + curl \ + wget \ + git \ + unzip \ + software-properties-common \ + apt-transport-https \ + ca-certificates \ + gnupg \ + lsb-release \ + vim \ + nano \ + tree \ + htop \ + sudo \ + make \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Zeitzone konfigurieren +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +# Erstelle einen non-root Benutzer +ARG USERNAME=vscode +ARG USER_UID=1001 +ARG USER_GID=$USER_UID +RUN groupadd --gid $USER_GID $USERNAME \ + && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \ + && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ + && chmod 0440 /etc/sudoers.d/$USERNAME + +# Shared bin Verzeichnis erstellen und Rechte setzen +RUN mkdir -p /shared/bin && chown -R $USERNAME:$USERNAME /shared/bin + +# Arbeitsverzeichnis setzen +WORKDIR /workspace/plexams.go + +# Benutzer wechseln +USER $USERNAME + +# # Delve Debugger installieren +# RUN /usr/local/go/bin/go install github.com/go-delve/delve/cmd/dlv@latest +# ENV PATH="/home/vscode/go/bin:$PATH" + +# Set GOBIN to shared volume +ENV GOBIN=/shared/bin +ENV PATH="${PATH}:/shared/bin" + +# Standard-Befehl +CMD ["/bin/bash"] diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..3ec5b2f --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,74 @@ +{ + "name": "plexams-go", + "build": { + "dockerfile": "Dockerfile" + }, + + "features": { + "ghcr.io/devcontainers/features/go:1": { + "version": "1.25.1" + } + }, + + "customizations": { + "vscode": { + "extensions": [ + "golang.Go", + "eamodio.gitlens", + "gruntfuggly.todo-tree", + "oderwat.indent-rainbow", + "pkief.material-icon-theme" + ], + "settings": { + "go.useLanguageServer": true, + "go.lintTool": "golangci-lint-v2", + "go.lintFlags": ["--path-mode=abs", "--fast-only"], + "go.formatTool": "custom", + "go.alternateTools": { + "customFormatter": "golangci-lint-v2" + }, + "go.formatFlags": ["fmt", "--stdin"], + "go.testOnSave": true, + "editor.formatOnSave": true, + "editor.tabSize": 4, + "editor.insertSpaces": true, + "editor.detectIndentation": true, + "editor.rulers": [80, 120], + "files.exclude": { + "**/.git": true, + "**/.svn": true, + "**/.hg": true, + "**/CVS": true, + "**/.DS_Store": true + }, + "terminal.integrated.defaultProfile.linux": "bash", + "terminal.integrated.cwd": "${workspaceFolder}" + } + } + }, + + "mounts": [ + "source=shared-binaries,target=/shared/bin,type=volume", + "source=${localEnv:HOME}/.gitconfig,target=/home/vscode/.gitconfig,type=bind,consistency=cached", + "source=${localEnv:HOME}/.ssh,target=/home/vscode/.ssh,type=bind,consistency=cached", + "source=${localEnv:HOME}/.plexams.yml,target=/home/vscode/.plexams.yml,type=bind,consistency=cached", + "source=${localEnv:HOME}/semester,target=/home/vscode/semester,type=bind,consistency=cached" + ], + + "forwardPorts": [8080, 8081, 8082], + "portsAttributes": { + "8080": { + "label": "Application", + "onAutoForward": "notify" + } + }, + + "postCreateCommand": "sudo chown -R vscode:vscode /shared/bin && go mod download", + + "remoteEnv": { + "GOBIN": "/shared/bin", + "PATH": "${containerEnv:PATH}:/shared/bin" + }, + + "runArgs": ["--network=host"] +} diff --git a/cmd/root.go b/cmd/root.go index 8f19db9..1e24b8e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -3,6 +3,7 @@ package cmd import ( "fmt" "os" + "path/filepath" "strings" "github.com/mitchellh/go-homedir" @@ -78,7 +79,10 @@ func initConfig() { if semester == "" { semester = viper.GetString("semester") } - viper.AddConfigPath(fmt.Sprintf("%s/%s", viper.GetString("semester-path"), semester)) + p := viper.GetString("semester-path") + p = os.ExpandEnv(p) // $HOME, $USER, ... + p, _ = homedir.Expand(p) // ~ und ~user + viper.AddConfigPath(filepath.Join(p, semester)) viper.SetConfigName("plexams") err = viper.MergeInConfig() if err != nil {