Skip to content

Commit bba16a6

Browse files
committed
Changed docker compose file to accept optional configuration parameters. Added helper shell script for docker.
Changed docker import to accept a login.json in the currect directory if available.
1 parent 0007f4a commit bba16a6

File tree

4 files changed

+130
-20
lines changed

4 files changed

+130
-20
lines changed

.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FLASK_HOST=127.0.0.1
2+
FLASK_PORT=4470
3+
ANKERCTL_DATA=ankerctl_vol

compose.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash
2+
3+
if [ -f '.env' ]; then
4+
export $(grep -v '^#' .env | xargs)
5+
else
6+
FLASK_HOST=127.0.0.1
7+
FLASK_PORT=4470
8+
BUILD_IMAGE=""
9+
ANKERCTL_DATA=ankerctl_vol
10+
fi
11+
12+
13+
print_usage() {
14+
15+
echo "Usage: $0 [option] <command>"
16+
echo ""
17+
echo "Options:"
18+
echo ""
19+
echo " -o Open mode. Allow connections from the network"
20+
echo " -b Build the docker image from source"
21+
echo " -p <port> Port for Ankerctl web interface"
22+
echo " -d <data> Ankerctl data volume"
23+
echo ""
24+
echo "Commands:"
25+
echo " up Run the docker container"
26+
echo " down Stop the docker container"
27+
}
28+
29+
30+
exit_error() {
31+
print_usage
32+
exit 1
33+
}
34+
35+
if [ $# -eq 0 ]; then
36+
print_usage
37+
exit 0
38+
fi
39+
40+
OPT_MATCHES=':obp:d:'
41+
42+
while getopts "${OPT_MATCHES}" options; do
43+
case "${options}" in
44+
o) FLASK_HOST=0.0.0.0 ;;
45+
b) BUILD_IMAGE="1" ;;
46+
p) FLASK_PORT=${OPTARG} ;;
47+
d) ANKERCTL_DATA=${OPTARG} ;;
48+
:)
49+
echo "Error: -${OPTARG} requires an argument"
50+
exit_error
51+
;;
52+
*)
53+
exit_error
54+
;;
55+
esac
56+
done
57+
58+
COMMAND=${@:$OPTIND:1}
59+
EXTRA=${@:$OPTIND+1:1}
60+
61+
if [ ! -z "${EXTRA}" ]; then
62+
echo "No parameters allowed after command"
63+
exit_error
64+
fi
65+
66+
echo "Command: ${COMMAND}"
67+
68+
case "${COMMAND}" in
69+
up)
70+
if [ ! -z "${BUILD_IMAGE}" ]; then
71+
# build docker image
72+
COMPOSE_EXTRA_PARAMS="--build "
73+
fi
74+
75+
FLASK_HOST=${FLASK_HOST} FLASK_PORT=${FLASK_PORT} ANKERCTL_DATA=${ANKERCTL_DATA} docker-compose up ${COMPOSE_EXTRA_PARAMS} -d
76+
77+
cat << EOF > ./.env
78+
FLASK_HOST=${FLASK_HOST}
79+
FLASK_PORT=${FLASK_PORT}
80+
BUILD_IMAGE=${BUILD_IMAGE}
81+
ANKERCTL_DATA=${ANKERCTL_DATA}
82+
EOF
83+
84+
;;
85+
86+
down)
87+
docker-compose down
88+
;;
89+
90+
*)
91+
echo "Unrecognized command: ${CMD}"
92+
echo ""
93+
exit_error
94+
;;
95+
esac

docker-compose.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ services:
1111

1212
# bind to localhost by default
1313
environment:
14-
- FLASK_HOST=127.0.0.1
15-
- FLASK_PORT=4470
14+
- FLASK_HOST=$FLASK_HOST
15+
- FLASK_PORT=$FLASK_PORT
1616
volumes:
17-
- ankerctl_vol:/root/.config/ankerctl
17+
- $ANKERCTL_DATA:/root/.config/ankerctl
1818

1919
volumes:
2020
ankerctl_vol:

docker-import.sh

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,37 @@ if [ "$(docker container inspect -f "{{.State.Status}}" "${CONTAINER}")" != "run
2323
fi
2424

2525

26-
WINEPREFIX=${WINEPREFIX:-$HOME/.wine}
26+
if [ -f "./login.json" ]; then
27+
echo "** Importing ./login.json **"
28+
docker cp -L ./login.json ${CONTAINER}:/tmp
29+
if docker exec -it ${CONTAINER} /app/ankerctl.py -k config import /tmp/login.json; then
30+
echo "Configuration imported successfully. Restarting container..."
31+
docker restart ${CONTAINER}
32+
exit $?
33+
else
34+
echo "Configuration import failed :("
35+
fi
36+
else
37+
WINEPREFIX=${WINEPREFIX:-$HOME/.wine}
2738

28-
for root in "${APPDATA}" "${HOME}"; do
29-
for prefix in "Library/Application Support" "$WINEPREFIX/drive_c/users/${USER}/AppData/Local"; do
30-
for suffix in "AnkerMake/AnkerMake_64bit_fp/login.json" "Ankermake/AnkerMake_64bit_fp/login.json"; do
31-
name="$root/$prefix/$suffix";
32-
if [ -f "${name}" ]; then
33-
echo "** Importing ${name} credentials **";
34-
docker cp -L "${name}" ${CONTAINER}:/tmp
35-
if docker exec -it ${CONTAINER} /app/ankerctl.py -k config import /tmp/login.json; then
36-
echo "Configuration imported successfully. Restarting container..."
37-
docker restart ${CONTAINER}
38-
exit $?
39+
for root in "${APPDATA}" "${HOME}"; do
40+
for prefix in "Library/Application Support" "$WINEPREFIX/drive_c/users/${USER}/AppData/Local"; do
41+
for suffix in "AnkerMake/AnkerMake_64bit_fp/login.json" "Ankermake/AnkerMake_64bit_fp/login.json"; do
42+
name="$root/$prefix/$suffix";
43+
if [ -f "${name}" ]; then
44+
echo "** Importing ${name} credentials **";
45+
docker cp -L "${name}" ${CONTAINER}:/tmp
46+
if docker exec -it ${CONTAINER} /app/ankerctl.py -k config import /tmp/login.json; then
47+
echo "Configuration imported successfully. Restarting container..."
48+
docker restart ${CONTAINER}
49+
exit $?
50+
else
51+
echo "Configuration import failed :("
52+
fi
3953
else
40-
echo "Configuration import failed :("
54+
echo "** No ${name} credentials detected **";
4155
fi
42-
else
43-
echo "** No ${name} credentials detected **";
44-
fi
56+
done
4557
done
4658
done
47-
done
59+
fi

0 commit comments

Comments
 (0)