Merge feat/git-env-setup: add git env support

This commit is contained in:
João Carlos Machado de Paiva Araújo 2026-10-03 13:32:41 +00:00
commit 6bd957fbce
5 changed files with 47 additions and 5 deletions

5
.env Normal file
View file

@ -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

9
.env.example Normal file
View file

@ -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:<GIT_TOKEN>@<host>/<repo>
# For SSH, configure SSH keys instead (not covered here).

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
.env

View file

@ -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"]

View file

@ -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