-
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
114 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,32 @@ | ||
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 translate the command line info Compose V2 `docker compose` then run the latter. | ||
|
||
## installation | ||
|
||
We provide an install script for automated installtion: | ||
|
||
```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 | ||
``` | ||
1. make compose-switch executable | ||
```console | ||
$ chmode +x /usr/local/bin/compose-switch | ||
``` | ||
1. rename docker-compose if you already have it installed as `/usr/local/bin/docker-compose` | ||
```console | ||
$ mv /usr/local/bin/docker-compose /usr/local/bin/docker-compose-v1 | ||
``` | ||
1. define an "alternatives" group for `docker-compose` command: | ||
```console | ||
$ update-alternatives --install /usr/local/bin/docker-compose docker-compose /$(which docker-compose) 1 | ||
$ update-alternatives --install /usr/local/bin/docker-compose docker-compose /usr/local/bin/compose-switch 99 | ||
``` |
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,24 @@ | ||
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,42 @@ | ||
#!/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 -x | ||
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 [ $COMPOSE -ne "" ]; 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" |
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
Oops, something went wrong.