FROM ubuntu:latest

RUN DEBIAN_FRONTEND=noninteractive apt update
RUN DEBIAN_FRONTEND=noninteractive apt install -y libsecret-1-dev curl
RUN curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o /usr/local/bin/n && chmod +x /usr/local/bin/n
RUN n lts
RUN apt install -y gnome-keyring dbus-x11

# Start the gnome keyring daemon when a bash session is initialized (requires passing --privileged when calling `docker run`)
RUN echo '[ -z "$GNOME_KEYRING_CONTROL" ] && eval $(echo letmein | gnome-keyring-daemon --unlock | sed -e "s/^/export /g")' > /root/.bashrc

COPY . /root/alks-cli

WORKDIR /root/alks-cli

# --unsafe-perm=true keeps npm from dropping to the `nobody` user for lifecycle
# scripts when installing as root. The keychain backend (@napi-rs/keyring) ships
# prebuilt binaries and has no postinstall build — the former keytar-specific
# reason for this flag is gone — but it is retained as a general safeguard for
# any dependency lifecycle script during a root global install in this container.
RUN npm install --unsafe-perm=true . -g

# Start a dbus session and then run /bash/bash as the callback
ENTRYPOINT [ "dbus-run-session", "--", "/bin/bash" ]