Skip to content

Commit 56233fd

Browse files
common-utils overwrites .zshrc coming from image built (#1069)
* common-utils overwrites .zshrc coming from image built with common-utils already * version bumped and added scenario to test the user issue * cp command failing fix test * bump version reverted * fixed the pipeline failures * discarded diff logic and introduced new one * Update src/common-utils/main.sh * instead of overwritting, template file will be appended to existing .zshrc file if INSTALL_OH_MY_ZSH_CONFIG is true * removed if statement to check .zshrc file exists * if condition added to check user_rc_file exist * linter error fixed * optimize duplication for template_path and user_rc_file logic --------- Co-authored-by: Samruddhi Khandale <[email protected]>
1 parent 9b18903 commit 56233fd

File tree

6 files changed

+45
-3
lines changed

6 files changed

+45
-3
lines changed

src/common-utils/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "common-utils",
3-
"version": "2.4.5",
3+
"version": "2.4.6",
44
"name": "Common Utilities",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/common-utils",
66
"description": "Installs a set of common command line utilities, Oh My Zsh!, and sets up a non-root user.",

src/common-utils/main.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,6 @@ if [ "${INSTALL_ZSH}" = "true" ]; then
491491
echo 'source $HOME/.profile' >> "${user_home}/.zprofile" # TODO: Reconsider adding '.profile' to '.zprofile'
492492
chown ${USERNAME}:${group_name} "${user_home}/.zprofile"
493493
fi
494-
495494
if [ "${ZSH_ALREADY_INSTALLED}" != "true" ]; then
496495
if [ "${ADJUSTED_ID}" = "rhel" ]; then
497496
global_rc_path="/etc/zshrc"
@@ -543,7 +542,8 @@ if [ "${INSTALL_ZSH}" = "true" ]; then
543542

544543
# Add devcontainer .zshrc template
545544
if [ "$INSTALL_OH_MY_ZSH_CONFIG" = "true" ]; then
546-
echo -e "$(cat "${template_path}")\nDISABLE_AUTO_UPDATE=true\nDISABLE_UPDATE_PROMPT=true" > ${user_rc_file}
545+
template_code="$(cat "${template_path}")\nDISABLE_AUTO_UPDATE=true\nDISABLE_UPDATE_PROMPT=true"
546+
echo -e "$([ -f "${user_rc_file}" ] && cat "${user_rc_file}")\n${template_code}" > "${user_rc_file}"
547547
sed -i -e 's/ZSH_THEME=.*/ZSH_THEME="devcontainers"/g' ${user_rc_file}
548548
fi
549549

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
# Definition specific tests
9+
check "configure-zshrc-without-overwrite" bash -c "grep 'rbenv init -' ~/.zshrc"
10+
11+
# Report result
12+
reportResults
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM mcr.microsoft.com/devcontainers/ruby:3.2
2+
3+
RUN echo 'eval "$(rbenv init -)"' >> /home/vscode/.zshrc
4+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
VERSION='test-version'
2+
DEFINITION_ID='test-id'
3+
VARIANT='test-variant'
4+
GIT_REPOSITORY='test-repository'
5+
GIT_REPOSITORY_RELEASE='test-release'
6+
GIT_REPOSITORY_REVISION='test-revision'
7+
BUILD_TIMESTAMP='test-time'
8+
CONTENTS_URL='test-url'

test/common-utils/scenarios.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,24 @@
235235
}
236236
}
237237
},
238+
"devcontainer-ruby-zshrc": {
239+
"build": {
240+
"dockerfile": "Dockerfile"
241+
},
242+
"remoteUser": "vscode",
243+
"features": {
244+
"common-utils": {
245+
"installZsh": true,
246+
"username": "vscode",
247+
"userUid": "1000",
248+
"userGid": "1000",
249+
"upgradePackages": true,
250+
"installOhMyZsh": true,
251+
"installOhMyZshConfig": true,
252+
"configureZshAsDefaultShell": true
253+
}
254+
}
255+
},
238256
"alpine-base-zsh-default": {
239257
"image": "mcr.microsoft.com/devcontainers/base:alpine",
240258
"remoteUser": "vscode",

0 commit comments

Comments
 (0)