Compare commits

4 Commits

3 changed files with 118 additions and 78 deletions

View File

@@ -7,21 +7,33 @@ A program to take notes during a sermon. The web app was built with PHP and Sym
This was my first publicly available docker container so I did not realize what some decisions would do. If you are upgrading from v1 you first need to save your database OR you will lose all your current notes!! Follow the steps below to do that
1. You need to make sure that you have a running SSH server on your host computer
2. On your host computer, `docker exec -it sermon-notes bash`
3. `cd var/`
4. `scp data.db {user}@{host computer IP}:{path}`
2. Make a directory in your `sermon-notes` folder for your database (e.g. `data`)
3. On your host computer, `docker exec -it sermon-notes bash`
4. `scp .env {user}@{IP}:{path}`
5. Authenticate with the password
6. This will copy the file over SFTP to the host computer
7. After this then you run the `docker run...` command in Step 1 of the `Installation` instructions below, once the container is running you need to copy the `data.db` file into the working directory of the docker container.
- For example, if you have `~/docker/sermon-notes` as the path for the container on the host computer, you'll copy the `data.db` to `~/docker/sermon-notes/data`
6. `cd var/`
7. `scp data.db {user}@{IP}:{path}/data`
8. This will copy the file to the host computer
9. After this then you run the `docker run...` command in Step 3 of the `Installation` instructions below
## Installation
1. Make a directory in your desired docker storage folder (e.g. `~/docker/sermon-notes`), then `cd` into it.
2. Create a file called `.env` in that folder, no need to add anything to it right now.
3. Run `docker run -d --name sermon-notes -p 80:80 -v $PWD/data:/data -v $PWD/.env:/var/www/html/.env gitea.rkprather.com/ryan/sermon-notes:latest`, this will download and start the container and keep it running in the background. If you already have something on port 80 change the first `80` to whatever open port you'd like.
4. Run `docker exec -it sermon-notes bash install.sh` This will run an install script to create an .env file specific to your install, populate with the beginning factors, and then run a `composer` command to download the necessary package dependancies.
5. Once complete you have a running system that you can navigate to in your browser with `http://{ip}:{port}`|`http://{hostname}:{port}`. Then you just need to register for an account. The first account that is created is made an admin so that you can access the `Reference Editor` and update any reference material if necessary.
3. Download your preferred compose file (`wget -O compose.yml {link}`)
1. [`compose.sqlite.yml`](https://gitea.rkprather.com/ryan/sermon-notes/raw/branch/main/docker/compose.sqlite.yml) - compose file for if you are planning to use SQLite
2. [`compose.mysql.yml`](https://gitea.rkprather.com/ryan/sermon-notes/raw/branch/main/docker/compose.mysql.yml) - compose file with an integrated MYSQL database image
3. [`compose.mariadb.yml`](https://gitea.rkprather.com/ryan/sermon-notes/raw/branch/main/docker/compose.mariadb.yml) - compose file with an integrate MariaDB database image
4. [`compose.pgsql.yml`](https://gitea.rkprather.com/ryan/sermon-notes/raw/branch/main/docker/compose.pgsql.yml) - compose file with an integrate Postgres database image
5. [`compose.shared-db.yml`](https://gitea.rkprather.com/ryan/sermon-notes/raw/branch/main/docker/compose.shared-db.yml) - compose file with no database image because you are planning on using an existing database container or bare metal server
4. Pull the image `docker pull gitea.rkprather.com/ryan/sermon-notes:latest`
5. **NOTE: IF UPGRADING SKIP THIS STEP!!!** - Run the setup script, this will setup your .env file so that when you start the container everything will be where it is supposed to be.
- `docker run --rm -it -v ${PWD}/.env:/var/www/html/.env gitea.rkprather.com/ryan/sermon-notes:latest /var/www/html/setup.php --{database-type} {--shared}`
- `{database-type}` = `sqlite`, `mysql`, `mariadb`, or `pgsql`
- If you intend on this being connected to a shared database make sure that you specify `--shared`.
6. Start the container with compose `docker compose up -d`
7. **NOTE: IF UPGRADING SKIP THIS STEP!!!** Run `docker exec -it sermon-notes /var/www/html/install.php`. This will run the `php composer` to populate the database with all the desired reference material.
8. Once complete you have a running system that you can navigate to in your browser with `http://{ip}:{port}`|`http://{hostname}:{port}`. Then you just need to register for an account. The first account that is created is made an admin so that you can access the `Reference Editor` and update any reference material if necessary.
## Operation

View File

@@ -2,83 +2,17 @@
<?php
if (!file_exists('/var/www/html/.env')) {
die;
}
$cmd = getopt("", ["sqlite", "mysql", "mariadb", "pgsql"]);
$key = `openssl rand -base64 32 | tr -d '=' | tr -d '+' | tr -d '/' | tr -d ' '`;
$key = substr($key, 0, 32);
$database_url = null;
$getCreds = true;
$creds = null;
if (isset($cmd['sqlite'])) {
$database_url = "DATABASE_URL=\"sqlite:////data/data.db\"";
$getCreds = false;
} elseif (isset($cmd['mysql'])) {
$database_url = "DATABASE_URL=\"mysql://\${DB_USER}:\${DB_PASS}@\${DB_HOST}:\${DB_PORT}/\${DB_NAME}?charset=utf8&use_unicode=1\"";
} elseif (isset($cmd['mariadb'])) {
$database_url = "DATABASE_URL=\"mysql://\${DB_USER}:\${DB_PASS}@\${DB_HOST}:\${DB_PORT}/\${DB_NAME}?charset=utf8mb4\"";
} elseif (isset($cmd['pgsql'])) {
$database_url = "DATABASE_URL=\"postgresql://\${DB_USER}:\${DB_PASS}@\${DB_HOST}:\${DB_PORT}/\${DB_NAME}?sslmode=require\"";
}
if (is_null($database_url)) {
$getCreds = false;
die("When calling this make sure that you enter a database type");
}
if ($getCreds) {
$db_host = readline("DB Host: ");
$db_port = readline("DB Port: ");
$db_name = readline("DB Schema: ");
$db_user = readline("DB User: ");
print "DB Password: ";
// Disable echoing of input characters
system('stty -echo');
// Read the password from standard input
$db_password = trim(fgets(STDIN));
// Re-enable echoing of input characters
system('stty echo');
$creds = <<<CREDS
DB_HOST=$db_host
DB_PORT=$db_port
DB_NAME=$db_name
DB_USER=$db_user
DB_PASS=$db_password
CREDS;
}
$output = <<<EOF
APP_ENV=prod
APP_DEBUG=0
APP_SECRET=$key
MESSAGENER_TRANSPORT_DSN=doctrine://default?auto_setup=0
$creds$database_url
EOF;
file_put_contents('/var/www/html/.env', $output);
print "Updating packages and compiling assets".PHP_EOL;
`COMPOSE_ALLOW_SUPERUSER=1 composer update`;
`symfony console asset-map:compile`;
if ($getCreds) {
print "Creating database schema".PHP_EOL;
`symfony console doctrine:database:create`;
}
print "Creating database schema".PHP_EOL;
`symfony console doctrine:database:create`;
print "Updating migrations and setting permissions for data folder".PHP_EOL;
`symfony console doctrine:migrations:migrate --no-interaction`;
if (isset($cmd['sqlite'])) {
`chown -R www-data:www-data /data`;
}
`chown -R www-data:www-data /data`;
// import reference material

94
setup.php Executable file
View File

@@ -0,0 +1,94 @@
#!/usr/local/bin/php
<?php
if (!file_exists('/var/www/html/.env')) {
die;
}
$cmd = getopt("", ["sqlite", "mysql", "mariadb", "pgsql", "shared"]);
$key = `openssl rand -base64 32 | tr -d '=' | tr -d '+' | tr -d '/' | tr -d ' '`;
$key = substr($key, 0, 32);
$database_url = null;
$getCreds = true;
$creds = null;
$http_port = readline("What port do you want the server to listen on (80)? ");
$http_port = (empty($http_port) ? 80 : $http_port);
if (isset($cmd['sqlite'])) {
$database_url = "DATABASE_URL=\"sqlite:////data/data.db\"";
$getCreds = false;
} elseif (isset($cmd['mysql'])) {
$database_url = "DATABASE_URL=\"mysql://\${DB_USER}:\${DB_PASS}@\${DB_HOST}:\${DB_PORT}/\${DB_NAME}?charset=utf8&use_unicode=1\"";
} elseif (isset($cmd['mariadb'])) {
$database_url = "DATABASE_URL=\"mysql://\${DB_USER}:\${DB_PASS}@\${DB_HOST}:\${DB_PORT}/\${DB_NAME}?charset=utf8mb4\"";
} elseif (isset($cmd['pgsql'])) {
$database_url = "DATABASE_URL=\"postgresql://\${DB_USER}:\${DB_PASS}@\${DB_HOST}:\${DB_PORT}/\${DB_NAME}?sslmode=require\"";
}
if (is_null($database_url)) {
$getCreds = false;
die("When calling this make sure that you enter a database type");
}
if ($getCreds) {
$dbInfo = null;
if (isset($cmd['shared'])) {
$db_host = readline("DB Host: ");
$db_port = readline("DB Port: ");
$db_name = readline("DB Schema: ");
$db_user = readline("DB User: ");
print "DB Password: ";
// Disable echoing of input characters
system('stty -echo');
// Read the password from standard input
$db_password = trim(fgets(STDIN));
// Re-enable echoing of input characters
system('stty echo');
} else {
$db_host = 'db';
$db_port = (isset($cmd['pgsql']) ? 5432 : 3306);
$db_name = 'sermon_notes';
$db_user = 'root';
$pwd = `openssl rand -base64 32 | tr -d '=' | tr -d '+' | tr -d '/' | tr -d ' '`;
$db_password = substr($pwd, 0, 32);
if (isset($cmd['pgsql'])) {
$dbInfo = <<<INFO
POSTGRES_USER=$db_user
POSTGRES_PASSWORD=$db_password
INFO;
} elseif (isset($cmd['mysql']) || isset($cmd['mariadb'])) {
$dbInfo = <<<INFO
MYSQL_ROOT_PASSWORD=$db_password
INFO;
}
}
$creds = <<<CREDS
DB_HOST=$db_host
DB_PORT=$db_port
DB_NAME=$db_name
DB_USER=$db_user
DB_PASS=$db_password
$dbInfo
CREDS;
}
$output = <<<EOF
APP_ENV=prod
APP_DEBUG=0
APP_SECRET=$key
MESSAGENER_TRANSPORT_DSN=doctrine://default?auto_setup=0
HTTP_PORT=$http_port
$creds$database_url
EOF;
file_put_contents('/var/www/html/.env', $output);