Skip to content

Commit 37cc4f3

Browse files
committed
Address Sourcery review: clarify org vs user package paths
- Explain how <owner>/<repo> maps to the GHCR image name in README - Add separate instructions for org-owned vs personal repos (UI URLs and CLI endpoints differ) - Update migration script to auto-detect org vs user and use the correct API endpoint - Mention `pixi run dev-use-prebuilt` in the README instructions
1 parent f44873a commit 37cc4f3

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,15 @@ By default, the devcontainer builds locally from `.devcontainer/Dockerfile`. Thi
6363

6464
## Switching to a prebuilt image (optional)
6565

66-
A CI workflow (`.github/workflows/devcontainer.yml`) automatically builds and pushes a devcontainer image to GHCR whenever `.devcontainer/` files change on `main`. To use it for faster startup:
66+
A CI workflow (`.github/workflows/devcontainer.yml`) automatically builds and pushes a devcontainer image to GHCR whenever `.devcontainer/` files change on `main`. The image is published as `ghcr.io/<owner>/<repo>/devcontainer:latest`, where `<owner>` is your GitHub username or organization and `<repo>` is the repository name (e.g. `ghcr.io/myuser/myproject/devcontainer:latest`).
67+
68+
You can migrate automatically with:
69+
70+
```bash
71+
pixi run dev-use-prebuilt
72+
```
73+
74+
Or manually:
6775

6876
1. Edit `.devcontainer/devcontainer.json`: comment out the `"build"` and `"features"` blocks, uncomment the `"image"` line
6977
2. Update the image reference to match your repo: `ghcr.io/<owner>/<repo>/devcontainer:latest`
@@ -75,7 +83,8 @@ A CI workflow (`.github/workflows/devcontainer.yml`) automatically builds and pu
7583
**Option 1: GitHub Web UI**
7684

7785
1. Go to your repository's package settings:
78-
`https://github.com/users/<username>/packages/container/<repo>%2Fdevcontainer/settings`
86+
- Personal repos: `https://github.com/users/<username>/packages/container/<repo>%2Fdevcontainer/settings`
87+
- Organization repos: `https://github.com/orgs/<org>/packages/container/<repo>%2Fdevcontainer/settings`
7988
2. Under "Danger Zone", click **Change visibility**
8089
3. Select **Public** and confirm
8190

@@ -85,8 +94,11 @@ A CI workflow (`.github/workflows/devcontainer.yml`) automatically builds and pu
8594
# Ensure your token has the write:packages scope
8695
gh auth refresh -s write:packages
8796

88-
# Set the package to public
97+
# For personal repos:
8998
gh api --method PATCH /user/packages/container/<repo>%2Fdevcontainer -f visibility=public
99+
100+
# For organization repos:
101+
gh api --method PATCH /orgs/<org>/packages/container/<repo>%2Fdevcontainer -f visibility=public
90102
```
91103

92104
# Github setup

scripts/devcontainer_use_prebuilt.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,35 @@ echo "Updated $DEVCONTAINER_JSON to use prebuilt image."
6464
echo ""
6565
echo "Attempting to make GHCR package public..."
6666

67+
OWNER=$(echo "$REPO" | cut -d'/' -f1)
6768
PACKAGE_NAME=$(echo "$REPO" | cut -d'/' -f2)
6869
ENCODED_PACKAGE="${PACKAGE_NAME}%2Fdevcontainer"
6970

70-
if gh api --method PATCH "/user/packages/container/${ENCODED_PACKAGE}" -f visibility=public >/dev/null 2>&1; then
71+
# Determine if owner is an org or a user
72+
IS_ORG=false
73+
if gh api "/orgs/${OWNER}" >/dev/null 2>&1; then
74+
IS_ORG=true
75+
fi
76+
77+
if $IS_ORG; then
78+
API_PATH="/orgs/${OWNER}/packages/container/${ENCODED_PACKAGE}"
79+
SETTINGS_URL="https://github.com/orgs/${OWNER}/packages/container/${ENCODED_PACKAGE}/settings"
80+
else
81+
API_PATH="/user/packages/container/${ENCODED_PACKAGE}"
82+
SETTINGS_URL="https://github.com/users/${OWNER}/packages/container/${ENCODED_PACKAGE}/settings"
83+
fi
84+
85+
if gh api --method PATCH "$API_PATH" -f visibility=public >/dev/null 2>&1; then
7186
echo "GHCR package is now public."
7287
else
7388
echo "Could not set package visibility automatically."
7489
echo ""
7590
echo "To make the package public manually, either:"
7691
echo ""
77-
echo " 1. Visit: https://github.com/users/$(echo "$REPO" | cut -d'/' -f1)/packages/container/${ENCODED_PACKAGE}/settings"
92+
echo " 1. Visit: $SETTINGS_URL"
7893
echo " -> Danger Zone -> Change visibility -> Public"
7994
echo ""
8095
echo " 2. Run:"
8196
echo " gh auth refresh -s write:packages"
82-
echo " gh api --method PATCH /user/packages/container/${ENCODED_PACKAGE} -f visibility=public"
97+
echo " gh api --method PATCH $API_PATH -f visibility=public"
8398
fi

0 commit comments

Comments
 (0)