diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..81bbe84 --- /dev/null +++ b/.env.sample @@ -0,0 +1,28 @@ +# 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" + +# 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 +MYSQL_RANDOM_ROOT_PASSWORD=yes diff --git a/.gitignore b/.gitignore index 55ae295..7092144 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ vendor/ lib/config.php logs/ pgp/data/ +data/ +.env 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..ca60169 --- /dev/null +++ b/lib/config.docker.php @@ -0,0 +1,55 @@ + '', + 'domain' => '', + 'from' => '' + ]; + + public static $pgpVerificationAPI = ''; + public static $redisAPI = ''; + + public static $db = [ + '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 ad4ab91..8865a58 100644 --- a/lib/config.template.php +++ b/lib/config.template.php @@ -1,4 +1,5 @@ '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] +