diff --git a/.env b/.env new file mode 100644 index 0000000..7b07449 --- /dev/null +++ b/.env @@ -0,0 +1,5 @@ +# Git credentials for containerized opencode +GIT_NAME="João Carlos Machado de Paiva Araújo" +GIT_EMAIL="joaocarlosmpa@gmail.com" +GIT_TOKEN="" +# Leave empty if not using HTTPS token auth with Forgejo/GitLab diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..d3b4b73 --- /dev/null +++ b/.env.example @@ -0,0 +1,9 @@ +# Git credentials for containerized opencode +# Copy to .env and fill in your values + +GIT_NAME="Your Name" +GIT_EMAIL="your.email@example.com" +GIT_TOKEN="" +# For Forgejo/GitLab, prefer Personal Access Token (PAT). Leave empty if not needed. +# For HTTPS remotes with token: URL can be https://oauth2:@/ +# For SSH, configure SSH keys instead (not covered here). diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/Containerfile b/Containerfile index b7561d0..66491f5 100644 --- a/Containerfile +++ b/Containerfile @@ -13,10 +13,32 @@ RUN dnf install -y git curl wget tar && \ RUN curl -fsSL https://opencode.ai/install | bash +# Configura Git com variáveis de ambiente (podem ser sobrescritas no runtime) +ENV GIT_NAME="" +ENV GIT_EMAIL="" +ENV GIT_TOKEN="" + # Prepara a pasta de trabalho (o script vai montar seus arquivos aqui) WORKDIR /workspace +# Script de entrypoint para configurar Git caso variáveis sejam fornecidas +RUN cat > /entrypoint.sh << 'EOF' +#!/bin/sh +set -e + +if [ -n "$GIT_NAME" ]; then + git config --global user.name "$GIT_NAME" 2>/dev/null || true +fi + +if [ -n "$GIT_EMAIL" ]; then + git config --global user.email "$GIT_EMAIL" 2>/dev/null || true +fi + +exec "$@" +EOF +RUN chmod +x /entrypoint.sh + # Define o comando padrão que vai rodar quando o container iniciar. # Se o nome do executável da sua ferramenta for 'opencode', use assim: +ENTRYPOINT ["/entrypoint.sh"] CMD ["/root/.opencode/bin/opencode"] - diff --git a/scripts/code b/scripts/code index 6dc8102..b43ceef 100755 --- a/scripts/code +++ b/scripts/code @@ -12,7 +12,6 @@ if [ "$WORK_DIR" = "/" ] || [ "$WORK_DIR" = "$HOME" ]; then fi # TRAVA DE SEGURANÇA 2: Exige que seja um repositório Git -# O comando rev-parse verifica se o diretório pertence a um repositório if ! git -C "$WORK_DIR" rev-parse --is-inside-work-tree >/dev/null 2>&1; then echo "🚨 ERRO: O diretório alvo não é um repositório Git." echo "Por segurança, o editor só pode ser aberto dentro de projetos versionados." @@ -20,12 +19,18 @@ if ! git -C "$WORK_DIR" rev-parse --is-inside-work-tree >/dev/null 2>&1; then fi # Inicia o container com segurança +if [ -f "$WORK_DIR/.env" ]; then + ENV_ARGS="--env-file $WORK_DIR/.env" +else + ENV_ARGS="" +fi + podman run -it --rm \ + $ENV_ARGS \ -v "$WORK_DIR:/workspace:Z" \ -w /workspace \ -e DISPLAY=$DISPLAY \ -v /tmp/.X11-unix:/tmp/.X11-unix:ro \ - -e WAYLAND_DISPLAY=$WAYLAND_DISPLAY \ - -v $XDG_RUNTIME_DIR/$WAYLAND_DISPLAY:$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY:ro \ + -e WAYLAND_DISPLAY=${WAYLAND_DISPLAY:-} \ + -v ${XDG_RUNTIME_DIR:-}/${WAYLAND_DISPLAY:-}:${XDG_RUNTIME_DIR:-}/${WAYLAND_DISPLAY:-}:ro \ opencode -