Skip to content

Commit 1bcd95f

Browse files
committed
migrate to shinsenter/php
1 parent 4c6df0d commit 1bcd95f

File tree

7 files changed

+47
-267
lines changed

7 files changed

+47
-267
lines changed

Dockerfile

Lines changed: 31 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,36 @@
1-
FROM php:8.3-fpm AS base
2-
3-
RUN apt-get update && apt-get install -y \
4-
nginx \
5-
nano \
6-
procps \
7-
psmisc \
8-
git \
9-
htop \
10-
nano \
11-
cron \
12-
openssl \
13-
libonig-dev \
14-
libxml2-dev \
15-
libssl-dev \
16-
libpng-dev \
17-
libjpeg-dev \
18-
libfreetype6-dev \
19-
libgmp-dev \
20-
libzip-dev \
21-
&& docker-php-ext-configure gd --with-jpeg --with-freetype \
22-
&& docker-php-ext-install mysqli pdo_mysql sockets gd zip gmp bcmath \
23-
&& apt-get clean && rm -rf /var/lib/apt/lists/*
24-
25-
FROM base AS builder
26-
27-
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
28-
29-
COPY app/ /app/
30-
31-
WORKDIR /app
32-
33-
RUN composer config platform.php-64bit 8.3
34-
RUN composer install --no-interaction --optimize-autoloader
35-
36-
FROM base
37-
38-
COPY --from=builder /usr/local/bin/composer /usr/local/bin/composer
39-
COPY --from=builder /app /app
40-
41-
COPY default.conf /etc/nginx/sites-available/default
42-
COPY setup/ /setup/
1+
FROM shinsenter/php:8.3-fpm-nginx
2+
3+
# Default application envs
4+
ENV ENABLE_CRONTAB=1
5+
ENV APP_PATH=/app
6+
ENV DOCUMENT_ROOT=public
7+
ENV TZ=UTC
438

44-
COPY docker-entrypoint.sh /usr/local/bin/
45-
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
9+
# Copy application files
10+
COPY app/ ${APP_PATH}/
11+
WORKDIR ${APP_PATH}
4612

47-
RUN chown -R www-data:www-data /app \
48-
&& chmod -R 755 /app
13+
# Install composer dependencies
14+
RUN composer config platform.php-64bit 8.3 && \
15+
composer install --no-interaction --optimize-autoloader --no-dev
4916

50-
ENV TZ=UTC
17+
# Create autorun scripts
18+
COPY setup/ /setup/
19+
RUN mkdir -p /startup && \
20+
ln -sf /setup/start.php /startup/20-migrations.php
21+
22+
# Copy cron jobs configuration
23+
COPY crontab /etc/cron.d/lerama-cron
24+
RUN chmod 0644 /etc/cron.d/lerama-cron
25+
26+
# Copy setup script
27+
COPY docker-entrypoint.sh /startup/10-setup-env.sh
28+
RUN chmod +x /startup/10-setup-env.sh
5129

52-
EXPOSE 8077
30+
# Set permissions
31+
RUN chown -R www-data:www-data ${APP_PATH} && \
32+
chmod -R 755 ${APP_PATH} && \
33+
mkdir -p ${APP_PATH}/${DOCUMENT_ROOT}/storage/thumbnails && \
34+
chown -R www-data:www-data ${APP_PATH}/${DOCUMENT_ROOT}/storage
5335

54-
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
36+
EXPOSE 80

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Configure pelo menos:
4040
docker-compose up -d
4141
```
4242

43-
4. Acesse: `http://localhost:8077`
43+
4. Acesse: `http://localhost:80`
4444

4545
## 🎯 CLI
4646

crontab

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Process feeds every hour
2+
0 * * * * /usr/local/bin/php /app/bin/lerama feed:process 2>&1
3+
4+
# Check feed status every hour at :30
5+
30 * * * * /usr/local/bin/php /app/bin/lerama feed:check-status 2>&1
6+
7+
# Update proxy list daily at midnight
8+
0 0 * * * /usr/local/bin/php /app/bin/lerama proxy:update 2>&1

default.conf

Lines changed: 0 additions & 53 deletions
This file was deleted.

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ services:
2222
SMTP_FROM_EMAIL: [email protected]
2323
SMTP_FROM_NAME: Lerama
2424
ports:
25-
- 8077:8077
25+
- 80:80
2626
volumes:
2727
- ./lerama/storage:/app/public/storage
2828
restart: unless-stopped

docker-entrypoint.sh

Lines changed: 5 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22
set -e
33

4+
# Colors for output
45
RED='\033[0;31m'
56
GREEN='\033[0;32m'
67
YELLOW='\033[1;33m'
@@ -10,74 +11,11 @@ log_success() {
1011
echo -e "${GREEN}[✓] $1${NC}"
1112
}
1213

13-
log_error() {
14-
echo -e "${RED}[✗] $1${NC}"
15-
exit 1
16-
}
17-
1814
log_info() {
1915
echo -e "${YELLOW}[i] $1${NC}"
2016
}
2117

22-
check_nginx() {
23-
log_info "Checking Nginx process status..."
24-
local max_attempts=5
25-
local attempt=0
26-
27-
while [ $attempt -lt $max_attempts ]; do
28-
if pgrep nginx > /dev/null; then
29-
log_success "Nginx started successfully"
30-
return 0
31-
fi
32-
33-
log_info "Waiting for Nginx to start... (Attempt $((attempt+1))/$max_attempts)"
34-
sleep 3
35-
attempt=$((attempt+1))
36-
done
37-
38-
log_error "Failed to start Nginx after $max_attempts attempts"
39-
}
40-
41-
check_php_fpm() {
42-
log_info "Checking PHP-FPM process status..."
43-
local max_attempts=5
44-
local attempt=0
45-
46-
while [ $attempt -lt $max_attempts ]; do
47-
if pgrep php-fpm > /dev/null; then
48-
log_success "PHP-FPM started successfully"
49-
return 0
50-
fi
51-
52-
log_info "Waiting for PHP-FPM to start... (Attempt $((attempt+1))/$max_attempts)"
53-
sleep 3
54-
attempt=$((attempt+1))
55-
done
56-
57-
log_error "Failed to start PHP-FPM after $max_attempts attempts"
58-
}
59-
60-
echo -e "\n${YELLOW}Lerama: Starting${NC}\n"
61-
62-
# Set timezone
63-
if [ -n "$TZ" ]; then
64-
log_info "Setting timezone to $TZ..."
65-
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime
66-
echo $TZ > /etc/timezone
67-
68-
echo "date.timezone = $TZ" > /usr/local/etc/php/conf.d/timezone.ini
69-
log_success "Timezone set to $TZ for both system and PHP"
70-
else
71-
log_info "No TZ environment variable set, using UTC as default timezone"
72-
73-
ln -snf /usr/share/zoneinfo/UTC /etc/localtime
74-
echo "UTC" > /etc/timezone
75-
76-
echo "date.timezone = UTC" > /usr/local/etc/php/conf.d/timezone.ini
77-
log_success "Timezone set to UTC for both system and PHP"
78-
fi
79-
80-
# Create or update .env file with environment variables
18+
# Create .env file with environment variables
8119
log_info "Setting up environment variables in /app/.env..."
8220
cat > /app/.env << EOL
8321
APP_NAME=Lerama
@@ -102,102 +40,7 @@ EOL
10240

10341
log_success "Environment variables set in /app/.env"
10442

105-
log_info "Starting PHP-FPM..."
106-
php-fpm &
107-
check_php_fpm
108-
109-
# Ensure /app/storage directory exists and has correct permissions
110-
log_info "Checking /app/public/storage directory..."
111-
if [ ! -d /app/public/storage ]; then
112-
log_info "Creating /app/public/storage directory..."
113-
mkdir -p /app/public/storage
114-
log_success "/app/public/storage directory created"
115-
fi
116-
117-
# Database
118-
log_info "Checking database tables..."
119-
php /setup/check-db.php
120-
121-
# NGINX
122-
log_info "Checking Nginx configuration..."
123-
nginx -t
124-
if [ $? -ne 0 ]; then
125-
log_error "Invalid Nginx configuration"
126-
else
127-
log_success "Valid Nginx configuration"
128-
fi
129-
130-
log_info "Starting Nginx..."
131-
nginx -g "daemon off;" &
132-
check_nginx
133-
134-
# Cron
135-
log_info "Setting up cron jobs..."
136-
137-
# Create a directory for cron scripts
138-
mkdir -p /app/cron-scripts
139-
chmod 755 /app/cron-scripts
140-
141-
cat > /app/cron-scripts/feed_process.sh << 'EOL'
142-
#!/bin/bash
143-
echo "$(date): Starting feed:process cron job"
144-
/usr/local/bin/php /app/bin/lerama feed:process 2>&1 | sed "s/^/[feed:process] /"
145-
echo "$(date): Finished feed:process cron job"
146-
EOL
147-
148-
cat > /app/cron-scripts/feed_check_status.sh << 'EOL'
149-
#!/bin/bash
150-
echo "$(date): Starting feed:check-status cron job"
151-
/usr/local/bin/php /app/bin/lerama feed:check-status 2>&1 | sed "s/^/[feed:check-status] /"
152-
echo "$(date): Finished feed:check-status cron job"
153-
EOL
154-
155-
cat > /app/cron-scripts/proxy_update.sh << 'EOL'
156-
#!/bin/bash
157-
echo "$(date): Starting proxy_update cron job"
158-
/usr/local/bin/php /app/bin/lerama proxy:update 2>&1 | sed "s/^/[proxy:update] /"
159-
echo "$(date): Finished proxy_update cron job"
160-
EOL
161-
162-
# Make the scripts executable
163-
chmod +x /app/cron-scripts/*.sh
164-
165-
# Set up crontab to use the wrapper scripts and redirect output to Docker logs
166-
(
167-
echo "0 * * * * /app/cron-scripts/feed_process.sh >> /proc/1/fd/1 2>> /proc/1/fd/2"
168-
echo "30 * * * * /app/cron-scripts/feed_check_status.sh >> /proc/1/fd/1 2>> /proc/1/fd/2"
169-
echo "0 0 * * * /app/cron-scripts/proxy_update.sh >> /proc/1/fd/1 2>> /proc/1/fd/2"
170-
) | crontab -
171-
172-
service cron restart
173-
174-
log_success "Cron jobs added with stdout logging"
175-
176-
# Update proxy list if PROXY_LIST is defined
43+
# Update proxy list if PROXY_LIST environment variable is defined
17744
if [ -n "$PROXY_LIST" ]; then
178-
log_info "PROXY_LIST environment variable detected, updating proxy list..."
179-
php /app/bin/lerama proxy:update
180-
if [ $? -eq 0 ]; then
181-
log_success "Proxy list updated successfully"
182-
else
183-
log_info "Failed to update proxy list, will retry later"
184-
fi
185-
fi
186-
187-
# Set correct permissions for /app/storage
188-
log_info "Setting permissions for /app/public/storage..."
189-
chown -R www-data:www-data /app/public/storage
190-
chmod -R 755 /app/public/storage
191-
log_success "Permissions set for /app/public/storage"
192-
193-
# PHP-FPM
194-
if [ ! -d /var/run/php ]; then
195-
log_info "Creating PHP-FPM directory..."
196-
mkdir -p /var/run/php
197-
chown -R www-data:www-data /var/run/php
198-
log_success "PHP-FPM directory created"
199-
fi
200-
201-
echo -e "\n${GREEN}Lerama: Initialized ===${NC}\n"
202-
203-
wait -n
45+
log_info "PROXY_LIST environment variable detected, will update proxy list after startup..."
46+
fi

setup/install.php renamed to setup/start.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function executeSqlFile($conn, $filePath, $migrationName = null) {
105105
}
106106

107107
try {
108-
$envFile = '../app/.env';
108+
$envFile = '/app/.env';
109109
$env = parseEnvFile($envFile);
110110

111111
if (empty($env)) {

0 commit comments

Comments
 (0)