features icon indicating copy to clipboard operation
features copied to clipboard

`common-utils` overwrites `.zshrc` coming from image built with `common-utils` already

Open AliOsm opened this issue 1 year ago • 15 comments

I'm using rails/ruby image, which already uses common-utils. But I want to override some options like making Zsh the default shell and install OhMyZsh. When I add:

"ghcr.io/devcontainers/features/common-utils:latest": {
  "installOhMyZsh": true,
  "configureZshAsDefaultShell": true
}

To my devcontainer.json, this common-utils usage overwrites the .zshrc coming from rails/ruby image, which should not happen based on this common-utils script.

Any thoughts why this could happen?

AliOsm avatar Jul 10 '24 09:07 AliOsm

I think I found something, when I add common-utils as follows:

"ghcr.io/devcontainers/features/common-utils:latest": {
  "installOhMyZsh": false,
  "installOhMyZshConfig": false,
  "configureZshAsDefaultShell": true
}

IT is not overwriting the .zshrc file, but enabling OhMyZsh stuff as follows:

"ghcr.io/devcontainers/features/common-utils:latest": {
  "installOhMyZsh": true,
  "installOhMyZshConfig": true,
  "configureZshAsDefaultShell": true
}

Overwrites it. So, I think the bug lives in this snippet.

AliOsm avatar Jul 10 '24 09:07 AliOsm

Specifically, this line overwrites the .zshrc file.

AliOsm avatar Jul 10 '24 09:07 AliOsm

So, the issue is as follows: in rails/ruby feature, an rbenv initialization line is added to the .zshrc file (ref). When I enable OhMyZsh, .zshrc file changes to OhMyZsh template and the initialization line disappears, so I need to add the following to my post create script in my DevContainer setup to add the initialization again:

echo 'eval "$(rbenv init -)"' >> /home/vscode/.zshrc
eval "$(rbenv init -)"

AliOsm avatar Jul 10 '24 09:07 AliOsm

Hi 👋

Thanks for reporting!

@gauravsaini04 / @prathameshzarkar9 Can either of you look into fixing the bug?

samruddhikhandale avatar Jul 10 '24 20:07 samruddhikhandale

Hi @samruddhikhandale ,

I have created a PR to fix this issue: PR 1069 Kindly review the same

prathameshzarkar9 avatar Jul 31 '24 10:07 prathameshzarkar9

Hi @samruddhikhandale , PR is updated and the test cases in the pipeline are now succeed. Kindly review the PR once.

prathameshzarkar9 avatar Aug 06 '24 19:08 prathameshzarkar9

Closing as fixed with https://github.com/devcontainers/features/pull/1069. Feel free to reopen if needed, thanks!

samruddhikhandale avatar Aug 13 '24 20:08 samruddhikhandale

I think the changes to resolve this has broken devcontainers using ghcr.io/devcontainers/features/node:1. node & npm are not found after building the container

I have had to specify ghcr.io/devcontainers/features/common-utils:2.4.5 to get it building with node & npm again.

Mark-J-Lawrence avatar Aug 15 '24 10:08 Mark-J-Lawrence

Thanks for letting us know, I have reverted the changes. See https://github.com/devcontainers/features/pull/1094

@prathameshzarkar9 Can you take a look at the issue and merge the changes with the fix?

samruddhikhandale avatar Aug 15 '24 16:08 samruddhikhandale

Hi @Mark-J-Lawrence , We tried to reproduce the scenario but it is not reproducing in our codespace. Can you help us and provide a .devcontainer configuration file content to check what base image you are using and other configuration attributes values to have exact match with your usecase so that we would be able to trobleshoot and find the exact root cause.?

prathameshzarkar9 avatar Sep 02 '24 09:09 prathameshzarkar9

Hi @samruddhikhandale , I have created new PR https://github.com/devcontainers/features/pull/1111 to fix this issue. kindly review the same

prathameshzarkar9 avatar Sep 02 '24 09:09 prathameshzarkar9

@prathameshzarkar9

