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
Containerization #91
Open
Danack
wants to merge
9
commits into
php:master
Choose a base branch
from
Danack:containers
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Containerization #91
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9d97d12
It's 2021. Containers are a thing.
Danack a8b2895
Group by needs to specifically reference a column name, not a variable.
Danack 1dc3db5
Add two high quality api endpoints.
Danack 7d7c235
Obfuscate the email a bit more.
Danack d98d67c
Added instructions on how to bring the docker box up.
Danack 1080c0f
Retrieve bug id, so that the bug can be linked to from other sites.
Danack 729468d
Update fixtures to have realistic data.
Danack 4489863
Tidy up from feedback.
Danack fb1d82b
clarified comment.
Danack File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ | |
|
||
# Generated by Composer | ||
/vendor/ | ||
composer.phar | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
# * IMPORTANT: Additional settings that can override those from this file! | ||
# The files must end with '.cnf', otherwise they'll be ignored. | ||
# | ||
!includedir /etc/mysql/conf.d/ | ||
!includedir /etc/mysql/mysql.conf.d/ | ||
|
||
[mysqld] | ||
sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
FROM debian:9-slim | ||
|
||
USER root | ||
|
||
# Get Debian up-to-date | ||
RUN apt-get update -qq \ | ||
&& DEBIAN_FRONTEND=noninteractive apt-get install -y git \ | ||
mariadb-client wget curl iputils-ping \ | ||
ca-certificates lsb-release apt-transport-https gnupg | ||
|
||
# Install 3rd party PHP 7.2 packages | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment mentions 7.2 while actually 7.4 is installed. |
||
RUN echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee -a /etc/apt/sources.list.d/php.list | ||
|
||
RUN wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg | ||
|
||
RUN apt-get update -qq \ | ||
&& DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y php7.4 php7.4-common php7.4-cli \ | ||
php7.4-mysql php7.4-curl php7.4-xml php7.4-mbstring \ | ||
php7.4-intl php7.4-zip php7.4-sqlite3 unzip | ||
|
||
# Make the default directory you | ||
WORKDIR /var/app | ||
|
||
# CMD tail -f README.md | ||
CMD sh /var/app/containers/installer/entrypoint.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
set -e | ||
set -x | ||
|
||
# Generate a local_config.php if it doesn't already exist. | ||
if [ ! -f "/var/app/local_config.php" ]; then | ||
echo "<?php" > /var/app/local_config.php | ||
echo "" >> /var/app/local_config.php | ||
echo "/**" >> /var/app/local_config.php | ||
echo " * Generated from containers/installer/entrypoint.sh" >> /var/app/local_config.php | ||
|
||
echo " * Feel free to edit. Delete to have it re-generated from" >> /var/app/local_config.php | ||
echo " * scratch on next 'docker-compose up'" >> /var/app/local_config.php | ||
echo " */" >> /var/app/local_config.php | ||
echo "" >> /var/app/local_config.php | ||
echo "\$site_data = [" >> /var/app/local_config.php | ||
echo " 'method' => 'http'," >> /var/app/local_config.php | ||
echo " 'url' => '127.0.0.1'," >> /var/app/local_config.php | ||
echo " 'basedir' => ''," >> /var/app/local_config.php | ||
echo " 'email' => 'php-bugs@lists.php.net'," >> /var/app/local_config.php | ||
echo " 'doc_email' => 'doc-bugs@lists.php.net'," >> /var/app/local_config.php | ||
echo " 'security_email' => 'security@php.net'," >> /var/app/local_config.php | ||
echo " 'db' => 'phpbugsdb'," >> /var/app/local_config.php | ||
echo " 'db_user' => 'nobody'," >> /var/app/local_config.php | ||
echo " 'db_pass' => 'bugs_password'," >> /var/app/local_config.php | ||
echo " 'db_host' => 'db'," >> /var/app/local_config.php | ||
echo " 'patch_tmp' => \"{\$ROOT_DIR}/uploads/patches/\"," >> /var/app/local_config.php | ||
echo "];" >> /var/app/local_config.php | ||
echo "" >> /var/app/local_config.php | ||
echo "define('DEVBOX', true);" >> /var/app/local_config.php | ||
fi | ||
|
||
|
||
if [ ! -f "composer.phar" ]; then | ||
echo "composer.phar does not exist, downloading."; | ||
curl "https://getcomposer.org/download/2.0.9/composer.phar" -o composer.phar | ||
fi | ||
php composer.phar install | ||
|
||
echo "Installer is finished." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
FROM debian:9-slim | ||
|
||
USER root | ||
|
||
# Get Debian up-to-date | ||
RUN apt-get update -qq \ | ||
&& DEBIAN_FRONTEND=noninteractive apt-get install -y git \ | ||
mariadb-client wget curl iputils-ping \ | ||
ca-certificates lsb-release apt-transport-https gnupg | ||
|
||
# bsdmainutils | ||
|
||
# Install 3rd party PHP 7.2 packages | ||
RUN echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee -a /etc/apt/sources.list.d/php.list | ||
|
||
RUN wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg | ||
|
||
RUN apt-get update -qq \ | ||
&& DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y php7.4 php7.4-common php7.4-cli \ | ||
php7.4-mysql php7.4-curl php7.4-xml php7.4-mbstring \ | ||
php7.4-intl php7.4-redis php7.4-zip php7.4-sqlite3 unzip | ||
|
||
# Make the default directory you | ||
WORKDIR /var/app | ||
|
||
# CMD tail -f README.md | ||
CMD sh /var/app/containers/web/entrypoint.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
set -e | ||
set -x | ||
|
||
|
||
echo "Wait for DB before starting site."; | ||
|
||
php scripts/wait_for_db.php | ||
|
||
echo "DB, site should be available." | ||
|
||
php -S 0.0.0.0:80 -t www/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
version: "3" | ||
services: | ||
db: | ||
image: mysql:5.7 | ||
environment: | ||
MYSQL_ROOT_PASSWORD: sql_root_password | ||
MYSQL_DATABASE: phpbugsdb | ||
MYSQL_USER: nobody | ||
MYSQL_PASSWORD: "bugs_password" | ||
networks: | ||
default_network: | ||
ports: | ||
- "3306:3306" | ||
volumes: | ||
- ./containers/db/my.cnf:/etc/mysql/my.cnf | ||
- ./data/mysql:/var/lib/mysql | ||
# The next lines init the DB. Rename them to force correct order | ||
- ./sql/schema.sql:/docker-entrypoint-initdb.d/2_schemas.sql | ||
- ./sql/fixtures.sql:/docker-entrypoint-initdb.d/3_fixtures.sql | ||
installer: | ||
build: containers/installer | ||
environment: | ||
# - COMPOSER_CACHE_DIR=/var/app/var/cache/composer | ||
- COMPOSER_ALLOW_SUPERUSER=1 | ||
networks: | ||
default_network: | ||
volumes: | ||
- .:/var/app | ||
web: | ||
build: containers/web | ||
depends_on: | ||
- "db" | ||
- "installer" | ||
networks: | ||
default_network: | ||
ports: | ||
- "80:80" | ||
volumes: | ||
- .:/var/app | ||
networks: | ||
default_network: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
$ROOT_DIR = __DIR__ . '/../'; | ||
require_once __DIR__.'/../local_config.php'; | ||
|
||
$pdo = new \PDO( | ||
'mysql:host='.$site_data["db_host"].';dbname='.$site_data["db"].';charset=utf8', | ||
$site_data["db_user"], | ||
$site_data["db_pass"], | ||
[ | ||
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, | ||
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, | ||
\PDO::ATTR_EMULATE_PREPARES => false, | ||
] | ||
); | ||
|
||
$res = $pdo->prepare(' | ||
INSERT INTO bugdb ( | ||
package_name, | ||
bug_type, | ||
email, | ||
sdesc, | ||
ldesc, | ||
php_version, | ||
php_os, | ||
passwd, | ||
reporter_name, | ||
status, | ||
ts1, | ||
private, | ||
visitor_ip | ||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, "Open", NOW(), ?, INET6_ATON(?)) | ||
'); | ||
|
||
$params = [ | ||
$package_name = "Web Site", | ||
$bug_type = "Bug", | ||
$email = 'john@example.com', | ||
$sdesc = 'short desc', | ||
$ldesc = 'This is a long description', | ||
$php_version = '8.0.2', | ||
$php_os = '', | ||
$passwd = 'pass12345', | ||
$reporter_name = 'danack', | ||
// $status, | ||
// $ts1, | ||
$private = 'N', | ||
$visitor_ip = '127.0.0.1' | ||
]; | ||
|
||
$result = $res->execute($params); | ||
|
||
var_dump($result); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
$ROOT_DIR = __DIR__ . '/../'; | ||
require_once __DIR__.'/../local_config.php'; | ||
|
||
$pdo = new \PDO( | ||
'mysql:host='.$site_data["db_host"].';dbname='.$site_data["db"].';charset=utf8', | ||
$site_data["db_user"], | ||
$site_data["db_pass"], | ||
[ | ||
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, | ||
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, | ||
\PDO::ATTR_EMULATE_PREPARES => false, | ||
] | ||
); | ||
|
||
$res = $pdo->prepare(" | ||
INSERT INTO bugdb_comments (bug, email, reporter_name, comment, comment_type, ts, visitor_ip) | ||
VALUES (?, ?, ?, ?, ?, NOW(), INET6_ATON(?)) | ||
"); | ||
|
||
$params = [ | ||
$bug = 2, | ||
$email = 'dan_test@example.com', | ||
$reporter_name = 'John', | ||
$comment = 'The day shall not save them', | ||
$comment_type = 'unknown', | ||
// $ts, | ||
$visitor_ip = '127.0.0.1' | ||
]; | ||
|
||
$result = $res->execute($params); | ||
|
||
var_dump($result); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
// ugh | ||
$ROOT_DIR = __DIR__ . '/../'; | ||
require_once __DIR__.'/../local_config.php'; | ||
|
||
$maxTimeToWait = 120; | ||
$startTime = microtime(true); | ||
|
||
do { | ||
try { | ||
$pdo = new \PDO( | ||
'mysql:host='.$site_data["db_host"].';dbname='.$site_data["db"].';charset=utf8', | ||
$site_data["db_user"], | ||
$site_data["db_pass"], | ||
[ | ||
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, | ||
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, | ||
\PDO::ATTR_EMULATE_PREPARES => false, | ||
] | ||
); | ||
|
||
$pdo->query('SELECT 1'); | ||
echo "DB appears to be available.\n"; | ||
exit(0); | ||
} catch (\Exception $e) { | ||
echo "DB not available yet.\n"; | ||
} | ||
|
||
sleep(1); | ||
} while ((microtime(true) - $startTime) < $maxTimeToWait); | ||
|
||
echo "DB failed to be available in $maxTimeToWait seconds.\n"; | ||
exit(-1); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
/data/
or at least/data/mysql/
has to be added to ignores because mysql data that is mounted from there makes the working copy dirty.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kamazee thanks. Have cleaned this up.