Merge pull request 'Migrate to Alpine' (#5) from development into master
All checks were successful
/ docker (push) Successful in 29s
All checks were successful
/ docker (push) Successful in 29s
Reviewed-on: #5
This commit is contained in:
commit
f3febd737d
14
Dockerfile
14
Dockerfile
@ -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,18 +1,29 @@
|
|||||||
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"
|
||||||
if [ -f "/var/www/html/upload.php" ]; then
|
if [ -f "/var/www/html/upload.php" ]; then
|
||||||
echo "Upload script was found, ignoring copy."
|
echo "Upload script was found, ignoring copy."
|
||||||
else
|
else
|
||||||
cp /tmp/upload.php /var/www/html
|
cp /tmp/upload.php /var/www/html
|
||||||
echo "Upload script was not found, copying it."
|
echo "Upload script was not found, copying it."
|
||||||
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;'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
25
upload.php
25
upload.php
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user