Skip to content

Commit e5e1c5e

Browse files
author
ide-coder
committed
fix: resolve ruby command not found and add CI test stage
- Add 'rbenv rehash' after ruby install to generate shims - Add 'rbenv rehash' after gem install to update shims - Remove manual symlinks (PATH already includes shims directory) - Add test job to verify: - Default user is 'coder' - All installed tools are accessible - sudo works without password - su command is blocked - Mirror configurations are correct
1 parent 847d366 commit e5e1c5e

2 files changed

Lines changed: 128 additions & 7 deletions

File tree

.github/workflows/build-and-push.yml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,127 @@ jobs:
145145
run: |
146146
TAG=$(echo "${{ steps.meta.outputs.tags }}" | head -n1 | tr -d '\n')
147147
docker buildx imagetools inspect "$TAG"
148+
149+
test:
150+
name: Test Image
151+
runs-on: ${{ matrix.runs-on }}
152+
needs: merge
153+
permissions:
154+
contents: read
155+
packages: read
156+
strategy:
157+
fail-fast: false
158+
matrix:
159+
include:
160+
- platform: linux/amd64
161+
runs-on: ubuntu-latest
162+
- platform: linux/arm64
163+
runs-on: ubuntu-24.04-arm
164+
165+
steps:
166+
- name: Set lowercase image name
167+
run: |
168+
echo "IMAGE_NAME=ghcr.io/$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
169+
170+
- name: Get current date for tagging
171+
run: echo "DATE_TAG=$(date +'%Y%m%d')" >> $GITHUB_ENV
172+
173+
- name: Log in to the Container registry
174+
uses: docker/login-action@v3
175+
with:
176+
registry: ghcr.io
177+
username: ${{ github.actor }}
178+
password: ${{ secrets.GITHUB_TOKEN }}
179+
180+
- name: Pull image
181+
run: docker pull ${{ env.IMAGE_NAME }}:${{ env.DATE_TAG }}
182+
183+
- name: Test default user is coder
184+
run: |
185+
echo "Testing default user is 'coder'..."
186+
USER=$(docker run --rm ${{ env.IMAGE_NAME }}:${{ env.DATE_TAG }} whoami)
187+
if [ "$USER" != "coder" ]; then
188+
echo "::error::Default user is '$USER', expected 'coder'"
189+
exit 1
190+
fi
191+
echo "✓ Default user is 'coder'"
192+
193+
- name: Test installed tools accessibility
194+
run: |
195+
echo "Testing installed tools accessibility for coder user..."
196+
197+
# Define tools to test with their version commands
198+
declare -A TOOLS=(
199+
["go"]="go version"
200+
["gopls"]="gopls version"
201+
["dlv"]="dlv version"
202+
["golangci-lint"]="golangci-lint --version"
203+
["python3"]="python3 --version"
204+
["pip"]="pip --version"
205+
["uv"]="uv --version"
206+
["conda"]="conda --version"
207+
["node"]="node --version"
208+
["npm"]="npm --version"
209+
["pnpm"]="pnpm --version"
210+
["yarn"]="yarn --version"
211+
["java"]="java -version"
212+
["mvn"]="mvn --version"
213+
["ruby"]="ruby --version"
214+
["gem"]="gem --version"
215+
["rails"]="rails --version"
216+
["git"]="git --version"
217+
["curl"]="curl --version"
218+
["wget"]="wget --version"
219+
["vim"]="vim --version | head -1"
220+
["kubectl"]="kubectl version --client"
221+
["yq"]="yq --version"
222+
)
223+
224+
FAILED_TOOLS=""
225+
226+
for tool in "${!TOOLS[@]}"; do
227+
cmd="${TOOLS[$tool]}"
228+
echo "Testing $tool..."
229+
if docker run --rm ${{ env.IMAGE_NAME }}:${{ env.DATE_TAG }} bash -c "$cmd" > /dev/null 2>&1; then
230+
echo " ✓ $tool is accessible"
231+
else
232+
echo " ✗ $tool is NOT accessible"
233+
FAILED_TOOLS="$FAILED_TOOLS $tool"
234+
fi
235+
done
236+
237+
if [ -n "$FAILED_TOOLS" ]; then
238+
echo "::error::The following tools are not accessible:$FAILED_TOOLS"
239+
exit 1
240+
fi
241+
242+
echo "✓ All tools are accessible for coder user"
243+
244+
- name: Test sudo without password
245+
run: |
246+
echo "Testing sudo works without password..."
247+
docker run --rm ${{ env.IMAGE_NAME }}:${{ env.DATE_TAG }} bash -c "sudo whoami" | grep -q "root" && echo "✓ sudo works without password" || { echo "::error::sudo requires password"; exit 1; }
248+
249+
- name: Test su command is blocked
250+
run: |
251+
echo "Testing su command is blocked..."
252+
if docker run --rm ${{ env.IMAGE_NAME }}:${{ env.DATE_TAG }} bash -c "sudo su - root" 2>&1 | grep -q "sudo: su: command not found\|Sorry, user coder is not allowed to execute"; then
253+
echo "✓ su command is properly blocked"
254+
else
255+
echo "::warning::su command might not be properly blocked"
256+
fi
257+
258+
- name: Test mirror configurations
259+
run: |
260+
echo "Testing mirror configurations..."
261+
262+
# Test Go proxy
263+
docker run --rm ${{ env.IMAGE_NAME }}:${{ env.DATE_TAG }} bash -c 'echo $GOPROXY | grep -q "goproxy.cn"' && echo " ✓ Go proxy configured" || echo " ⚠ Go proxy not using goproxy.cn"
264+
265+
# Test npm registry
266+
docker run --rm ${{ env.IMAGE_NAME }}:${{ env.DATE_TAG }} bash -c 'npm config get registry | grep -q "npmmirror"' && echo " ✓ npm registry configured" || echo " ⚠ npm registry not using npmmirror"
267+
268+
# Test gem sources
269+
docker run --rm ${{ env.IMAGE_NAME }}:${{ env.DATE_TAG }} bash -c 'gem sources | grep -q "ruby-china"' && echo " ✓ gem sources configured" || echo " ⚠ gem sources not using ruby-china"
270+
271+
echo "✓ Mirror configurations verified"

