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

Support docker compose plugin to justfile #1149

Closed
sharkAndshark opened this issue Jan 22, 2024 · 4 comments
Closed

Support docker compose plugin to justfile #1149

sharkAndshark opened this issue Jan 22, 2024 · 4 comments

Comments

@sharkAndshark
Copy link
Collaborator

The Docker compose plugin way:

docker compose up

The Docker compose standalone way:

docker-compose up

Is there one way to support them both? I tried many in justfile but all failed.

@nyurik
Copy link
Member

nyurik commented Jan 22, 2024

I think we may need to test if the system has a docker-compose, and if it does not, use docker compose - something similar to the check we have in the cargo-install just command - but do it once when just starts up?

@nyurik
Copy link
Member

nyurik commented Jan 22, 2024

A temporary workaround could be to add an alias to bash

@justb4
Copy link
Contributor

justb4 commented Jan 25, 2024

This is a common problem, that will still remain some years, until docker compose is the only command.
We solved this in a workshop launch control Bash script like @nyurik indicated: sniff for the variant and set an alias. See these lines i.e.:

# Sniff which Docker Compose variant is installed
# and set an alias.
# See https://github.com/geopython/geopython-workshop/issues/82
if command docker-compose --version &> /dev/null
then
  alias dockercompose='docker-compose'
  echo "Using docker-compose"
else
  if !command docker compose version &> /dev/null
  then
    echo "Neither docker-compose nor docker compose is available"
    echo "Check your Docker Installation"
    exit 1
  fi
  alias dockercompose='docker compose'  
  echo "Using docker compose"
fi

..and then use the alias dockercompose. Never heard of just (other than my first name..) but seems something to be added in the justfile as bash is presumed? Will PR...

@justb4
Copy link
Contributor

justb4 commented Jan 25, 2024

The "bash-script" approach in my comment above does not really work direct in a justfile because of the 'just-syntax'. But figured out an alternative, using standard var and -substitution, so an approach with oneliner:

dockercompose := `if docker-compose --version &> /dev/null; then echo "docker-compose"; else echo "docker compose"; fi`
.
.
up:
   {{ dockercompose }} up

up-build:
    {{ dockercompose }} up --build
.
.

There is a justfile in the repo root and the demo dir. Will go ahead with this approach.

nyurik pushed a commit that referenced this issue Jan 29, 2024
This should solve #1149. See also [my comment there for the
approach](#11). In short
through a variable that is substituted. Note that this may not work if
an older Docker version is installed without the Python `docker-compose`
script...As both variants will not be present. Maybe add an extra
test+warning msg for that case.

```
dockercompose := `if docker-compose --version &> /dev/null; then echo "docker-compose"; else echo "docker compose"; fi`
.
.
up:
   {{ dockercompose }} up

up-build:
    {{ dockercompose }} up --build
.
.
```

---------

Co-authored-by: Lucas <[email protected]>
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

No branches or pull requests

3 participants