Skip to content

Commit

Permalink
Fix sqlite db folder for container
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGillam committed Aug 11, 2024
1 parent 270b4dc commit ee240bc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .shogun/Dockerfile.dojo-basic-lite
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ RUN apt-get update && apt-get install -y \
# Set the environment variable for database type
ENV DOJO_DB_TYPE=sqlite

# Create the db directory and set permissions
RUN mkdir -p /var/www/html/db && \
chmod 755 /var/www/html/db

COPY ./src/basic /var/www/html

# Run reset-db.php script
RUN php /var/www/html/reset-db.php

LABEL org.opencontainers.image.source=https://github.com/SamuraiWTF/samurai-dojo
LABEL org.opencontainers.image.description="Basic PHP 7.4.27-apache-bullseye image with dojo-basic with sqlite support."
LABEL org.opencontainers.image.licenses="lgpl"
3 changes: 2 additions & 1 deletion src/basic/opendb.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

function db_connect() {
global $db_type, $dbhost, $dbuser, $dbpass, $dbname;
$db_file = '/var/www/html/db/' . $dbname . '.sqlite';

if ($db_type === 'mysql') {
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
} else {
$conn = new SQLite3('/var/www/html/db/' . $dbname . '.sqlite');
$conn = new SQLite3($db_file);
}

return $conn;
Expand Down
1 change: 1 addition & 0 deletions src/basic/reset-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function execute_query($conn, $query) {
$conn->select_db($dbname);
} else {
echo("<br>Setting up SQLite...");

$db_file = '/var/www/html/db/' . $dbname . '.sqlite';

// Delete the existing database file if it exists
Expand Down

0 comments on commit ee240bc

Please sign in to comment.