Dockerfile

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,13 @@ RUN git clone https://github.com/rbenv/rbenv.git /home/coder/.rbenv \
132132
&& git clone https://github.com/rbenv/ruby-build.git /home/coder/.rbenv/plugins/ruby-build
133133

134134
# Install latest stable Ruby and Rails
135+
# Note: rbenv rehash generates shims in ~/.rbenv/shims directory
135136
RUN /home/coder/.rbenv/plugins/ruby-build/install.sh \
136137
&& RBENV_ROOT=/home/coder/.rbenv /home/coder/.rbenv/bin/rbenv install 3.4.1 \
137138
&& RBENV_ROOT=/home/coder/.rbenv /home/coder/.rbenv/bin/rbenv global 3.4.1 \
138-
&& RBENV_ROOT=/home/coder/.rbenv /home/coder/.rbenv/shims/gem install bundler rails --no-document
139-
140-
# Create symlinks for ruby, gem, rails to system path (ensures commands work in all shells)
141-
RUN ln -sf /home/coder/.rbenv/shims/ruby /usr/local/bin/ruby \
142-
&& ln -sf /home/coder/.rbenv/shims/gem /usr/local/bin/gem \
143-
&& ln -sf /home/coder/.rbenv/shims/rails /usr/local/bin/rails \
144-
&& ln -sf /home/coder/.rbenv/shims/bundler /usr/local/bin/bundler
139+
&& RBENV_ROOT=/home/coder/.rbenv /home/coder/.rbenv/bin/rbenv rehash \
140+
&& RBENV_ROOT=/home/coder/.rbenv /home/coder/.rbenv/shims/gem install bundler rails --no-document \
141+
&& RBENV_ROOT=/home/coder/.rbenv /home/coder/.rbenv/bin/rbenv rehash
145142

146143
# Configure gem mirror
147144
RUN echo "---\n:sources:\n - https://gems.ruby-china.com/" > /home/coder/.gemrc

0 commit comments

Comments
 (0)