Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common-utils: various cleaning things from other pr. #653

Conversation

naturedamends
Copy link
Contributor

@naturedamends naturedamends commented Aug 13, 2023

Proposal

Enable usage of the installOhMyZshConfig flag within Microsoft base dev container images.

Since images may have had previous installs which come with commom-utils. This allows the config option to function as stated.

failed proposal

This is now just cleaning up the file and fixes some issues with the flag for non root usernames.

@naturedamends naturedamends requested a review from a team as a code owner August 13, 2023 20:32
@naturedamends
Copy link
Contributor Author

naturedamends commented Aug 13, 2023

Tests are failing locally due to a permissions issue writing to ~/.oh-my-zsh owned by vscode as user root.

Present in debian:bullseye and alpine

#14 34.71 USERNAME: vscode
ls -la /root
#14 34.71 total 20
#14 34.71 drwx------ 1 root root 4096 Jul 25 00:00 .
#14 34.71 drwxr-xr-x 1 root root 4096 Aug 13 19:51 ..
#14 34.71 -rw-r--r-- 1 root root 2026 Aug 13 19:52 .bashrc
#14 34.71 -rw-r--r-- 1 root root  161 Jul  9  2019 .profile
ls -la /home/vscode
#14 34.71 total 24
#14 34.71 drwxr-xr-x 2 vscode vscode 4096 Aug 13 19:52 .
#14 34.71 drwxr-xr-x 1 root   root   4096 Aug 13 19:52 ..
#14 34.71 -rw-r--r-- 1 vscode vscode  220 Mar 27  2022 .bash_logout
[2023-08-13T19:52:32.078Z] 
#14 34.71 -rw-r--r-- 1 vscode vscode 4981 Aug 13 19:52 .bashrc
#14 34.71 -rw-r--r-- 1 vscode vscode  807 Mar 27  2022 .profile
#14 34.71 Cloning into '/home/vscode/.oh-my-zsh'...

[2023-08-13T19:52:32.976Z] #14 35.72 chown: cannot access '/home/vscode/.zshrc': No such file or directory

Copy link
Member

@samruddhikhandale samruddhikhandale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing the PR, left some comments!

src/common-utils/main.sh Outdated Show resolved Hide resolved
src/common-utils/main.sh Outdated Show resolved Hide resolved
src/common-utils/main.sh Outdated Show resolved Hide resolved
src/common-utils/main.sh Outdated Show resolved Hide resolved
test/common-utils/scenarios.json Outdated Show resolved Hide resolved
test/common-utils/scenarios.json Outdated Show resolved Hide resolved
@naturedamends
Copy link
Contributor Author

Testing the marked flag I have is a little hard since I would need to build a base image within a test, since the avaliable base images have old version of the source code, and thus no flag.

@samruddhikhandale
Copy link
Member

Looks like the recent commits are causing multiple test failures. See https://github.com/devcontainers/features/actions/runs/5868233855?pr=653

@naturedamends
Copy link
Contributor Author

naturedamends commented Aug 16, 2023

Do you understand this -- error with the coreutils cp? @samruddhikhandale . Couldn't re create locally

cp -f /tmp/dev-container-features/common-utils_0/scripts/devcontainers.zsh-theme /home/vscode/.oh-my-zsh/custom/themes/devcontainers.zsh-theme
#14 0.396 + cp -f /home/vscode/.oh-my-zsh/custom/themes/devcontainers.zsh-theme /home/vscode/.oh-my-zsh/custom/themes/codespaces.zsh-theme
#14 0.397 cp: '/home/vscode/.oh-my-zsh/custom/themes/devcontainers.zsh-theme' and '/home/vscode/.oh-my-zsh/custom/themes/codespaces.zsh-theme' are the same file

