From 8cda0f8ccc35ce8e60deedc0b411638204a64eac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20=C5=A0?= Date: Wed, 3 Apr 2019 18:31:27 +0200 Subject: [PATCH 1/3] Add basic support for Docker --- .env.sample | 23 +++++++++++++++++ .gitignore | 2 ++ Dockerfile.database | 3 +++ Dockerfile.pgp | 11 +++++++++ Dockerfile.web | 25 +++++++++++++++++++ docker-compose.yml | 55 +++++++++++++++++++++++++++++++++++++++++ lib/config.docker.php | 52 ++++++++++++++++++++++++++++++++++++++ lib/config.template.php | 1 + lib/helpers.php | 2 +- public/.htaccess | 7 ++++++ 10 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 .env.sample create mode 100644 Dockerfile.database create mode 100644 Dockerfile.pgp create mode 100644 Dockerfile.web create mode 100644 docker-compose.yml create mode 100644 lib/config.docker.php create mode 100644 public/.htaccess diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..186a1a7 --- /dev/null +++ b/.env.sample @@ -0,0 +1,23 @@ +# App settings +APP_BASE=https://indielogin.com/ +APP_NAME=IndieLogin.com +APP_USERAGENT= + +# Github client settings +GITHUB_ID= +GITHUB_SECRET= + +# Twitter client settings +TWITTER_ID= +TWITTER_SECRET= + +# Mailgun settings +MAILGUN_KEY=key- +MAILGUN_DOMAIN=mail.indielogin.com +MAILGUN_FROM="indielogin.com" + +# Database settings +MYSQL_DATABASE=indielogin +MYSQL_USER=indielogin +MYSQL_PASSWORD=indielogin +MYSQL_RANDOM_ROOT_PASSWORD=yes diff --git a/.gitignore b/.gitignore index 55ae295..0be710c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ vendor/ lib/config.php logs/ pgp/data/ +data/ +.env \ No newline at end of file diff --git a/Dockerfile.database b/Dockerfile.database new file mode 100644 index 0000000..2294ff7 --- /dev/null +++ b/Dockerfile.database @@ -0,0 +1,3 @@ +FROM mariadb + +COPY schema/schema.sql /docker-entrypoint-initdb.d diff --git a/Dockerfile.pgp b/Dockerfile.pgp new file mode 100644 index 0000000..e3e8cc4 --- /dev/null +++ b/Dockerfile.pgp @@ -0,0 +1,11 @@ +FROM ruby:alpine + +RUN mkdir -p /usr/src/app +WORKDIR /usr/src/app + +RUN apk add build-base + +COPY pgp /usr/src/app +RUN bundle install + +CMD rackup --host 0.0.0.0 -p 9009 diff --git a/Dockerfile.web b/Dockerfile.web new file mode 100644 index 0000000..6dc252d --- /dev/null +++ b/Dockerfile.web @@ -0,0 +1,25 @@ +# Install dependencies + +FROM composer AS dependencies + +RUN mkdir -p /var/www/html +WORKDIR /var/www/html + +COPY . /var/www/html + +RUN composer install + +# Serve website + +FROM php:apache + +RUN mkdir -p /var/www/html +WORKDIR /var/www/html + +COPY --from=dependencies /var/www/html /var/www/html + +RUN docker-php-ext-install pdo_mysql mysqli +RUN a2enmod rewrite + +RUN sed -i 's/DocumentRoot \/var\/www\/html/DocumentRoot \/var\/www\/html\/public/' /etc/apache2/sites-available/000-default.conf +RUN sed -i 's/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0c2b2e9 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,55 @@ +version: "3" + +services: + web: + build: + context: . + dockerfile: Dockerfile.web + ports: + - 80:80 + volumes: + - .:/var/www/html + environment: + - APP_BASE + - APP_NAME + - GITHUB_ID + - GITHUB_SECRET + - TWITTER_ID + - TWITTER_SECRET + - MAILGUN_KEY + - MAILGUN_DOMAIN + - MAILGUN_FROM + - VERIFICATION_API + - MYSQL_DATABASE + - MYSQL_USER + - MYSQL_PASSWORD + depends_on: + - database + - pgp + - redis + + database: + build: + context: . + dockerfile: Dockerfile.database + volumes: + - .:/var/www/html + - data:/var/lib/mysql + environment: + - MYSQL_DATABASE + - MYSQL_USER + - MYSQL_PASSWORD + - MYSQL_RANDOM_ROOT_PASSWORD + + pgp: + build: + context: . + dockerfile: Dockerfile.pgp + volumes: + - .:/var/www/html + + redis: + image: redis:alpine + +volumes: + data: {} diff --git a/lib/config.docker.php b/lib/config.docker.php new file mode 100644 index 0000000..9f38163 --- /dev/null +++ b/lib/config.docker.php @@ -0,0 +1,52 @@ + MAILGUN_KEY, + 'domain' => MAILGUN_DOMAIN, + 'from' => MAILGUN_FROM + ]; + + public static $pgpVerificationAPI = PGP_API; + public static $redisAPI = REDIS_API; + + public static $db = [ + 'host' => MYSQL_HOST, + 'database' => MYSQL_DATABASE, + 'username' => MYSQL_USER, + 'password' => MYSQL_PASSWORD + ]; +} diff --git a/lib/config.template.php b/lib/config.template.php index ad4ab91..84d048f 100644 --- a/lib/config.template.php +++ b/lib/config.template.php @@ -17,6 +17,7 @@ class Config { ]; public static $pgpVerificationAPI = 'http://127.0.0.1:9009'; + public static $redisAPI = 'tcp://127.0.0.1:6379'; public static $db = [ 'host' => '127.0.0.1', diff --git a/lib/helpers.php b/lib/helpers.php index d18ff55..a731a14 100644 --- a/lib/helpers.php +++ b/lib/helpers.php @@ -63,7 +63,7 @@ function random_user_code() { function redis() { static $client = false; if(!$client) - $client = new Predis\Client('tcp://127.0.0.1:6379'); + $client = new Predis\Client(Config::$redisAPI); return $client; } diff --git a/public/.htaccess b/public/.htaccess new file mode 100644 index 0000000..ade97a5 --- /dev/null +++ b/public/.htaccess @@ -0,0 +1,7 @@ + + RewriteEngine On + + RewriteCond %{REQUEST_FILENAME} !-f + RewriteCond %{REQUEST_FILENAME} !-d + RewriteRule ^ /index.php [L] + From 036fbfa2634bfaadb61e7e3eb3d366bf3a3af14a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20=C5=A0?= Date: Wed, 3 Apr 2019 18:33:16 +0200 Subject: [PATCH 2/3] Fix new line --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0be710c..7092144 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ lib/config.php logs/ pgp/data/ data/ -.env \ No newline at end of file +.env From fb353ff7ad645ccc1f4ed54d9e2f59c85e5638ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20=C5=A0?= Date: Tue, 10 Sep 2019 20:27:34 +0200 Subject: [PATCH 3/3] Make better config file --- .env.sample | 5 +++ lib/config.docker.php | 81 +++++++++++++++++++++-------------------- lib/config.template.php | 1 + 3 files changed, 48 insertions(+), 39 deletions(-) diff --git a/.env.sample b/.env.sample index 186a1a7..81bbe84 100644 --- a/.env.sample +++ b/.env.sample @@ -16,7 +16,12 @@ MAILGUN_KEY=key- MAILGUN_DOMAIN=mail.indielogin.com MAILGUN_FROM="indielogin.com" +# Service settings +PGP_API=http://pgp:9009 +REDIS_API=tcp://redis:6379 + # Database settings +MYSQL_HOST=database MYSQL_DATABASE=indielogin MYSQL_USER=indielogin MYSQL_PASSWORD=indielogin diff --git a/lib/config.docker.php b/lib/config.docker.php index 9f38163..ca60169 100644 --- a/lib/config.docker.php +++ b/lib/config.docker.php @@ -1,52 +1,55 @@ MAILGUN_KEY, - 'domain' => MAILGUN_DOMAIN, - 'from' => MAILGUN_FROM + 'key' => '', + 'domain' => '', + 'from' => '' ]; - public static $pgpVerificationAPI = PGP_API; - public static $redisAPI = REDIS_API; + public static $pgpVerificationAPI = ''; + public static $redisAPI = ''; public static $db = [ - 'host' => MYSQL_HOST, - 'database' => MYSQL_DATABASE, - 'username' => MYSQL_USER, - 'password' => MYSQL_PASSWORD + 'host' => '', + 'database' => '', + 'username' => '', + 'password' => '' ]; } + +Config::$base = getenv('APP_BASE', true); +Config::$name = getenv('APP_NAME', true); +Config::$useragent = getenv('APP_USERAGENT', true); + +Config::$githubClientID = getenv('GITHUB_ID', true); +Config::$githubClientSecret = getenv('GITHUB_SECRET', true); + +Config::$twitterClientID = getenv('TWITTER_ID', true); +Config::$twitterClientSecret = getenv('TWITTER_SECRET', true); + +Config::$mailgun = [ + 'key' => getenv('MAILGUN_KEY', true), + 'domain' => getenv('MAILGUN_DOMAIN', true), + 'from' => getenv('MAILGUN_FROM', true) +]; + +Config::$pgpVerificationAPI = getenv('PGP_API', true); +Config::$redisAPI = getenv('REDIS_API', true); + +Config::$mailgun = [ + 'host' => getenv('MYSQL_HOST', true), + 'database' => getenv('MYSQL_DATABASE', true), + 'username' => getenv('MYSQL_USER', true), + 'password' => getenv('MYSQL_PASSWORD', true) +]; diff --git a/lib/config.template.php b/lib/config.template.php index 84d048f..8865a58 100644 --- a/lib/config.template.php +++ b/lib/config.template.php @@ -1,4 +1,5 @@