zplug icon indicating copy to clipboard operation
zplug copied to clipboard

having trouble calling `zplug install` while building a Docker image

Open deepsweet opened this issue 8 years ago • 24 comments

Problem Summary

having trouble calling zplug install while building a Docker image:

Step 11 : RUN zsh -ic 'zplug install'
 ---> Running in 591efba9a9b2
[zplug] WARNING: pipe syntax is deprecated! Please use 'on' tag instead.
[zplug] No package to install

but calling zplug install after logged in a container works fine.

System Information

  • uname -a

    Linux dcf3b8b9ed12 4.4.22-moby #1 SMP Sun Sep 25 22:54:41 UTC 2016 x86_64 GNU/Linux
    
  • zsh --version

    zsh 5.2 (x86_64-unknown-linux-gnu)
    
  • zplug --version

    2.3.2
    

Steps to Reproduce

here is some minimal Dockerfile that you can try:

FROM dock0/arch

RUN pacman -Syu --noconfirm awk zsh
RUN useradd --create-home --shell /usr/bin/zsh test
WORKDIR /home/test
USER test
RUN git clone https://github.com/zplug/zplug ~/.zplug
ENV ZPLUG_HOME=~/.zplug
RUN echo 'source ~/.zplug/init.zsh' > .zshrc
RUN echo 'zplug "zsh-users/zsh-syntax-highlighting", nice:10' >> .zshrc
RUN echo 'zplug load --verbose' >> .zshrc
RUN zsh -ic 'zplug install'
CMD ["zsh"]

to build it:

docker build -t zplug_docker_issue .

to explore what is inside:

docker run -it --rm zplug_docker_issue

deepsweet avatar Oct 11 '16 09:10 deepsweet

I don't use docker so if anyone who does can help us on this issue that would be great!

NigoroJr avatar Oct 23 '16 00:10 NigoroJr

I can help you with any necessary debugging.

  1. should zsh -ic 'zplug install' work as expected? maybe I have missed something really important from the very beginning.
  2. do you have any ideas to what this WARNING: pipe syntax is deprecated! Please use 'on' tag instead. is related to?

deepsweet avatar Oct 30 '16 18:10 deepsweet

I'm a bit familiar with Docker and tried this out. The pipe error is from here I believe? You can trigger this in the shell too instead echo "zplug is awesome" | zsh -ic zplug install, if you skip the zsh -ic bit and are already in zsh shell you won't trigger that error. The other log line of "No package to install" is here.

So based on that probably safe to assume that Docker is building/running those commands in the Dockerfile with pipes somewhere. You can also change your CMD to CMD ["zsh","-ic","zplug install"] and it'll run the package install each time you run the container(obviously not ideal).

Another option might be to install them on the host and then copy them into the container during build, again not ideal.

polarathene avatar Nov 14 '16 06:11 polarathene

The solution I think is for you to build an image then run the command in a container followed by committing the active container to the docker image as described here.

I've got this working, added a theme as a more visual way of seeing it worked:

FROM dock0/arch

# Install ZSH
RUN pacman -Syu --noconfirm awk zsh

# Create user `test`, switch to user and set directory to their home.
RUN useradd --create-home --shell /usr/bin/zsh test
WORKDIR /home/test
USER test

# Provided an absolute path here instead. `git` didn't seem able to use it
# and `zplug install` seemed to throw some errors
ENV ZPLUG_HOME /home/test/.zplug

# Install zplug
RUN git clone https://github.com/zplug/zplug $ZPLUG_HOME

# Creating a .zshrc, you could use ADD to include an actual file instead
RUN echo 'source ~/.zplug/init.zsh' > .zshrc \
    && echo 'zplug "sindresorhus/pure", use:"{async,pure}.zsh"' >> .zshrc \
    && echo 'zplug "zsh-users/zsh-syntax-highlighting", nice:10' >> .zshrc \
    && echo 'zplug load --verbose' >> .zshrc

# Install the plugins/packages, commit container changes after to a new image
CMD ["zsh", "-ic", "zplug install"] 

Run the following to build/install/run:

BUILD_IMAGE=zplug_docker_issue \
&& FINAL_IMAGE=zplug_docker_issue_2 \
&& docker build -t $BUILD_IMAGE . \
&& docker run -it $BUILD_IMAGE \
&& LAST_ACTIVE_CONTAINER=$(docker ps -l -q) \
&& docker commit --change='CMD ["zsh"]' -m "Installed zplug packages" $LAST_ACTIVE_CONTAINER $FINAL_IMAGE \
&& docker run -it $FINAL_IMAGE

You can omit the last docker run command if you don't want to jump into the container after everything is done. Just run it again in future with the $FINAL_IMAGE image name.

polarathene avatar Nov 14 '16 11:11 polarathene

@NigoroJr The workaround could possibly be avoided if there is a way to avoid the pipe detection blocking.

Perhaps by including an additional flag to zplug install or detecting an env var? I don't know if that'd cause any problems by temporary ignoring the pipe detection.

polarathene avatar Nov 14 '16 11:11 polarathene

When I hit up against this error in another context (sourcing .zshrc from i3), I was able to work around by using /dev/null as standard input, like so:

    zplug "zce" </dev/null

talwrii avatar Dec 01 '17 03:12 talwrii

