Compare commits

..

22 Commits

Author SHA1 Message Date
Lee
f3febd737d Merge pull request 'Migrate to Alpine' (#5) from development into master
All checks were successful
/ docker (push) Successful in 29s
Reviewed-on: #5
2023-07-07 23:54:10 +00:00
d6f346200a revert to not using Imagick
All checks were successful
/ docker (push) Successful in 29s
2023-07-08 00:51:33 +01:00
9109639908 please work I am begging you
All checks were successful
/ docker (push) Successful in 44s
2023-07-08 00:48:05 +01:00
0f9c6789bf i asked john, no idea what was changed
Some checks failed
/ docker (push) Failing after 23s
2023-07-08 00:47:22 +01:00
1213a7a4a0 part 4
Some checks failed
/ docker (push) Failing after 23s
2023-07-08 00:45:23 +01:00
34627788c6 part 3
Some checks failed
/ docker (push) Failing after 22s
2023-07-08 00:43:41 +01:00
2ce6d071b6 part 2
Some checks failed
/ docker (push) Failing after 23s
2023-07-08 00:42:40 +01:00
e47372cdc4 re-add imagick
Some checks failed
/ docker (push) Failing after 21s
2023-07-08 00:41:26 +01:00
6c1de0446b set socket perms
All checks were successful
/ docker (push) Successful in 27s
2023-07-08 00:35:47 +01:00
725f655fd9 show fallback msg
All checks were successful
/ docker (push) Successful in 26s
2023-07-08 00:34:15 +01:00
75e5f47d84 pls work - create php dir for socket
Some checks failed
/ docker (push) Failing after 22s
2023-07-08 00:32:46 +01:00
1ac3a21776 maybe this will fix it? who knows
All checks were successful
/ docker (push) Successful in 27s
2023-07-08 00:30:33 +01:00
50da4c5052 chatgpt is silly, but I am more silly
All checks were successful
/ docker (push) Successful in 27s
2023-07-08 00:28:33 +01:00
cf5dd64b46 this isn't a Dockerfile skull
All checks were successful
/ docker (push) Successful in 26s
2023-07-08 00:27:01 +01:00
ade90e81e9 make php use a sock
All checks were successful
/ docker (push) Successful in 26s
2023-07-08 00:24:42 +01:00
cf219a418e fix php not loading?
All checks were successful
/ docker (push) Successful in 27s
2023-07-08 00:19:15 +01:00
f756361521 no idea if this will work
All checks were successful
/ docker (push) Successful in 28s
2023-07-08 00:18:05 +01:00
bcb0a5d61a start work on making init script work
All checks were successful
/ docker (push) Successful in 27s
2023-07-08 00:16:13 +01:00
14ca6a6ba3 pin php version
All checks were successful
/ docker (push) Successful in 30s
2023-07-08 00:14:05 +01:00
99ca7597f4 attempt 3
Some checks failed
/ docker (push) Failing after 24s
2023-07-08 00:11:43 +01:00
f8a23c19ba attempt 2
Some checks failed
/ docker (push) Failing after 21s
2023-07-08 00:10:16 +01:00
911038f6fc attempt 1 of moving to alpine
Some checks failed
/ docker (push) Failing after 22s
2023-07-08 00:08:36 +01:00
4 changed files with 33 additions and 39 deletions

@ -1,12 +1,10 @@
FROM ubuntu:23.04 FROM alpine:3.18.2
# Install dependencies # Install dependencies
RUN apt update RUN apk update && \
RUN DEBIAN_FRONTEND=noninteractive \ apk upgrade && \
apt install nginx php8.1 php8.1-fpm php8.1-gd php8.1-imagick -y apk add --no-cache nginx php81 php81-fpm php81-gd && \
rm -rf /var/cache/apk/*
# Clean up
RUN apt clean
# Set up nginx # Set up nginx
COPY ./docker/nginx.conf /etc/nginx/nginx.conf COPY ./docker/nginx.conf /etc/nginx/nginx.conf
@ -16,4 +14,4 @@ COPY ./upload.php /tmp/upload.php
COPY ./docker/start.sh /start.sh COPY ./docker/start.sh /start.sh
# Start server # Start server
CMD ["bash", "/start.sh"] CMD ["sh", "/start.sh"]

@ -44,7 +44,7 @@ http {
try_files $uri =404; try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php8.1-fpm.sock; fastcgi_pass unix:/run/php/php.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php; fastcgi_index index.php;

@ -1,5 +1,9 @@
if [[ -z "${MAX_UPLOAD_SIZE}" ]]; then #!/bin/sh
# TODO: add all the other fallback values for the other variables
if [ -z "$MAX_UPLOAD_SIZE" ]; then
MAX_UPLOAD_SIZE="8M" # Default fallback value MAX_UPLOAD_SIZE="8M" # Default fallback value
echo "MAX_UPLOAD_SIZE was not set, using default value of ${MAX_UPLOAD_SIZE}"
fi fi
echo "Checking if upload script exists in /var/www/html" echo "Checking if upload script exists in /var/www/html"
@ -11,8 +15,15 @@ else
fi fi
# Letting php know that we are running in docker # Letting php know that we are running in docker
echo "env[DOCKER] = true" >> /etc/php/8.1/fpm/pool.d/www.conf echo "env[DOCKER] = true" >> /etc/php81/php-fpm.d/www.conf
echo "clear_env = no" >> /etc/php/8.1/fpm/pool.d/www.conf echo "clear_env = no" >> /etc/php81/php-fpm.d/www.conf
# Create the directory for PHP socket
mkdir -p /run/php
# Set php-fpm to listen on socket
touch /run/php/php.sock
sed -i 's/^listen = .*/listen = \/run\/php\/php.sock/' /etc/php81/php-fpm.d/www.conf
echo "Setting permissions for upload script" echo "Setting permissions for upload script"
chmod 777 /var/www/html/upload.php chmod 777 /var/www/html/upload.php
@ -20,16 +31,16 @@ chmod 777 /var/www/html/upload.php
echo "Setting max upload size to ${MAX_UPLOAD_SIZE}" echo "Setting max upload size to ${MAX_UPLOAD_SIZE}"
# Set max upload size for php # Set max upload size for php
sed -i "s/^upload_max_filesize = .*/upload_max_filesize = ${MAX_UPLOAD_SIZE}/" /etc/php/8.1/fpm/php.ini sed -i "s/^upload_max_filesize = .*/upload_max_filesize = ${MAX_UPLOAD_SIZE}/" /etc/php81/php.ini
sed -i "s/^post_max_size = .*/post_max_size = ${MAX_UPLOAD_SIZE}/" /etc/php/8.1/fpm/php.ini sed -i "s/^post_max_size = .*/post_max_size = ${MAX_UPLOAD_SIZE}/" /etc/php81/php.ini
# Set max upload size for nginx # Set max upload size for nginx
sed -i "s/client_max_body_size 500M;/client_max_body_size ${MAX_UPLOAD_SIZE};/" /etc/nginx/nginx.conf sed -i "s/client_max_body_size 500M;/client_max_body_size ${MAX_UPLOAD_SIZE};/" /etc/nginx/nginx.conf
function start() { function start() {
echo "Starting PHP & Nginx" echo "Starting PHP & Nginx"
/etc/init.d/php8.1-fpm start && php-fpm81 &&
chmod 777 /run/php/php8.1-fpm.sock && chmod 777 /run/php/php.sock &&
nginx -g 'daemon off;' nginx -g 'daemon off;'
} }

@ -162,28 +162,13 @@ try {
// Check the file type and size // Check the file type and size
if ($shouldConvertToWebp && in_array($fileType, ["png", "jpeg", "jpg"]) && $_FILES["sharex"]["size"] > $webpThreadhold) { if ($shouldConvertToWebp && in_array($fileType, ["png", "jpeg", "jpg"]) && $_FILES["sharex"]["size"] > $webpThreadhold) {
// Create an Imagick object from the uploaded file $image = imagecreatefromstring(file_get_contents($_FILES["sharex"]["tmp_name"]));
$image = new Imagick($_FILES["sharex"]["tmp_name"]);
// Convert the image to WebP
$image->setImageFormat("webp");
$image->setImageCompressionQuality($webpQuality);
// Set the output filename
$webp_file = pathinfo($finalName, PATHINFO_FILENAME) . ".webp"; $webp_file = pathinfo($finalName, PATHINFO_FILENAME) . ".webp";
imagewebp($image, $webp_file, 90); // Convert the image and save it
// Save the converted image imagedestroy($image); // Free up memory
$image->writeImage($webp_file);
// Free up memory
$image->clear();
$image->destroy();
$fileSize = filesize($webp_file); // Update the file size
// Update the final filename
$finalName = $webp_file; $finalName = $webp_file;
$needsToBeSaved = false; $shouldSave = false;
$fileSize = filesize($webp_file); // Update the file size
} }
if ($needsToBeSaved) { // Save the file if it has not been saved yet if ($needsToBeSaved) { // Save the file if it has not been saved yet