Skip to content

Commit

Permalink
Merge pull request #961 from m-1-k-3/master
Browse files Browse the repository at this point in the history
Support docker compose v2 API
  • Loading branch information
m-1-k-3 committed Dec 13, 2023
2 parents 7c7eb55 + 635dbf9 commit 018be70
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 26 deletions.
2 changes: 1 addition & 1 deletion config/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.2
1.3.2-d127c9c3
15 changes: 5 additions & 10 deletions emba
Original file line number Diff line number Diff line change
Expand Up @@ -662,11 +662,6 @@ main() {
exit 1
fi
fi
if ! command -v docker-compose > /dev/null ; then
print_output "[!] No docker-compose found" "no_log"
print_output "$(indent "Install docker-compose via apt-get install docker-compose to use EMBA with docker")" "no_log"
exit 1
fi

OPTIND=1
ARGUMENTS=()
Expand Down Expand Up @@ -721,21 +716,21 @@ main() {
disable_strict_mode "${STRICT_MODE}" 0
if [[ "${ONLY_DEP}" -gt 0 ]]; then
# check dependencies mode:
EMBA="${INVOCATION_PATH}" FIRMWARE="${FIRMWARE_PATH}" docker-compose run --rm emba -c './emba -f /firmware -i "$@"' _ "${ARGUMENTS[@]}"
EMBA="${INVOCATION_PATH}" FIRMWARE="${FIRMWARE_PATH}" "${DOCKER_COMPOSE[@]}" run --rm emba -c './emba -f /firmware -i "$@"' _ "${ARGUMENTS[@]}"
D_RETURN=$?
EMBA="${INVOCATION_PATH}" FIRMWARE="${FIRMWARE_PATH}" docker-compose run --rm emba_quest -c './emba -f /firmware -i "$@"' _ "${ARGUMENTS[@]}"
EMBA="${INVOCATION_PATH}" FIRMWARE="${FIRMWARE_PATH}" "${DOCKER_COMPOSE[@]}" run --rm emba_quest -c './emba -f /firmware -i "$@"' _ "${ARGUMENTS[@]}"
if [[ $? -ne ${D_RETURN} ]]; then
D_RETURN=1
fi
elif [[ "${DIFF_MODE}" -gt 0 ]]; then
FIRMWARE_PATH1="$(abs_path "${FIRMWARE_PATH1}")"
# firmware diff mode - needs two firmware files:
EMBA="${INVOCATION_PATH}" FIRMWARE="${FIRMWARE_PATH}" LOG="${LOG_DIR}" docker-compose run -v "${FIRMWARE_PATH1}":/firmware2 --rm emba -c './emba -l /logs -f /firmware -o /firmware2 -i "$@"' _ "${ARGUMENTS[@]}"
EMBA="${INVOCATION_PATH}" FIRMWARE="${FIRMWARE_PATH}" LOG="${LOG_DIR}" "${DOCKER_COMPOSE[@]}" run -v "${FIRMWARE_PATH1}":/firmware2 --rm emba -c './emba -l /logs -f /firmware -o /firmware2 -i "$@"' _ "${ARGUMENTS[@]}"
D_RETURN=$?
else
# default EMBA analysis mode:
local QUEST_CONTAINER_=""
QUEST_CONTAINER_="$(EMBA="${INVOCATION_PATH}" FIRMWARE="${FIRMWARE_PATH}" LOG="${LOG_DIR}" docker-compose run --detach --rm emba_quest -c './emba -l /logs -f /firmware -i "$@"' _ "${ARGUMENTS[@]}")"
QUEST_CONTAINER_="$(EMBA="${INVOCATION_PATH}" FIRMWARE="${FIRMWARE_PATH}" LOG="${LOG_DIR}" "${DOCKER_COMPOSE[@]}" run --detach --rm emba_quest -c './emba -l /logs -f /firmware -i "$@"' _ "${ARGUMENTS[@]}")"
export QUEST_CONTAINER="${QUEST_CONTAINER_}"
print_output "[*] Quest container ${QUEST_CONTAINER_} started and detached.\\n" "main"
print_ln "no_log"
Expand All @@ -745,7 +740,7 @@ main() {
store_kill_pids "${QUEST_PID}"
disown "${QUEST_PID}" 2> /dev/null || true

EMBA="${INVOCATION_PATH}" FIRMWARE="${FIRMWARE_PATH}" LOG="${LOG_DIR}" docker-compose run --rm emba -c './emba -l /logs -f /firmware -i "$@"' _ "${ARGUMENTS[@]}"
EMBA="${INVOCATION_PATH}" FIRMWARE="${FIRMWARE_PATH}" LOG="${LOG_DIR}" "${DOCKER_COMPOSE[@]}" run --rm emba -c './emba -l /logs -f /firmware -i "$@"' _ "${ARGUMENTS[@]}"
D_RETURN=$?
# stop quest container
if [[ "$( docker container inspect -f '{{.State.Status}}' "${QUEST_CONTAINER_}" )" == "running" ]]; then
Expand Down
24 changes: 24 additions & 0 deletions helpers/helpers_emba_dependency_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,27 @@ check_docker_image(){
fi
}

check_docker_version() {
# docker-compose vs docker compose - see https://docs.docker.com/compose/migrate/
print_output " Docker compose version - \\c" "no_log"
if command -v docker > /dev/null; then
if docker --help | grep -q compose; then
export DOCKER_COMPOSE=("docker" "compose")
echo -e "${GREEN}""${DOCKER_COMPOSE[@]} ok""${NC}"
elif command -v docker-compose > /dev/null; then
export DOCKER_COMPOSE=("docker-compose")
echo -e "${GREEN}""${DOCKER_COMPOSE[@]} ok""${NC}"
else
echo -e "${RED}""not ok""${NC}"
DEP_ERROR=1
fi
else
# no docker at all ... not good
echo -e "${RED}""not ok""${NC}"
DEP_ERROR=1
fi
}

dependency_check()
{
local LATEST_EMBA_VERSION=""
Expand Down Expand Up @@ -292,6 +313,9 @@ dependency_check()
echo -e "${GREEN}""ok""${NC}"
fi

if [[ "${USE_DOCKER}" -eq 1 && "${IN_DOCKER}" -ne 1 ]]; then
check_docker_version
fi
# EMBA is developed for and on KALI Linux
# In our experience we can say that it runs on most Debian based systems without any problems
if [[ "${USE_DOCKER}" -eq 0 ]] ; then
Expand Down
31 changes: 17 additions & 14 deletions installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -287,20 +287,23 @@ activate_pipenv "./external/emba_venv"
# initial installation of the host environment:
I01_default_apps_host

DOCKER_COMP_VER=$(docker-compose -v | grep version | tr '-' ' ' | awk '{print $4}' | tr -d ',' | sed 's/^v//')
if [[ $(version "${DOCKER_COMP_VER}") -lt $(version "1.28.5") ]]; then
echo -e "\n${ORANGE}WARNING: compatibility of the used docker-compose version is unknown!${NC}"
echo -e "\n${ORANGE}Please consider updating your docker-compose installation to version 1.28.5 or later.${NC}"
echo -e "\n${ORANGE}Please check the EMBA wiki for further details: https://github.com/e-m-b-a/emba/wiki/Installation#prerequisites${NC}"
read -p "If you know what you are doing you can press any key to continue ..." -n1 -s -r
fi

# check pip3 docker version TODO move into pipenv
DOCKER_VER=$(pip3 show docker | grep Version: | awk '{print $2}' || true)
if [[ $(version "${DOCKER_VER}") -ge $(version "7.0.0") ]]; then
echo -e "\n${ORANGE}WARNING: compatibility of the used docker version is unknown!${NC}"
echo -e "\n${ORANGE}Please consider downgrading your pip3 docker version. \$pip3 install \"docker<7.0.0\"${NC}"
read -p "If you know what you are doing you can press any key to continue ..." -n1 -s -r
export DOCKER_COMPOSE=("docker-compose")
# docker moved around v7 to a new API (API v2)
# we need to check if our installed docker version has support for the compose sub-command:
if command -v docker > /dev/null; then
if docker --help | grep -q compose; then
# new docker API version v2 -> docker v7
export DOCKER_COMPOSE=("docker" "compose")
else
# we only need to check the docker-compose version if we are running on the old API with docker-compose
DOCKER_COMP_VER=$("${DOCKER_COMPOSE[@]}" -v | grep version | tr '-' ' ' | awk '{print $4}' | tr -d ',' | sed 's/^v//')
if [[ $(version "${DOCKER_COMP_VER}") -lt $(version "1.28.5") ]]; then
echo -e "\n${ORANGE}WARNING: compatibility of the used docker-compose version is unknown!${NC}"
echo -e "\n${ORANGE}Please consider updating your docker-compose installation to version 1.28.5 or later.${NC}"
echo -e "\n${ORANGE}Please check the EMBA wiki for further details: https://github.com/e-m-b-a/emba/wiki/Installation#prerequisites${NC}"
read -p "If you know what you are doing you can press any key to continue ..." -n1 -s -r
fi
fi
fi

if [[ "${OTHER_OS}" -eq 1 ]]; then
Expand Down
2 changes: 1 addition & 1 deletion installer/I05_emba_docker_image_dl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ I05_emba_docker_image_dl() {
docker pull "${CONTAINER}"
sed -i "/image:/c\ image: ${CONTAINER}" docker-compose.yml
export DOCKER_CLI_EXPERIMENTAL=disabled
docker-compose up --no-start
"${DOCKER_COMPOSE[@]}" up --no-start
else
echo "Estimated download-Size: ~5500 MB"
echo -e "${ORANGE}""WARNING: docker command missing - no docker pull possible.""${NC}"
Expand Down

0 comments on commit 018be70

Please sign in to comment.