tomeichlersmith / denv

uniformly interact with containerized environments across runners
https://tomeichlersmith.github.io/denv/
GNU General Public License v3.0
8 stars 2 forks source link

Installation script on macOS fails #39

Closed tamasgal closed 1 year ago

tamasgal commented 1 year ago

Describe the bug The installation script on macOS (13.3.1) fails with a permission error.

To Reproduce Steps to reproduce the behavior:

  1. Set up denv with...
  2. Try to run...
  3. See odd behavior...

Expected behavior denv should install without errors

Screenshots Here is the output of a session where I try to install denv:

░ tamasgal@silentbox:~
░ 17:42:18 > curl -s https://raw.githubusercontent.com/tomeichlersmith/denv/main/install | sh

ERROR: Cannot write into /Users/tamasgal/.local/share/man/man1, permission denied

░ tamasgal@silentbox:~
░ 17:43:04 1 > mkdir .denv

░ tamasgal@silentbox:~
░ 17:43:13 > curl -s https://raw.githubusercontent.com/tomeichlersmith/denv/main/install | \
  sh -s -- --prefix .denv --next --simple

ERROR: Cannot write into .denv/share/man/man1, permission denied

░ tamasgal@silentbox:~
░ 17:43:24 1 > mkdir -p .denv/share/man/man1

░ tamasgal@silentbox:~
░ 17:47:03 > curl -s https://raw.githubusercontent.com/tomeichlersmith/denv/main/install | \
  sh -s -- --prefix .denv --next --simple

 INFO: Checking dependencies...
 INFO: Downloading...
 INFO: Unpacking...
install: illegal option -- D
usage: install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
               [-o owner] file1 file2
       install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
               [-o owner] file1 ... fileN directory
       install -d [-v] [-g group] [-m mode] [-o owner] directory ...
ERROR: Copying to .denv/bin failed.
       Do you have permission to write there?
tomeichlersmith commented 1 year ago

aaah :facepalm: yes, the install script, I'm guessing the permission denied error is coming from trying to copy a file into a directory that hasn't been created yet

https://github.com/tomeichlersmith/denv/blob/f754454ace8ba42ace3ac9f76ad1a84b6c5c1296/install#L129-L139

I don't know why I didn't mkdir -p for the ${man_dest_path} but this should (lol) be an easy fix.

tamasgal commented 1 year ago

Yeah ;) That's what I also tried (see above), but then hit the next thing with ERROR: Copying to .denv/bin failed., probably related to the illegal option which I mentioned in Zoom, since some commands on macOS are not GNU.

tomeichlersmith commented 1 year ago

Alright, I fixed up the copying/mkdir, can you try the following?

curl -s https://raw.githubusercontent.com/tomeichlersmith/denv/39-install-macos/install | sh -s -- --prefix install

I'm assuming the illegal option is from using the install command. Could you post the man page or help printout for install for me? I can also just google around while I'm waiting for jobs to run.

tomeichlersmith commented 1 year ago

https://ss64.com/osx/cp.html this says there is no -t flag for cp which could be the issue and https://ss64.com/osx/install.html is the same for install.

Going to update the install script to avoid the -t flags...

tomeichlersmith commented 1 year ago

Alright, I got the install operational (I think) and added docker on MacOS to the testing suite. It is currently failing with a confusing error:

 INFO: Testing denv with docker
PASS: 'denv' failed when it should have failed
PASS: 'denv init ubuntu:22.04' ran successfully
PASS: 'denv init ubuntu:18.04' failed when it should have failed
PASS: 'denv config print' ran successfully
PASS: 'denv false' failed when it should have failed
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/usr/local/bin/_denv_entrypoint": is a directory: unknown: permission denied.
time="2023-09-05T17:59:59Z" level=error msg="error waiting for container: "
FAIL:  != tmp.YwMDO4sv when comparing 'denv printenv DENV_NAME' and 'basename /var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/tmp.YwMDO4sv'
Error: Process completed with exit code 1.

It's odd because this is failing on the second command that launched a container. denv false runs false within the container and that seems to run fine while the following run fails. I suspect this is due to the configuration of docker on MacOS and I am unsure if it is an issue with the runner or with docker on MacOS in general.

tamasgal commented 1 year ago

Hmm, I tried but something strange is happening. I installed denv in ~/.denv and ~/.denv/bin was populated but then after doing denv init (and realising that Docker was not running), the ~/.denv/bin folder vanished. It's a bit scary that things are deleted without any good reason ;)

Here is the history:

░ tamasgal@silentbox:~
░ 13:31:41 > curl -s https://raw.githubusercontent.com/tomeichlersmith/denv/39-i
nstall-macos/install | sh -s -- --prefix .denv
 INFO: Checking dependencies...
 INFO: Downloading...
 INFO: Unpacking...
 INFO: Successfully installed denv to /Users/tamasgal/.denv/bin
 INFO: Found /Users/tamasgal/.denv/bin in PATH, you're all set!

░ tamasgal@silentbox:~
░ 13:31:44 > denv
/Users/tamasgal/.denv/bin/denv: line 314: /Users/tamasgal/.denv/config: No such file or directory

░ tamasgal@silentbox:~
░ 13:31:47 1 > denv init

  denv init [help|-h|--help] IMAGE [WORKSPACE] [--no-gitignore]
            [--force] [--name NAME]

 ARGUMENT
  help       : print this help and exit
  IMAGE      : the container image to use for running the denv
  WORKSPACE  : the directory to create the denv for
               optional, defaults to present working directory

 OPTIONS
  -h, --help     : print this help and exit
  --no-gitignore : don't generate a gitignore for the .denv directory
  --force        : overwrite an existing denv if it exists
  --name         : set a name for this denv

ERROR: Provide at least an image to use for running

░ tamasgal@silentbox:~
░ 13:31:51 1 > denv init python:2.7
This workspace already has a denv. Would you like to overwrite it? [Y/n] y
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

(here I started Docker.app)

░ tamasgal@silentbox:~ took 5s
░ 13:32:04 1 > denv
zsh: command not found: denv

░ tamasgal@silentbox:~
░ 13:32:58 130 > ls .denv
config

░ tamasgal@silentbox:~
░ 13:33:00 > which denv
denv not found
tomeichlersmith commented 1 year ago

Ah yes, this is because the directory .denv in the current working directory is what is used by denv to store the configuration.

Right now, "overwriting" means deleting .denv and starting from an empty directory; however, I could undo that and simply ignore the fact that other files may be in .denv.

This is where the offending lines are

https://github.com/tomeichlersmith/denv/blob/f754454ace8ba42ace3ac9f76ad1a84b6c5c1296/denv#L587-L608

Instead of rm -r .denv, you could replace that with just rm -f .denv/config to make sure the new config is "clean" in some sense. That would allow you to install denv into .denv.

Edit: I've updated the development branch to avoid fully removing the .denv directory. You should be good to re-try. :crossed_fingers:

tamasgal commented 1 year ago

OK works now, thanks! :) We can close this. I'll do some further tests :)