Skip to content

Commit

Permalink
Changed docker compose file to accept optional configuration paramete…
Browse files Browse the repository at this point in the history
…rs. Added helper shell script for docker.

Changed docker import to accept a login.json in the currect directory if available.
  • Loading branch information
anselor committed Mar 13, 2024
1 parent 0007f4a commit 8af1fbf
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 20 deletions.
95 changes: 95 additions & 0 deletions compose.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/bash

if [ -f '.env' ]; then
export $(grep -v '^#' .env | xargs)
else
FLASK_HOST=127.0.0.1
FLASK_PORT=4470
BUILD_IMAGE=""
ANKERCTL_DATA=ankerctl_vol
fi


print_usage() {

echo "Usage: $0 [option] <command>"
echo ""
echo "Options:"
echo ""
echo " -o Open mode. Allow connections from the network"
echo " -b Build the docker image from source"
echo " -p <port> Port for Ankerctl web interface"
echo " -d <data> Ankerctl data volume"
echo ""
echo "Commands:"
echo " up Run the docker container"
echo " down Stop the docker container"
}


exit_error() {
print_usage
exit 1
}

if [ $# -eq 0 ]; then
print_usage
exit 0
fi

OPT_MATCHES=':obp:d:'

while getopts "${OPT_MATCHES}" options; do
case "${options}" in
o) FLASK_HOST=0.0.0.0 ;;
b) BUILD_IMAGE="1" ;;
p) FLASK_PORT=${OPTARG} ;;
d) ANKERCTL_DATA=${OPTARG} ;;
:)
echo "Error: -${OPTARG} requires an argument"
exit_error
;;
*)
exit_error
;;
esac
done

COMMAND=${@:$OPTIND:1}
EXTRA=${@:$OPTIND+1:1}

if [ ! -z "${EXTRA}" ]; then
echo "No parameters allowed after command"
exit_error
fi

echo "Command: ${COMMAND}"

case "${COMMAND}" in
up)
if [ ! -z "${BUILD_IMAGE}" ]; then
# build docker image
COMPOSE_EXTRA_PARAMS="--build "
fi

FLASK_HOST=${FLASK_HOST} FLASK_PORT=${FLASK_PORT} ANKERCTL_DATA=${ANKERCTL_DATA} docker-compose up ${COMPOSE_EXTRA_PARAMS} -d

cat << EOF > ./.env
FLASK_HOST=${FLASK_HOST}
FLASK_PORT=${FLASK_PORT}
BUILD_IMAGE=${BUILD_IMAGE}
ANKERCTL_DATA=${ANKERCTL_DATA}
EOF

;;

down)
docker-compose down
;;

*)
echo "Unrecognized command: ${CMD}"
echo ""
exit_error
;;
esac
6 changes: 3 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ services:

# bind to localhost by default
environment:
- FLASK_HOST=127.0.0.1
- FLASK_PORT=4470
- FLASK_HOST={$FLASK_HOST:-127.0.0.1}
- FLASK_PORT=${FLASK_PORT:-4470}
volumes:
- ankerctl_vol:/root/.config/ankerctl
- ${ANKERCTL_DATA:-ankerctl_vol}:/root/.config/ankerctl

volumes:
ankerctl_vol:
46 changes: 29 additions & 17 deletions docker-import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,37 @@ if [ "$(docker container inspect -f "{{.State.Status}}" "${CONTAINER}")" != "run
fi


WINEPREFIX=${WINEPREFIX:-$HOME/.wine}
if [ -f "./login.json" ]; then
echo "** Importing ./login.json **"
docker cp -L ./login.json ${CONTAINER}:/tmp
if docker exec -it ${CONTAINER} /app/ankerctl.py -k config import /tmp/login.json; then
echo "Configuration imported successfully. Restarting container..."
docker restart ${CONTAINER}
exit $?
else
echo "Configuration import failed :("
fi
else
WINEPREFIX=${WINEPREFIX:-$HOME/.wine}

for root in "${APPDATA}" "${HOME}"; do
for prefix in "Library/Application Support" "$WINEPREFIX/drive_c/users/${USER}/AppData/Local"; do
for suffix in "AnkerMake/AnkerMake_64bit_fp/login.json" "Ankermake/AnkerMake_64bit_fp/login.json"; do
name="$root/$prefix/$suffix";
if [ -f "${name}" ]; then
echo "** Importing ${name} credentials **";
docker cp -L "${name}" ${CONTAINER}:/tmp
if docker exec -it ${CONTAINER} /app/ankerctl.py -k config import /tmp/login.json; then
echo "Configuration imported successfully. Restarting container..."
docker restart ${CONTAINER}
exit $?
for root in "${APPDATA}" "${HOME}"; do
for prefix in "Library/Application Support" "$WINEPREFIX/drive_c/users/${USER}/AppData/Local"; do
for suffix in "AnkerMake/AnkerMake_64bit_fp/login.json" "Ankermake/AnkerMake_64bit_fp/login.json"; do
name="$root/$prefix/$suffix";
if [ -f "${name}" ]; then
echo "** Importing ${name} credentials **";
docker cp -L "${name}" ${CONTAINER}:/tmp
if docker exec -it ${CONTAINER} /app/ankerctl.py -k config import /tmp/login.json; then
echo "Configuration imported successfully. Restarting container..."
docker restart ${CONTAINER}
exit $?
else
echo "Configuration import failed :("
fi
else
echo "Configuration import failed :("
echo "** No ${name} credentials detected **";
fi
else
echo "** No ${name} credentials detected **";
fi
done
done
done
done
fi

0 comments on commit 8af1fbf

Please sign in to comment.