None of the solutions above are clean, unfortunately. Building docker image with a non usual set of steps looks fishy, and the /dev/null redirect didnot work. Any update on this?

danielporto avatar Jan 29 '18 14:01 danielporto

OK, I'll improve this behavior as my next task

babarot avatar May 14 '18 13:05 babarot

This happens when you run zplug via ssh command as well.

ssh $server 'zsh -ci "zplug install"'

This yields,

[zplug] WARNING: pipe syntax is deprecated! Please use 'on' tag instead. [zplug] no packages to install

but after logging in and running 'zplug install' will run properly and installs packages.

windware-ono avatar Jul 10 '18 12:07 windware-ono

Any updates on this? I got the same error while building a docker image with zsh -ic "zplug install" or sourcing the .zshrc file with zplug install in it.

taishi8117 avatar Jul 28 '19 19:07 taishi8117

@taishi8117 you may try

ENV LC_ALL en_US.UTF-8
RUN curl -sL --proto-redir -all,https https://raw.githubusercontent.com/zplug/installer/master/installer.zsh | zsh
RUN ["zsh", "-ic", "zplug install"]

Inside .zshrc, the part related to zplug is:

source ~/.zplug/init.zsh

# zplug "supercrabtree/k"

# enhanced zsh vim mode
zplug "softmoth/zsh-vim-mode"

# smart jump to other directories
# zplug "skywind3000/z.lua"

# configuration for theme pure
# zplug "mafredri/zsh-async", from:github
# zplug "sindresorhus/pure", use:pure.zsh, from:github, as:theme

# command auto-suggestion based on history
zplug "zsh-users/zsh-autosuggestions"

# Syntax highlighting bundle, load it after other plugin
zplug "zdharma/fast-syntax-highlighting", defer:2

# automatch pairs
zplug "hlissner/zsh-autopair", defer:2

# turn screen to matrix
# zplug "amstrad/oh-my-matrix"

# Then, source plugins and add commands to $PATH
zplug load

I can successfully build the docker image with the above instructions.

jdhao avatar Sep 30 '19 12:09 jdhao

Hello, I am experiencing this same issue

nemanjan00 avatar Feb 03 '20 00:02 nemanjan00

This is my attempt to solve it:

https://github.com/nemanjan00/dev-environment

nemanjan00 avatar Feb 03 '20 00:02 nemanjan00

Yes, I can confirm, it does work, if I use #6277d2e

https://github.com/eliasnorrby/zplug/commit/6277d2e0b9f0850aa037e8be2eb70b3bd447688a

COPY ./zplug /tmp/zplug
RUN patch ~/.zplug/base/core/add.zsh /tmp/zplug/patch/pipe_fix.diff

RUN zsh -ic "TERM=xterm-256color ZPLUG_PIPE_FIX=true zplug install"

This did the trick...

nemanjan00 avatar Feb 03 '20 06:02 nemanjan00

This repo has a Dockerfile. So could you test it?

babarot avatar Feb 03 '20 09:02 babarot

It does not look like deps are installed inside that dockerfile

nemanjan00 avatar Feb 03 '20 09:02 nemanjan00

Yeah, but you can modify it with following by your requirements.

babarot avatar Feb 03 '20 09:02 babarot

That particular step is problem and I doubt it would work here either, without modifications. Will try it

nemanjan00 avatar Feb 03 '20 09:02 nemanjan00

Even with that one, I am having problems doing zplug install

https://travis-ci.org/nemanjan00/zplug/builds/645367846

nemanjan00 avatar Feb 03 '20 09:02 nemanjan00

Not the prettiest solution, but

zsh <<< "source $HOME/.zshrc; zplug install"

worked for me. Somehow the here string makes it so zplug's pipe check isn't triggered.

dhnza avatar Jun 16 '20 18:06 dhnza

Yes, I can confirm, it does work, if I use #6277d2e

eliasnorrby@6277d2e

COPY ./zplug /tmp/zplug
RUN patch ~/.zplug/base/core/add.zsh /tmp/zplug/patch/pipe_fix.diff

RUN zsh -ic "TERM=xterm-256color ZPLUG_PIPE_FIX=true zplug install"

This did the trick...

I just wanted to add that I was struggling with this issue, and @nemanjan00 's patch has solved it for me. Is this something that's worth merging?

jmdaly avatar May 28 '21 20:05 jmdaly

I encountered this issue and wasn't able to resolve using the suggestions above. I'm putting my workaround here in case it helps someone out there.

What worked for me was writing the installation steps in a zsh script such as

#!/bin/zsh
# Install zplug plugins
source ~/.zshrc
zplug install

and then copying and running this script from within the Dockerfile

COPY ./install_zplug.zsh .
RUN ./zplug.zsh

Of course zsh would need to be installed before this step.

aalbaali avatar Aug 27 '22 02:08 aalbaali

I encountered this issue and wasn't able to resolve using the suggestions above.

Have you been using zplug for a while, or only recently adopted it?

AFAIK the zsh community seems to discourage zplug as it's no longer maintained. No actual development since around 2018? Seems like an odd choice to go with now :sweat_smile:

polarathene avatar Aug 27 '22 04:08 polarathene

@polarathene I've been using it for around a year or so. I wasn't aware quite aware that zplug is no longer maintained. I'll look for alternatives in this case. Thanks for the heads up

aalbaali avatar Aug 27 '22 14:08 aalbaali