-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compose-switch is installed as a Linux "alternative" to docker-compose
Signed-off-by: Nicolas De Loof <[email protected]>
- Loading branch information
Showing
16 changed files
with
145 additions
and
425 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,3 @@ jobs: | |
|
||
- name: Test | ||
run: make test | ||
|
||
- name: e2e | ||
run: make bin e2e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,65 @@ | ||
Compose Switch | ||
-------------- | ||
|
||
This is a thin wrapper to actually run either docker-compose v1 (python) or docker compose v2 (compose CLI plugin) depending on user's configuration | ||
Compose Switch is a replacement to the Compose V1 `docker-compose` (python) executable. It translates the command line into Compose V2 `docker compose` then run the latter. | ||
|
||
## installation | ||
|
||
We provide an script for automated installation: | ||
|
||
```console | ||
$ curl -fL https://raw.githubusercontent.com/docker/compose-cli/main/scripts/install/install_linux.sh | sh | ||
``` | ||
|
||
### Manual installation | ||
|
||
1. download compose-switch binary for your architecture | ||
```console | ||
$ curl -fL https://github.com/docker/compose-switch/releases/download/v1.0.1/docker-compose-linux-amd64 -o /usr/local/bin/compose-switch | ||
``` | ||
|
||
2. make compose-switch executable | ||
```console | ||
$ chmod +x /usr/local/bin/compose-switch | ||
``` | ||
|
||
3. If you have installed Docker Compose v1 manually as `/usr/local/bin/docker-compose`, you have to rename `docker-compose` binary to avoid conflict. If you installed install the docker-compose package from your distro, this step is not necessary. | ||
```console | ||
$ mv /usr/local/bin/docker-compose /usr/local/bin/docker-compose-v1 | ||
``` | ||
|
||
4. Define an _alternatives_ group for `docker-compose` command. | ||
If you renamed `docker-compose` binary on step 3. use the path of the renamed file, otherwise use the full path for docker-compose command (probably `/usr/bin/docker-compose`) | ||
```console | ||
$ update-alternatives --install /usr/local/bin/docker-compose docker-compose <PATH_TO_DOCKER_COMPOSE_V1> 1 | ||
$ update-alternatives --install /usr/local/bin/docker-compose docker-compose /usr/local/bin/compose-switch 99 | ||
``` | ||
Note: On Redhat-based distribution, use `alternatives` command. | ||
|
||
|
||
## check installation | ||
|
||
```console | ||
$ update-alternatives --display docker-compose | ||
docker-compose - auto mode | ||
link best version is /usr/local/bin/compose-switch | ||
link currently points to /usr/local/bin/compose-switch | ||
link docker-compose is /usr/local/bin/docker-compose | ||
/usr/bin/docker-compose - priority 1 | ||
/usr/local/bin/compose-switch - priority 99 | ||
``` | ||
|
||
## select Compose implementation to run by `docker-compose` | ||
|
||
```console | ||
$ update-alternatives --config docker-compose | ||
There are 2 choices for the alternative docker-compose (providing /usr/local/bin/docker-compose). | ||
|
||
Selection Path Priority Status | ||
------------------------------------------------------------ | ||
* 0 /usr/local/bin/compose-switch 99 auto mode | ||
1 /usr/bin/docker-compose 1 manual mode | ||
2 /usr/local/bin/compose-switch 99 manual mode | ||
|
||
Press <enter> to keep the current choice[*], or type selection number: | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FROM centos | ||
|
||
RUN yum install -y curl yum-utils | ||
|
||
# install docker cli | ||
RUN yum-config-manager \ | ||
--add-repo \ | ||
https://download.docker.com/linux/centos/docker-ce.repo | ||
RUN yum install -y docker-ce-cli | ||
|
||
# install compose v1 | ||
RUN curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose | ||
RUN chmod +x /usr/local/bin/docker-compose | ||
|
||
# install compose v2 | ||
RUN mkdir -p /usr/local/lib/docker/cli-plugins | ||
RUN curl -L https://github.com/docker/compose/releases/download/v2.0.0-rc.3/docker-compose-linux-amd64 > /usr/local/lib/docker/cli-plugins/docker-compose | ||
RUN chmod +x /usr/local/lib/docker/cli-plugins/docker-compose | ||
|
||
COPY install_on_linux.sh /tmp/install_on_linux.sh | ||
RUN /tmp/install_on_linux.sh | ||
|
||
RUN docker-compose --version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,41 @@ | ||
#!/bin/sh | ||
|
||
COMPOSE_SWITCH_VERSION="1.0.0" | ||
COMPOSE_SWITCH_URL="https://github.com/docker/compose-switch/releases/download/$COMPOSE_SWITCH_VERSION/docker-compose" | ||
DOCKER_COMPOSE_V1_PATH_ORIG="$(which docker-compose)" | ||
DOCKER_COMPOSE_V1_PATH_NEW="$DOCKER_COMPOSE_V1_PATH_ORIG-v1" | ||
set -e | ||
|
||
if [ ! -f "${DOCKER_COMPOSE_V1_PATH_ORIG}" ]; then | ||
echo "'docker-compose' V1 could not be found in PATH. Aborting..." | ||
exit 1 | ||
fi | ||
|
||
if [ -f "${DOCKER_COMPOSE_V1_PATH_NEW}" ]; then | ||
echo "Looks like docker-compose V1->V2 switch is already installed. 'docker-compose' binary was already moved to '${DOCKER_COMPOSE_V1_PATH_NEW}'." | ||
echo "If you are trying to re-enable Docker Compose V2, please run:" | ||
echo "$ docker-compose enable-v2" | ||
exit 0 | ||
fi | ||
ARCHITECTURE=amd64 | ||
if [ "$(uname -m)" = "aarch64" ]; then | ||
ARCHITECTURE=arm64 | ||
fi | ||
COMPOSE_SWITCH_VERSION="v1.0.1" | ||
COMPOSE_SWITCH_URL="https://github.com/docker/compose-switch/releases/download/${COMPOSE_SWITCH_VERSION}/docker-compose-linux-${ARCHITECTURE}" | ||
|
||
error=$(docker compose version 2>&1 >/dev/null) | ||
if [ $? -ne 0 ]; then | ||
echo "Docker Compose V2 is not installed" | ||
exit 1 | ||
fi | ||
|
||
TMP_FILE=$(mktemp) | ||
echo "Downloading compose V1->V2 switch into $TMP_FILE..." | ||
curl -L -o "$TMP_FILE" "$COMPOSE_SWITCH_URL" | ||
chmod +x "$TMP_FILE" | ||
curl -fL $COMPOSE_SWITCH_URL -o /usr/local/bin/compose-switch | ||
chmod +x /usr/local/bin/compose-switch | ||
|
||
echo "Switching Docker Compose binary" | ||
mv "$DOCKER_COMPOSE_V1_PATH_ORIG" "$DOCKER_COMPOSE_V1_PATH_NEW" | ||
mv "$TMP_FILE" "$DOCKER_COMPOSE_V1_PATH_ORIG" | ||
COMPOSE=$(command -v docker-compose) | ||
if [ "$COMPOSE" = /usr/local/bin/docker-compose ]; then | ||
# This is a manual installation of docker-compose | ||
# so, safe for us to rename binary | ||
mv /usr/local/bin/docker-compose /usr/local/bin/docker-compose-v1 | ||
COMPOSE=/usr/local/bin/docker-compose-v1 | ||
fi | ||
|
||
echo "Compose V1->V2 installed" | ||
ALTERNATIVES="update-alternatives" | ||
if ! command -v $ALTERNATIVES; then | ||
ALTERNATIVES=alternatives | ||
fi | ||
|
||
$DOCKER_COMPOSE_V1_PATH_ORIG enable-v2 | ||
echo "Docker Compose V2 enabled" | ||
docker-compose version | ||
echo "Configuring `docker-compose` alternatives" | ||
if [ ! -z $COMPOSE ]; then | ||
$ALTERNATIVES --install /usr/local/bin/docker-compose docker-compose $COMPOSE 1 | ||
fi | ||
$ALTERNATIVES --install /usr/local/bin/docker-compose docker-compose /usr/local/bin/compose-switch 99 | ||
|
||
echo "To switch back to Compose V1, you can run: `docker-compose disable-v2`" | ||
echo "'docker-compose' is now set to run Compose V2" | ||
echo "use '$ALTERNATIVES --config docker-compose' if you want to switch back to Compose V1" |
Oops, something went wrong.