This document explains how to set up proper authentication for using GitHub Container Registry (ghcr.io) with this development container and how it works in different environments (local, fork, GitHub Codespaces).
The development container can pull cached images from GitHub Container Registry to speed up build times. To enable this feature, you need to authenticate with GHCR by setting up a GitHub token.
- Go to your GitHub account settings: https://github.com/settings/tokens
- Click "Generate new token" (classic)
- Give it a descriptive name like "FinMath Dev Container"
- Set an expiration date
- Select at least the following scopes:
read:packages(to read packages from GitHub package registry)write:packages(if you want to publish packages)
- Click "Generate token"
- Important: Copy the token immediately as you won't be able to see it again
- Open VS Code settings (File > Preferences > Settings)
- Search for "dev container env"
- Under "Dev > Containers: Environment Variables", add the following:
{ "GITHUB_TOKEN": "your-github-token-here", "USER_NAME": "your-github-username", "REPO_NAME": "finmath" }
- Create a
.envfile in your project root (make sure it's in.gitignore) - Add the following variables:
GITHUB_TOKEN=your-github-token-here USER_NAME=your-github-username REPO_NAME=finmath - VSCode will automatically load these variables when opening the dev container
- The
.github/workflows/notebook-tests.ymlfile uses GitHub Actions' built-in authentication with GHCR - For local development, the
devcontainer.jsonpasses your GitHub token to the Docker build process - The Dockerfile uses this token to authenticate with GHCR and pull cached layers
With this setup, you'll be able to take advantage of cached image layers from GHCR to significantly speed up your container builds.
When using GitHub Codespaces:
- Authentication: Codespaces automatically provides the
CODESPACES_GITHUB_TOKENenvironment variable, which is used by our configuration. - Cache Access: The container will automatically authenticate with GHCR to access cached layers.
- No Manual Setup: You don't need to configure any authentication tokens manually.
- Performance: Builds will be faster as they use cached layers.
When you fork this repository:
- First Build: The first build will not have access to the original repository's cache layers unless you have explicit permissions.
- GitHub Actions: The workflow will still run but may take longer initially as it builds from scratch.
- Local Development:
- If you have a GitHub token with access to your fork's registry, add it as described above.
- If you don't have a token, the container will still build successfully but without using cache.
- Cache Creation: Your fork will create its own set of cached layers for future builds.
The container is designed to work even without authentication:
- No Token: If no GitHub token is provided, Docker will build the container without using cached layers.
- Complete Build: All dependencies will still be installed correctly, just without the speed benefit of layer caching.
- Functionality: All features of the container will work normally.
This flexible design ensures that anyone can use this development container in any environment without complications.