{
  "name": "cics-security-sdv-samples Container",
  "build": {
    "dockerfile": "Dockerfile"
  },
  "customizations": {
    "vscode": {
      "settings": {
        "vsintellicode.java.completionsEnabled": false,
        "vsintellicode.python.completionsEnabled": false,
        "vsintellicode.sql.completionsEnabled": false,
        "vsintellicode.typescript.completionsEnabled": false,
        "vsintellicode.modify.editor.suggestSelection": "disabled",
        "errorLens.onSave": true,
        "errorLens.messageEnabled": true,
        "versionlens.suggestions.showOnStartup": true,
        "editor.formatOnSave": true,
        "ansible.python.interpreterPath": "/usr/local/python/current/bin/python",
        "pylint.interpreter": [
          "/usr/local/python/current/bin/python"
        ],
        "eslint.workingDirectories": [
          "./docs",
          "./lib"
        ],
        "stylelint.validate": [
          "css",
          "scss"
        ],
        "stylelint.configBasedir": "./docs"
      },
      "extensions": [
        "dbaeumer.vscode-eslint",
        "usernamehw.errorlens",
        "igorsbitnev.error-gutters",
        "wayou.vscode-todo-highlight",
        "pflannery.vscode-versionlens",
        "bierner.markdown-emoji",
        "redhat.ansible",
        "ms-python.flake8",
        "gruntfuggly.todo-tree",
        "ms-python.python",
        "ms-python.pylint",
        "stylelint.vscode-stylelint"
      ]
    }
  },
  "features": {
    "ghcr.io/devcontainers/features/git:1": {},
    "ghcr.io/devcontainers/features/common-utils:2": {},
    "ghcr.io/devcontainers/features/node:1": {
      "version": "18"
    },
    "ghcr.io/devcontainers/features/python:1": {
      "version": "3.12"
    }
  },
  "forwardPorts": [
    3000,
    3001
  ],
  "privileged": true,
  "remoteUser": "root",
  "workspaceMount": "source=${localWorkspaceFolder},target=/workspaces,type=bind",
  "workspaceFolder": "/workspaces",
  "postStartCommand": "git config --global --add safe.directory /workspaces; git config commit.gpgsign false",
  "postAttachCommand": "/post_script/initialise_dev_container.sh"
}

Mark-J-Lawrence avatar Sep 02 '24 09:09 Mark-J-Lawrence

@prathameshzarkar9 this is what's in the initialise_dev_container.sh file:

# Install approval bot dependencies
npm install

# Install docs dependencies
cd docs
npm install
cd ..

# Install Ansible tooling
pip install ansible==10.2.0 ansible-lint==24.7.0 --root-user-action=ignore

# Install ansible script dependencies
cd ansible-sdv-pipeline
pip install -r requirements.txt --root-user-action=ignore

Mark-J-Lawrence avatar Sep 02 '24 09:09 Mark-J-Lawrence

Hi @Mark-J-Lawrence , Can you provide Dockerfile also just to verify the impact.

prathameshzarkar9 avatar Sep 02 '24 09:09 prathameshzarkar9

@prathameshzarkar9 sure....

FROM mcr.microsoft.com/devcontainers/base:jammy

RUN apt update

ENV LOG_LEVEL="trace"

EXPOSE 3000
EXPOSE 3001

COPY initialise_dev_container.sh /post_script/initialise_dev_container.sh

RUN mkdir -p /workspaces; \
    chmod 755 /post_script/initialise_dev_container.sh

WORKDIR /workspaces

Mark-J-Lawrence avatar Sep 02 '24 09:09 Mark-J-Lawrence

@prathameshzarkar9 Can you look at the latest details and continue investigation?

samruddhikhandale avatar Sep 25 '24 22:09 samruddhikhandale

Hi @samruddhikhandale , Latest review comments addressed. kindly review it once.

prathameshzarkar9 avatar Oct 03 '24 05:10 prathameshzarkar9

Completed with https://github.com/devcontainers/features/pull/1111

samruddhikhandale avatar Oct 17 '24 22:10 samruddhikhandale