Repository: mathesar-foundation/mathesar

Issue:
Installation issues when running on mac (silicon)
## Description
I'm facing these issues while trying to install using the latest `install.sh` script from master. I'm running 'macOS Big Sur', on a mac with Apple M1 processor.

1. Error thrown, while the line `sudo docker compose --profile prod up -d --wait` runs in the install script. Any command with `sudo docker` throws an error.

   ```
    2023/02/25 23:34:45 must use ASL logging (which requires CGO) if running as root
    2023/02/25 23:34:45 must use ASL logging (which requires CGO) if running as root
    2023/02/25 23:34:45 must use ASL logging (which requires CGO) if running as root
    2023/02/25 23:34:45 must use ASL logging (which requires CGO) if running as root
    [+] Running 0/0
    ⠋ watchtower Pulling                                                                                                                   0.1s
    ⠋ db Pulling                                                                                                                           0.1s
    ⠋ caddy-reverse-proxy Pulling                                                                                                          0.1s
    ⠋ service Pulling                                                                                                                      0.1s
    error getting credentials - err: exit status 1, out: ``
   ``` 
    This is because docker cannot run as root (or with sudo privileges) in mac.
    If possible, we should avoid `sudo` generally, while running on a mac.

2. The images don't run after downloading because the platforms do not match.
    ```
    ⠙ caddy-reverse-proxy The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested  0.0s
    ⠿ Container mathesar_service                                                                                                                                         Waiting 19.1s
    ⠏ service The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested              0.0s
    container for service "service" exited (3)
    ```
    We should be publishing an arm image along with the existing amd image. I sent a mail regarding this.

3. Installation fails because wget is not installed by default. We need to check if it is present during installation.

4. Startup (i.e. `docker compose --profile prod up -d --wait`) fails because `SECRET_KEY` in `.env` file is empty.


Discussion:
@kgodey I've added this to 'Launch nice-to-haves' but I think it might be a launch blocker. I assume a good percentage of people on HN might be using apple silicon.

Also, my local development setup is completely messed up due to the images only being `amd64`.
Suggestions to fix the issues:

For 1: Remove all sudo commands used with `docker` (Avoid sudo entirely if possible).
For 2: I've sent a [mail on pushing multi-platform images](https://groups.google.com/a/mathesar.org/g/mathesar-developers/c/dThnYWIYdn0/m/cmSsMWJ0AQAJ).
For 3: `wget` needs to be present for install.sh to work. We need to add it to docs, and check it the same way we check if docker is installed.
For 4: I have no idea. We need to debug this one.
> For 1: Remove all sudo commands used with `docker` (Avoid sudo entirely if possible).

This is a no-go for multiple reasons for anyone running on Linux.
- The rootless docker extension doesn't work with our upgrade infra (and generally has a bunch of networking limitations)
- Adding the user to the `docker` group opens up major security vulnerabilities for Linux users, and we don't want to recommend that.
- I don't think the upgrade infrastructure (or any upgrade infrastructure that uses the same general method) will work without `sudo`, since you need to mount the docker unix socket to communicate with the daemon from the upgrade container.
> This is a no-go for multiple reasons for anyone running on Linux.

I understand. Can we update our docs and tweak the script, so that linux users run the entire script as sudo (or give appropriate permissions to the user they want to use), and mac users can directly run the script?
- We'll branch based on `$OSTYPE` for sudo on docker commands
- We'll use the multiplatform builds for images
- We'll use `curl` instead of `wget`
- We'll remove the `-w` flag from the `base64` call in secret key generator command (it doesn't exist on mac)

Resolving patch:
diff --git a/db/install.py b/db/install.py
--- a/db/install.py
+++ b/db/install.py
@@ -10,7 +10,8 @@ def install_mathesar(
 ):
     """Create database and install Mathesar on it."""
     user_db_engine = engine.create_future_engine(
-        username, password, hostname, database_name, port
+        username, password, hostname, database_name, port,
+        connect_args={"connect_timeout": 10}
     )
     try:
         user_db_engine.connect()
@@ -48,6 +49,7 @@ def _create_database(database_name, hostname, username, password, port, skip_con
         root_database = "postgres"
         root_db_engine = engine.create_future_engine(
             username, password, hostname, root_database, port,
+            connect_args={"connect_timeout": 10}
         )
         with root_db_engine.connect() as conn:
             conn.execution_options(isolation_level="AUTOCOMMIT")


Test patch: