Skip to content

Commit 7cf7db8

Browse files
committed
Persist Codex/Gemini auth and fix dev cache permissions
- Restore Poetry/Pip cache ownership for non-root dev user - Pre-create Codex/Gemini auth dirs to avoid permission issues - Add Docker volumes/services for Codex/Gemini auth persistence and web login - Update README with clearer setup and auth instructions
1 parent 68335a0 commit 7cf7db8

3 files changed

Lines changed: 107 additions & 29 deletions

File tree

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ RUN poetry install $POETRY_OPTIONS_DEV -n -v -C /build && \
8484
rm -rf $POETRY_CACHE_DIR/* $PIP_CACHE_DIR/*
8585
RUN mkdir -p $POETRY_CACHE_DIR $PIP_CACHE_DIR && \
8686
chown -R $DOCKER_USER $POETRY_CACHE_DIR $PIP_CACHE_DIR
87+
RUN mkdir -p $DOCKER_USER_HOME/.codex && \
88+
chown -R $DOCKER_USER $DOCKER_USER_HOME/.codex
89+
RUN mkdir -p $DOCKER_USER_HOME/.gemini && \
90+
chown -R $DOCKER_USER $DOCKER_USER_HOME/.gemini
91+
RUN mkdir -p $DOCKER_USER_HOME/.config && \
92+
chown -R $DOCKER_USER $DOCKER_USER_HOME/.config
8793

8894
FROM build-deps-dev AS dev-build
8995
ARG DOCKER_USER=devuser

README.md

Lines changed: 72 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,20 @@
44

55
<!-- vim-markdown-toc GFM -->
66

7-
* [🧰 About the Template](#-about-the-template)
8-
* [Features](#-features)
9-
* [🧪 Tested with](#-tested-with)
7+
* [About the Template](#about-the-template)
8+
* [Features](#features)
9+
* [Tested with](#tested-with)
1010
* [🚀 Getting Started](#-getting-started)
11+
* [1. Configure environment and Python settings and API tokens](#1-configure-environment-and-python-settings-and-api-tokens)
12+
* [2. Set up Python project dependencies](#2-set-up-python-project-dependencies)
13+
* [3. Build your Vim IDE image](#3-build-your-vim-ide-image)
14+
* [4. Start developing inside the container](#4-start-developing-inside-the-container)
15+
* [5. Update dependencies when needed](#5-update-dependencies-when-needed)
16+
* [Build and run your application](#build-and-run-your-application)
17+
* [Optional: Run Codex or Gemini (see more examples below)](#optional-run-codex-or-gemini-see-more-examples-below)
18+
* [Optional: Run JupyterLab](#optional-run-jupyterlab)
1119
* [💻 AI-Powered CLI Workflow (Gemini & Codex)](#-ai-powered-cli-workflow-gemini--codex)
20+
* [If you do not have API keys](#if-you-do-not-have-api-keys)
1221
* [Interactive CLI Usage in Vim Terminal](#interactive-cli-usage-in-vim-terminal)
1322
* [Gemini CLI examples](#gemini-cli-examples)
1423
* [Codex CLI examples](#codex-cli-examples)
@@ -18,7 +27,7 @@
1827

1928
<!-- vim-markdown-toc -->
2029

21-
## 🧰 About the Template
30+
## About the Template
2231

2332
**vim-python-docker-template** is a lightweight, flexible starting point for
2433
containerized Python development. It’s especially well-suited for data science
@@ -44,30 +53,34 @@ The configuration is intentionally minimal and easy to adapt. You’re free to:
4453

4554
Use it as-is or tailor it to match your team's development workflow.
4655

47-
## Features
56+
## Features
4857

49-
- 📦 **Reproducible environments** for Python development
50-
- 🛠 **IDE-like Vim setup**, ready to go out of the box
51-
- 🐍 Supports custom **Python and Poetry** versions
52-
- 🧩 Simple to extend with Jupyter, SQL drivers, and more
53-
- 🔁 Works identically on any machine with Docker
58+
- **Reproducible environments** for Python development
59+
- **IDE-like Vim setup**, ready to go out of the box
60+
- Supports custom **Python and Poetry** versions
61+
- Simple to extend with Jupyter, SQL drivers, and more
62+
- Works identically on any machine with Docker
5463

55-
## 🧪 Tested with
64+
## Tested with
5665

5766
- **Docker**: `27.3.1``29.1.1`
5867
- **buildx**: `0.20.0``0.30.0`
5968
- **Compose**: `2.32.1``2.40.3`
6069

6170
## 🚀 Getting Started
6271

63-
1. Configure environment and Python settings and API tokens
72+
### 1. Configure environment and Python settings and API tokens
73+
74+
Set OS packages, `DOCKER_PLATFORM` (if not linux/amd64), a released
75+
`PYTHON_VERSION`, Poetry version, etc., and your API keys for `OPENAI_API_KEY`
76+
and `GEMINI_API_KEY`.
6477

6578
```bash
6679
cp .env.dist .env
67-
vim .env # Set OS packages, DOCKER_PLATFORM (if not linux/amd64), a released PYTHON_VERSION, Poetry version, etc., and your API keys for OPENAI_API_KEY and GEMINI_API_KEY.
80+
vim .env
6881
```
6982

70-
2. Set up Python project dependencies
83+
### 2. Set up Python project dependencies
7184

7285
```bash
7386
vim pyproject.toml # Edit dependencies, metadata, etc.
@@ -76,7 +89,7 @@ docker compose run --rm poetry lock # Generate or update poetry.lock
7689
# git add poetry.lock
7790
```
7891

79-
3. Build your Vim IDE image
92+
### 3. Build your Vim IDE image
8093

8194
```bash
8295
cp .vimrc.dist .vimrc
@@ -86,13 +99,13 @@ git config --local user.email you@example.com
8699
docker compose build vim-ide
87100
```
88101

89-
4. Start developing inside the container
102+
### 4. Start developing inside the container
90103

91104
```bash
92105
docker compose run --rm vim-ide
93106
```
94107

95-
5. Update dependencies when needed
108+
### 5. Update dependencies when needed
96109

97110
```bash
98111
docker compose run --rm poetry lock
@@ -106,15 +119,18 @@ docker compose build vim-ide
106119
docker compose run --rm vim-ide
107120
```
108121

109-
6. Build and run your application
122+
### Build and run your application
110123

111124
```bash
112125
docker compose build app
113126
docker compose run --rm app
114127
```
115128

116-
- Optional: Run Codex or Gemini (see more examples below)
117-
- Note: `codex` and `gemini` CLIs are installed during the image build via Arch packages (`openai-codex`, `gemini-cli`) configured in `VIM_PACKAGES` inside `.env`.
129+
### Optional: Run Codex or Gemini (see more examples below)
130+
131+
> 🔄 Note: `codex` and `gemini` CLIs are installed during the image build via
132+
> Arch packages (`openai-codex`, `gemini-cli`) configured in `VIM_PACKAGES`
133+
> inside `.env`.
118134
119135
```bash
120136
docker compose build codex
@@ -126,7 +142,7 @@ docker compose build gemini
126142
docker compose run --rm gemini
127143
```
128144

129-
- Optional: Run JupyterLab
145+
### Optional: Run JupyterLab
130146

131147
```bash
132148
docker compose build jupyterlab
@@ -145,6 +161,33 @@ Vim—so you can inspect, generate, and reason about code without breaking flow.
145161
NOTE: To use AI CLI tools such as Gemini or Codex, you must configure API keys
146162
according to each provider’s official documentation.
147163

164+
### If you do not have API keys
165+
166+
API keys for Codex and Gemini require separate billing. In some cases, you can
167+
use an OpenAI subscription (for example, ChatGPT Pro) or take advantage of the
168+
available limits of a personal Google account.
169+
170+
This type of access requires authentication via a browser. For OpenAI, run the
171+
command:
172+
173+
```bash
174+
docker compose run --rm codex-web-login
175+
```
176+
177+
For Gemini, there is no separate command — just run Gemini like
178+
179+
```bash
180+
docker compose run --rm gemini
181+
```
182+
183+
and choose “Login with Google.”
184+
185+
After completion, the authorization file will be saved to
186+
`${DOCKER_USER_HOME}/.codex` or `${DOCKER_USER_HOME}/.gemini`. In this template,
187+
those directories are persisted between runs via the `codex-auth` and
188+
`gemini-auth` Docker volumes, which allows the agent CLI tool to be restarted
189+
without any additional authentication steps.
190+
148191
### Interactive CLI Usage in Vim Terminal
149192

150193
For a more integrated workflow, you can use the Gemini and Codex CLIs directly
@@ -240,14 +283,14 @@ productivity and designed to work out of the box — but is fully customizable.
240283

241284
✨ Core Capabilities
242285

243-
- Syntax highlighting & intelligent folding
244-
- Autocompletion and LSP features via `coc.nvim`
245-
- Linting, formatting, and diagnostics
246-
- Git integration and diff signs
247-
- Markdown editing with ToC, folding, and preview support
248-
- Snippets, code actions, and refactoring shortcuts
249-
- Enhanced status line, file tree, and fuzzy finding
250-
- Python-focused indentation, folding, and style enforcement
286+
* Syntax highlighting & intelligent folding
287+
* Autocompletion and LSP features via `coc.nvim`
288+
* Linting, formatting, and diagnostics
289+
* Git integration and diff signs
290+
* Markdown editing with ToC, folding, and preview support
291+
* Snippets, code actions, and refactoring shortcuts
292+
* Enhanced status line, file tree, and fuzzy finding
293+
* Python-focused indentation, folding, and style enforcement
251294

252295
### 🔌Included Plugins
253296

compose.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ services:
5959
- type: bind
6060
source: .
6161
target: /application
62+
- type: volume
63+
source: gemini-auth
64+
target: ${DOCKER_USER_HOME}/.gemini
65+
- type: volume
66+
source: codex-auth
67+
target: ${DOCKER_USER_HOME}/.codex
6268
gemini:
6369
platform: *platform
6470
entrypoint: gemini
@@ -72,6 +78,9 @@ services:
7278
- type: bind
7379
source: .
7480
target: /application
81+
- type: volume
82+
source: gemini-auth
83+
target: ${DOCKER_USER_HOME}/.gemini
7584
codex:
7685
platform: *platform
7786
entrypoint: codex
@@ -85,6 +94,22 @@ services:
8594
- type: bind
8695
source: .
8796
target: /application
97+
- type: volume
98+
source: codex-auth
99+
target: ${DOCKER_USER_HOME}/.codex
100+
codex-web-login:
101+
platform: *platform
102+
entrypoint: codex login
103+
build:
104+
target: dev-build
105+
args: *default-args
106+
environment:
107+
<<: *default-env
108+
network_mode: host
109+
volumes:
110+
- type: volume
111+
source: codex-auth
112+
target: ${DOCKER_USER_HOME}/.codex
88113
jupyterlab:
89114
platform: *platform
90115
entrypoint:
@@ -117,3 +142,7 @@ volumes:
117142
driver: local
118143
poetry-cache:
119144
driver: local
145+
codex-auth:
146+
driver: local
147+
gemini-auth:
148+
driver: local

0 commit comments

Comments
 (0)