from this code

        # Add Dev Containers theme
        mkdir -p ${oh_my_install_dir}/custom/themes
        cp -f "${FEATURE_DIR}/scripts/devcontainers.zsh-theme" "${oh_my_install_dir}/custom/themes/devcontainers.zsh-theme"
        cp -f "${oh_my_install_dir}/custom/themes/devcontainers.zsh-theme" "${oh_my_install_dir}/custom/themes/codespaces.zsh-theme"

see extended log
6_test (common-utils, mcr.microsoft.comdevcontainersbaseubun.txt

See local test (issue not reproduced):

╭─dev at iMac in /opt/workspace/gists/cp-testing 23-08-16 - 22:22:53
╰─○ cat script
#!/bin/bash


cd "/home/vscode"
pwd

mkdir source
echo "testing" >> source/source
mkdir target

cp -vf source/source target/codespace
cp -vf target/codespace target/devcontainers

stat target/*
╭─dev at iMac in /opt/workspace/gists/cp-testing 23-08-16 - 22:23:11
╰─○ docker run -it -v $(pwd):/app -w /app --rm  mcr.microsoft.com/devcontainers/base:ubuntu  bash /app/script
/home/vscode
'source/source' -> 'target/codespace'
'target/codespace' -> 'target/devcontainers'
  File: target/codespace
  Size: 8               Blocks: 8          IO Block: 4096   regular file
Device: 89h/137d        Inode: 6571041     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2023-08-16 21:23:14.618101122 +0000
Modify: 2023-08-16 21:23:14.613101122 +0000
Change: 2023-08-16 21:23:14.613101122 +0000
 Birth: 2023-08-16 21:23:14.612101122 +0000
  File: target/devcontainers
  Size: 8               Blocks: 8          IO Block: 4096   regular file
Device: 89h/137d        Inode: 6571042     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2023-08-16 21:23:14.618101122 +0000
Modify: 2023-08-16 21:23:14.618101122 +0000
Change: 2023-08-16 21:23:14.618101122 +0000
 Birth: 2023-08-16 21:23:14.618101122 +0000

test with absolute paths

docker run -it -v $(pwd):/app -w /app --rm  mcr.microsoft.com/devcontainers/base:ubuntu  bash /app/script
/home/vscode
'/home/vscode/source/source' -> '/home/vscode/target/codespace'
'/home/vscode/target/codespace' -> '/home/vscode/target/devcontainers'
  File: target/codespace
  Size: 8               Blocks: 8          IO Block: 4096   regular file
Device: 89h/137d        Inode: 6571048     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2023-08-16 21:26:47.338729331 +0000
Modify: 2023-08-16 21:26:47.334729331 +0000
Change: 2023-08-16 21:26:47.334729331 +0000
 Birth: 2023-08-16 21:26:47.334729331 +0000
  File: target/devcontainers
  Size: 8               Blocks: 8          IO Block: 4096   regular file
Device: 89h/137d        Inode: 6571049     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2023-08-16 21:26:47.338729331 +0000
Modify: 2023-08-16 21:26:47.338729331 +0000
Change: 2023-08-16 21:26:47.338729331 +0000
 Birth: 2023-08-16 21:26:47.338729331 +0000

Tests stoped failing when changed to coping the template path to both destinations...

Should the link exist? I'm not sure, its just getting copied to root. If scripts append to the user, is it appropriate for root rc to reference it in the context of a dev container?

@naturedamends naturedamends changed the title WIP: Common-utils: Enable installOhMyZshConfig false for upstream images. Common-utils: Enable installOhMyZshConfig false for upstream images. Aug 16, 2023
@naturedamends naturedamends changed the title Common-utils: Enable installOhMyZshConfig false for upstream images. WIP: Common-utils: Enable installOhMyZshConfig false for upstream images. Aug 16, 2023
@@ -13,6 +13,8 @@ check "zsh" zsh --version
check "ps" ps --version
check "Oh My Zsh! theme" test -e $HOME/.oh-my-zsh/custom/themes/devcontainers.zsh-theme
check "zsh theme symlink" test -e $HOME/.oh-my-zsh/custom/themes/codespaces.zsh-theme
check "zsh theme filename" test -e $HOME/.oh-my-zsh/custom/themes/codespaces.zsh-theme
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would take the meaning of -e and symlink to mean xor... not sure @samruddhikhandale

@naturedamends naturedamends changed the title WIP: Common-utils: Enable installOhMyZshConfig false for upstream images. Common-utils: Enable installOhMyZshConfig false for upstream images. Aug 17, 2023
# Given previous step configured ~/.zshrc,
# When installOhMyZshConfig is false, done before INSTALL_ZSH since
# Or where installOhMyZshconfig false, and installZsh false
# Then remove the file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the PR changes installOhMyZshConfig would behave completely different as compared to other Feature options.

For eg. Let's say an image (say X) installs common-utils as follows -

"features": {
            "common-utils": {
                "installZsh": true,
            }
        }

Then a user creates their devcontainer.json as 👇

{
        "image": "X",
        "features": {
            "common-utils": {
                "installZsh": false
            }
        }
    }

"installZsh": false

Does this mean the Feature should remove the zsh installation? I don't think that the Features should remove an existing functionality, however, should only update or add new tools/configs/themes.

When a user add a Feature to their devcontainer.json, it is assumed that the "installZsh": false option would NOT install zsh but it doesn't mean that it should remove the already existing zsh. This behavior could create confusions and removing something is always a bit risky. I think we should avoid this approach.

@naturedamends Let me know what you think!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, remove the file, if zshrc exists and installZshConfig false and installZsh true?

Or do you not like the file being removed at all?

Should I remove the source of zshrc added in tests? Such that it's not executed within within build runtime. Then again.. it's a container

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or do you not like the file being removed at all?

This ☝️
You never know if the zsh config has been modified by the dockerfiles (or something else), hence, it's best to avoid removing anything. Also, removing config makes sense only if the Feature had an option like removeZshConfig , but doesn't seem like that's needed.

Copy link
Contributor Author

@naturedamends naturedamends Aug 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hose about linking ~/.zshrc to .zshrc.devcontainer.

Then downstream can handle, or ln -sf?

@naturedamends naturedamends changed the title Common-utils: Enable installOhMyZshConfig false for upstream images. Common-utils: various cleaning things from other pr. Aug 18, 2023
Comment on lines +379 to +387
# *********************************
# ** Ensure config directory **
# *********************************
user_config_dir="${user_home}/.config"
if [ ! -d "${user_config_dir}" ]; then
mkdir -p "${user_config_dir}"
chown ${USERNAME}:${group_name} "${user_config_dir}"
fi

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if [ "${USERNAME}" = "root" ]; then
user_home="/root"
else
user_home="/home/${USERNAME}"
if [ ! -d "${user_home}" ]; then
mkdir -p "${user_home}"
chown ${USERNAME}:${group_name} "${user_home}"
fi
fi
configures user_home, hence, should this be added after that?

Copy link
Contributor Author

@naturedamends naturedamends Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good catch. I want a clean home directory, so if im going to program this, I want it before any rc files. Not sure how much of a pain this is going to be

I came to the conclusion that you would not want any related flags in common-utils

Is the shell-setup feature going to be in features repo?
Then would it be prudent to add a flag to prevent any rc generation here

Thus you can enable the following to get equal functionality:
Common-utils rc false
Shell-setup shell zsh

I'm not familiar with any other fancy shells. Other than one I heard of that has a consistent output table format.

Would you consider adding a shell-setup to the features repo?

Sorry for bad grammar on tablet

# Copy files to alternate user if one is specified
cp -rf "${user_omz_filepaths[@]}" /root
# Set permissions for root user
chown -R root:root "${omz_added_filesnames[@]/#//root/}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, why is this needed?

Copy link
Contributor Author

@naturedamends naturedamends Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security. User scripts making it into root and being sourced.

Would be tempted to copy from a mktmp-d. To prevent copying any unknown files

Ie custom shell scripts
Or scripts appended to users linked template

Nvm. I will close pr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants