Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import login.json automatically in docker compose #89

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 53 additions & 21 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,58 @@
version: '3.9.1'
version: "3.9.1"

# You must manually run `ankerctl config import` atleast once
# docker run \
# -v ankerctl_vol:/root/.config/ankerctl \
# -v "$HOME/Library/Application Support/AnkerMake/AnkerMake_64bit_fp/login.json:/tmp/login.json" \
# ankerctl config import /tmp/login.json
services:
ankerctl:
image: ankerctl/ankerctl:latest
container_name: ankerctl
restart: unless-stopped
build: .
environment:
- FLASK_PORT=4470
- FLASK_HOST=0.0.0.0
volumes:
- ankerctl_vol:/root/.config/ankerctl
ports:
- 127.0.0.1:4470:4470
entrypoint: "/app/ankerctl.py"
command: ["webserver", "run"]
ankerctl_seed_mac:
image: busybox
container_name: ankerctl_seed_mac
restart: "no"
volumes:
- ankerctl_vol:/root/.config/ankerctl
- "$HOME/Library/Application Support/AnkerMake/AnkerMake_64bit_fp/login.json:/tmp/login.json"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail on mac because of the space, you need to properly escape the space between Application and Support.

command: sh -c "cp /tmp/login.json /root/.config/ankerctl/login.json || true"
ankerctl_seed_linux:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no version of AnkerMake for Linux just yet, and if there is in the future the path will look more like $HOME/.local/share/<AnkerMakeSpecificPath>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INFORMATIONAL: Not for v1.0.0 ship but for v.1.1 we can look at their alpha build of the new slicer since that does have a linux build.

Copy link
Contributor

@thomasjpatterson thomasjpatterson May 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok after futzing with this for about an hour I have it working this way:

volumes: - ankerctl_vol:/root/.config/ankerctl - $HOME/Library/Application Support/AnkerMake/AnkerMake_64bit_fp/login.json:/tmp/login.json #command: sh -c "cp /tmp/login.json /root/.config/ankerctl/login.json || true"
NO command argument

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Hmm, that is interesting. If the command argument is commented out then the cp won't work.

I suspect what happened is another previous attempt copied the login.json to the volume.

If you purge your docker volumes, and then try again I'm fairly confident that this will not work with that line commented out.

docker system prune
docker volume rm ankermake-m5-protocol_ankerctl_vol
docker compose up

image: busybox
container_name: ankerctl_seed_linux
restart: "no"
volumes:
- ankerctl_vol:/root/.config/ankerctl
# TODO: verify this is the correct linux path
- "$HOME/AnkerMake/AnkerMake_64bit_fp/login.json:/tmp/login.json"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be our best bet, for Linux users running ankermake through wine with default settings:

$HOME/.wine/drive_c/users/$USER/AppData/Local/AnkerMake/AnkerMake_64bit_fp/login.json

command: sh -c "cp /tmp/login.json /root/.config/ankerctl/login.json || true"
ankerctl_import:
# image: ghcr.io/ankermgmt/ankermake-m5-protocol:latest
image: ankerctl/ankerctl:latest
container_name: ankerctl_import
restart: "no"
build: .
volumes:
- ankerctl_vol:/root/.config/ankerctl
entrypoint: "/app/ankerctl.py"
command: ["config", "import", "/root/.config/ankerctl/login.json"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be simpler to put login.json in (say) /root/login.json?

In fact, this location clashes with an upcoming feature, where it will be possible to select other "profiles" than default.json. (profiles are "complete config imports" - thank of them like browser profiles).

Also, can't we stack ankerctl_seed_mac and ankerctl_seed_linux, by just trying several cp ... || true with different paths? We could try all well-known paths, and if one of them works, we can import it. How does that sound?

I realize now that /root isn't part of the volume, but since we import the config, I suppose that's actually a feature, since the copy of login.json will then be ephemeral, while the imported default.json will be kept. Seems good?

depends_on:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No ankerseed for Windows? Bind volumes work in Windows too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this just a naming thing though? It's called ankerctl_import and is still importing the login.json file right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, lets scrap linux support, and add windows support. Do you know the path on windows?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way I understand it, the ankerctl_seed_* containers try to copy-in a login.json file from the host system, and ankerctl_import runs the import action.

@spuder could we make ankerctl_import responsible for all the cp ... || true attempts, and also ankerctl.py config import? That would make this a simple two-step thing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, lets scrap linux support, and add windows support. Do you know the path on windows?

%LOCALAPPDATA%\Ankermake\AnkerMake_64bit_fp\login.json

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spuder See above

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or c:\Users\$USER\AppData\Local\Ankermake\AnkerMake_64bit_fp\login.json

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried a few local edits and can't find a way of getting thsi to work for Windows using Docker Desktop on WSL.

- ankerctl_seed_mac
- ankerctl_seed_linux

ankerctl:
# image: ghcr.io/ankermgmt/ankermake-m5-protocol:latest
image: ankerctl/ankerctl:latest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain how ankerctl/ankerctl:latest works? I'm not quite familiar with that syntax.

Suppose we make sure ghcr.io/ankermgmt/ankermake-m5-protocol:latest always has a fresh image available. What are the pros/cons of using that image here, vs pointing to ankerctl/ankerctl, which (I imagine) points to the locally-built image?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually ghcr.io/ankermgmt/ankermake-m5-protocol:latest will be preferred, however for testing it won't work since I need the latest docker container available on my machine.

We can switch ankerctl/ankerctl to ghcr once we have the updated web gui published.
I can actually change this in git, and just override it temporarily while testing.

container_name: ankerctl
restart: unless-stopped
build: .
environment:
- FLASK_PORT=4470
- FLASK_HOST=0.0.0.0
volumes:
- ankerctl_vol:/root/.config/ankerctl
ports:
- 127.0.0.1:4470:4470
working_dir: /app
entrypoint: "/app/ankerctl.py"
command: ["webserver", "run"]
depends_on:
- ankerctl_seed_mac
- ankerctl_seed_linux
- ankerctl_import

volumes:
ankerctl_vol:
external: true
external: false