Skip to content
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

POC: Docker files in local directory #980

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
APP_NAME=Cypht

# DB_CONNECTION_TYPE=host
# DB_DRIVER=mysql
# DB_PORT=
# DB_HOST=localhost
# DB_NAME=test
# DB_USER=test
# DB_PASS=123456
# DB_SOCKET=/var/lib/mysqld/mysqld.sock

# AUTH_USERNAME=admin
# AUTH_PASSWORD=admin_password
DB_CONNECTION_TYPE=host
DB_HOST=db
DB_NAME=cypht
DB_USER=cypht
DB_PASS=cypht_password
SESSION_TYPE=db
DB_DRIVER=mysql
DB_PORT=
DB_HOST=localhost
DB_NAME=test
DB_USER=test
DB_PASS=123456
DB_SOCKET=/var/lib/mysqld/mysqld.sock

SESSION_TYPE=PHP
AUTH_TYPE=DB
Expand Down
34 changes: 34 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: '3'
services:
db:
image: mariadb:10
ports:
- "3306:3306"
volumes:
- ./db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=root_password
- MYSQL_DATABASE=cypht
- MYSQL_USER=cypht
- MYSQL_PASSWORD=cypht_password
cypht:
# image: sailfrog/cypht-docker:latest
build:
context: .
dockerfile: ./docker/Dockerfile
volumes:
- ./cypht/users:/var/lib/hm3/users
# TODO: add health check here
ports:
- "80:80"
environment:
- CYPHT_AUTH_USERNAME=admin
- CYPHT_AUTH_PASSWORD=admin_password
- CYPHT_DB_CONNECTION_TYPE=host
- CYPHT_DB_HOST=db
- CYPHT_DB_NAME=cypht
- CYPHT_DB_USER=cypht
- CYPHT_DB_PASS=cypht_password
- CYPHT_SESSION_TYPE=db

# TODO: add memcache and redis to this sample
67 changes: 67 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
FROM php:7.4.33-fpm-alpine

# ENV CYPHT_DEST "/usr/local/share/cypht"

# WORKDIR "/var/www"

# TODO: change this to /app for simplification
WORKDIR "/usr/local/share/cypht"

RUN set -e \
&& apk add --no-cache \
supervisor \
nginx \
composer \
# GD
freetype libpng libjpeg-turbo \
php-session php-fileinfo php-dom php-xml libxml2-dev php-xmlwriter php-tokenizer \
&& apk add --no-cache --virtual .build-deps \
ca-certificates \
# wget \
# unzip \
# For GD (2fa module)
libpng-dev libjpeg-turbo-dev freetype-dev \
&& docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \
&& docker-php-ext-install gd pdo pdo_mysql \
# && mkdir ${CYPHT_DEST} \
# && cd ${CYPHT_DEST} \
# && mkdir /tmp/cypht-temp \
# && cd /tmp/cypht-temp \
# && wget https:/cypht-org/cypht/archive/master.zip \
# && unzip master.zip \
# && cp cypht-master/hm3.sample.ini cypht-master/hm3.ini \
# && find . -type d -print | xargs chmod 755 \
# && find . -type f -print | xargs chmod 644 \
# && chown -R root:root cypht-master \
# && mv cypht-master/* ${CYPHT_DEST} \
# && cd /tmp \
# && rm -rf cypht-temp \
# && apk del .build-deps \
# && cd ${CYPHT_DEST} \
# && composer update \
# && composer self-update --2 \
# && composer install \
&& echo "post_max_size = 60M" >> /usr/local/etc/php/php.ini \
&& echo "upload_max_filesize = 50M" >> /usr/local/etc/php/php.ini

COPY docker/nginx.conf /etc/nginx/nginx.conf
COPY docker/supervisord.conf /etc/supervisord.conf
# COPY docker/docker-entrypoint.sh /usr/local/bin/
# COPY docker/cypht_setup_database.php /tmp/cypht_setup_database.php

RUN set -ex \
&& ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log
# && chmod 700 docker/cypht_setup_database.php
# && chmod +x /usr/local/bin/docker-entrypoint.sh

COPY composer.* .

RUN composer update && composer install

COPY . .
COPY .env.example .env

EXPOSE 80 443

ENTRYPOINT ["docker/docker-entrypoint.sh"]
53 changes: 53 additions & 0 deletions docker/cypht_setup_database.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

// TODO: this file should probably start with something like #!/usr/bin/env php

$connected = false;
$session_type = CYPHT_SESSION_TYPE;
$auth_type = CYPHT_AUTH_TYPE;
$user_config_type = CYPHT_USER_CONFIG_TYPE;
$db_driver = CYPHT_DB_DRIVER;

// TODO: move this into the scripts/ dir. its not docker specific

while(!$connected) {
try{
$conn = new pdo('CYPHT_DB_DRIVER:host=CYPHT_DB_HOST;dbname=CYPHT_DB_NAME', 'CYPHT_DB_USER', 'CYPHT_DB_PASS');
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
printf("Database connection successful ...\n");
$connected = true;
} catch(PDOException $e){
error_log('Waiting for database connection ... (' . $e->getMessage() . ')');
sleep(1);
}
}
if ($session_type == 'DB') {
if ($db_driver == 'mysql') {
$stmt = "CREATE TABLE IF NOT EXISTS hm_user_session (hm_id varchar(250), data longblob, date timestamp, primary key (hm_id));";
} elseif ($db_driver == 'pgsql') {
$stmt = "CREATE TABLE IF NOT EXISTS hm_user_session (hm_id varchar(250) primary key not null, data text, date timestamp);";
}
// TODO: sqlite command
printf("Creating database table hm_user_session ...\n");
$conn->exec($stmt);
}
if ($auth_type == 'DB') {
if ($db_driver == 'mysql') {
$stmt = "CREATE TABLE IF NOT EXISTS hm_user (username varchar(250), hash varchar(250), primary key (username));";
} elseif ($db_driver == 'pgsql') {
$stmt = "CREATE TABLE IF NOT EXISTS hm_user (username varchar(255) primary key not null, hash varchar(255));";
}
// TODO: sqlite command
printf("Creating database table hm_user ...\n");
$conn->exec($stmt);
}
if ($user_config_type == 'DB') {
if ($db_driver == 'mysql') {
$stmt = "CREATE TABLE IF NOT EXISTS hm_user_settings(username varchar(250), settings longblob, primary key (username));";
} elseif ($db_driver == 'pgsql') {
$stmt = "CREATE TABLE IF NOT EXISTS hm_user_settings (username varchar(250) primary key not null, settings text);";
}
// TODO: sqlite command
printf("Creating database table hm_user_settings ...\n");
$conn->exec($stmt);
}
Loading