r3c / yaronet

Lightweight, traditionnal but full-featured PHP bulletin board
https://www.yaronet.com
GNU Affero General Public License v3.0
17 stars 4 forks source link

WIP: Feature/docker setup #3

Closed pinboro closed 5 years ago

pinboro commented 5 years ago

Introduce a simple Docker / docker-compose setup for local environment.

pinboro commented 5 years ago

I am considering running the script with Apache user.

pinboro commented 5 years ago

@r3c Updated.

pinboro commented 5 years ago

Oh, yeah, I was sticking to 'C' locale, which you need to input on the install.php page. But let's adjust to your default one.

RewriteBase needs at least one argument, which is "/" in my case. Could you update the default to be "/" please?

r3c commented 5 years ago

Yes you're right about RewriteBase being broken, let me fix that :)

pinboro commented 5 years ago

Default locale changed to en_US.UTF-8

pinboro commented 5 years ago

Added a retry loop for db connection to not fail hard when db container is not ready yet.

r3c commented 5 years ago

Almost there! It's mostly working now, the only remaining issue I can't get around for now is parser.php not being generated. When I run sudo docker-compose up command, following message appears in the log:

{ [Error: EACCES: permission denied, open 'src/parser.php']
  errno: -13,
  code: 'EACCES',
  syscall: 'open',
  path: 'src/parser.php' }

I don't know if it's related to root user or something else and will continue to investigate. Thanks for all your new changes!

[update] Grant permissions on setup/module to www-data from the entrypoint.sh script does the trick, although I'm not sure this is a really clean way of dealing with the issue as it's visible from host point of view.

Now this is done I'm having errors when web host tries to mount, saying it cannot resolve the DB hostname 😕

pinboro commented 5 years ago

Can you share the entire log?

pinboro commented 5 years ago

Also, this is good to do to be able to run docker command with being root.

https://docs.docker.com/install/linux/linux-postinstall/#manage-docker-as-a-non-root-user

r3c commented 5 years ago

That's not the same: your link describes how to configure Docker to avoid entering sudo docker on every command. What I was referring to is the chown call made on source files to switch them to www-data user, which I understand is needed for Apache to serve development files that are supposedly owned by current user instead. However this makes them impossible to update from host system anyway, which is not a desirable effect. I'll search how to avoid this in a further commit.

Here is the log, seems something is going wrong with the SQL setup, I'll try to see what exactly:


Creating network "yaronet_default" with the default driver
Creating yaronet_db_1 ... 
Creating yaronet_db_1 ... done
Creating yaronet_web_1 ... 
Creating yaronet_web_1 ... done
Attaching to yaronet_db_1, yaronet_web_1
db_1   | Initializing database
db_1   | 2019-03-10T10:32:01.699366Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1   | 2019-03-10T10:32:01.704379Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
db_1   | 2019-03-10T10:32:01.704398Z 0 [ERROR] Aborting
db_1   | 
yaronet_db_1 exited with code 1
web_1  | audited 4435 packages in 6.823s
web_1  | found 1 low severity vulnerability
web_1  |   run `npm audit fix` to fix them, or `npm audit` for details
web_1  | built src/parser.php
web_1  | audited 2 packages in 0.855s
web_1  | found 0 vulnerabilities
web_1  | 
web_1  | 
web_1  | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /yaronet/setup/docker/initdb.php on line 12
web_1  | 
web_1  | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /yaronet/setup/docker/initdb.php on line 12
web_1  | 
web_1  | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: No address associated with hostname
web_1  | Retrying...(9)
web_1  | 
web_1  | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /yaronet/setup/docker/initdb.php on line 12
web_1  | 
web_1  | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /yaronet/setup/docker/initdb.php on line 12
web_1  | 
web_1  | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: No address associated with hostname
web_1  | Retrying...(8)
web_1  | 
web_1  | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /yaronet/setup/docker/initdb.php on line 12
web_1  | 
web_1  | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /yaronet/setup/docker/initdb.php on line 12
web_1  | 
web_1  | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: No address associated with hostname
web_1  | Retrying...(7)
web_1  | 
web_1  | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /yaronet/setup/docker/initdb.php on line 12
web_1  | 
web_1  | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /yaronet/setup/docker/initdb.php on line 12
web_1  | 
web_1  | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: No address associated with hostname
web_1  | Retrying...(6)
web_1  | 
web_1  | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /yaronet/setup/docker/initdb.php on line 12
web_1  | 
web_1  | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /yaronet/setup/docker/initdb.php on line 12
web_1  | 
web_1  | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: No address associated with hostname
web_1  | Retrying...(5)
web_1  | 
web_1  | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /yaronet/setup/docker/initdb.php on line 12
web_1  | 
web_1  | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /yaronet/setup/docker/initdb.php on line 12
web_1  | 
web_1  | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: No address associated with hostname
web_1  | Retrying...(4)
web_1  | 
web_1  | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /yaronet/setup/docker/initdb.php on line 12
web_1  | 
web_1  | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /yaronet/setup/docker/initdb.php on line 12
web_1  | 
web_1  | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: No address associated with hostname
web_1  | Retrying...(3)
web_1  | 
web_1  | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /yaronet/setup/docker/initdb.php on line 12
web_1  | 
web_1  | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /yaronet/setup/docker/initdb.php on line 12
web_1  | 
web_1  | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: No address associated with hostname
web_1  | Retrying...(2)
web_1  | 
web_1  | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /yaronet/setup/docker/initdb.php on line 12
web_1  | 
web_1  | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /yaronet/setup/docker/initdb.php on line 12
web_1  | 
web_1  | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: No address associated with hostname
web_1  | Retrying...(1)
web_1  | 
web_1  | Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /yaronet/setup/docker/initdb.php on line 12
web_1  | 
web_1  | Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /yaronet/setup/docker/initdb.php on line 12
web_1  | 
web_1  | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: No address associated with hostname
yaronet_web_1 exited with code 1```
pinboro commented 5 years ago

I know it is not the same, just sharing for removing you some pain:)

r3c commented 5 years ago

Ah OK :)

[edit] Removed the "tmp" folder, now it's booting. Let's wait and see :)

r3c commented 5 years ago

Working! Here is the only change I applied to your latest patch:

$ git diff
diff --git a/setup/docker/entrypoint.sh b/setup/docker/entrypoint.sh
index bb47fc3..f0aaf9b 100755
--- a/setup/docker/entrypoint.sh
+++ b/setup/docker/entrypoint.sh
@@ -10,7 +10,7 @@ ln -s ${APP_HOME}/src /var/www/html

 # Install dependencies
 cd ${APP_HOME}
-chown -R www-data:www-data src /var/www
+chown -R www-data:www-data setup/module src /var/www
 npm install
 su -s setup/configure.sh www-data

How do you feel about applying this change and merging your patch into master? Seems a good baseline :)

pinboro commented 5 years ago

I am good! Let’s push a first baseline.

There are improvement points around the entrypoint, and permissions, but they are not critical for a local environment.

r3c commented 5 years ago

Done! Thanks a lot for your contribution and help! 👍