Commit 3555e39e by Ivan

feat: update entrypoint

parent bf140a70
# syntax=docker/dockerfile:1 # 移除 syntax 指令以避免网络问题
# 原指令: # syntax=docker/dockerfile:1
# check=error=true # check=error=true
# This Dockerfile is designed for Git-based deployment with Kamal # This Dockerfile is designed for Git-based deployment with Kamal
...@@ -51,7 +52,7 @@ VOLUME ["/rails/code", "/rails/storage", "/rails/public/uploads", "/rails/public ...@@ -51,7 +52,7 @@ VOLUME ["/rails/code", "/rails/storage", "/rails/public/uploads", "/rails/public
# Copy entrypoint script # Copy entrypoint script
COPY bin/docker-entrypoint /rails/bin/ COPY bin/docker-entrypoint /rails/bin/
RUN chmod +x /rails/bin/docker-entrypoint # RUN chmod +x /rails/bin/docker-entrypoint
# Run and own only the runtime files as a non-root user for security # Run and own only the runtime files as a non-root user for security
RUN groupadd --system --gid 1000 rails && \ RUN groupadd --system --gid 1000 rails && \
......
...@@ -12,22 +12,22 @@ echo "Setting up directories..." ...@@ -12,22 +12,22 @@ echo "Setting up directories..."
mkdir -p /rails/code /rails/storage /rails/public/uploads /rails/public/assets /rails/public/vite /rails/node_modules /rails/log /rails/tmp/pids /rails/tmp/cache /rails/tmp/sockets mkdir -p /rails/code /rails/storage /rails/public/uploads /rails/public/assets /rails/public/vite /rails/node_modules /rails/log /rails/tmp/pids /rails/tmp/cache /rails/tmp/sockets
# Set very permissive permissions for all directories # Set very permissive permissions for all directories
chmod -R 777 /rails/storage /rails/public/uploads /rails/public/assets /rails/public/vite /rails/node_modules /rails/log /rails/tmp # chmod -R 777 /rails/storage /rails/public/uploads /rails/public/assets /rails/public/vite /rails/node_modules /rails/log /rails/tmp
chown -R rails:rails /rails/storage /rails/public/uploads /rails/public/assets /rails/public/vite /rails/node_modules /rails/log /rails/tmp # chown -R rails:rails /rails/storage /rails/public/uploads /rails/public/assets /rails/public/vite /rails/node_modules /rails/log /rails/tmp
# Verify the storage directory exists and has proper permissions # Verify the storage directory exists and has proper permissions
echo "Verifying storage directory permissions:" # echo "Verifying storage directory permissions:"
ls -la /rails | grep storage # ls -la /rails | grep storage
# Test if storage directory is writable # # Test if storage directory is writable
echo "Testing storage directory write access..." # echo "Testing storage directory write access..."
if touch /rails/storage/test_write_access; then # if touch /rails/storage/test_write_access; then
echo "✅ Storage directory is writable" # echo "✅ Storage directory is writable"
rm /rails/storage/test_write_access # rm /rails/storage/test_write_access
else # else
echo "❌ ERROR: Cannot write to storage directory. Check volume mount and permissions." # echo "❌ ERROR: Cannot write to storage directory. Check volume mount and permissions."
# Continue anyway, but log the error # # Continue anyway, but log the error
fi # fi
# Wait for external volumes to be properly mounted # Wait for external volumes to be properly mounted
sleep 5 sleep 5
...@@ -116,22 +116,24 @@ if [ "${@: -2:1}" == "./bin/rails" ] && [ "${@: -1:1}" == "server" ]; then ...@@ -116,22 +116,24 @@ if [ "${@: -2:1}" == "./bin/rails" ] && [ "${@: -1:1}" == "server" ]; then
# Create database directory with proper permissions # Create database directory with proper permissions
mkdir -p /rails/storage mkdir -p /rails/storage
chmod -R 777 /rails/storage # 注释掉可能导致权限错误的命令
chown -R rails:rails /rails/storage # chmod -R 777 /rails/storage
# chown -R rails:rails /rails/storage
echo "Creating database files if they don't exist..." echo "Creating database files if they don't exist..."
# Create database files if they don't exist # Create database files if they don't exist
for db_file in production.sqlite3 production_cache.sqlite3 production_queue.sqlite3 production_cable.sqlite3; do for db_file in production.sqlite3 production_cache.sqlite3 production_queue.sqlite3 production_cable.sqlite3; do
if [ ! -f "/rails/storage/$db_file" ]; then if [ ! -f "/rails/storage/$db_file" ]; then
echo "Creating /rails/storage/$db_file" echo "Creating /rails/storage/$db_file"
touch "/rails/storage/$db_file" touch "/rails/storage/$db_file" || echo "Cannot create $db_file, but continuing anyway"
chmod 666 "/rails/storage/$db_file" # 注释掉可能导致权限错误的命令
chown rails:rails "/rails/storage/$db_file" # chmod 666 "/rails/storage/$db_file"
# chown rails:rails "/rails/storage/$db_file"
else else
echo "Database file /rails/storage/$db_file already exists" echo "Database file /rails/storage/$db_file already exists"
# Make sure existing file has correct permissions # 注释掉可能导致权限错误的命令
chmod 666 "/rails/storage/$db_file" # chmod 666 "/rails/storage/$db_file"
chown rails:rails "/rails/storage/$db_file" # chown rails:rails "/rails/storage/$db_file"
fi fi
done done
...@@ -145,11 +147,11 @@ if [ "${@: -2:1}" == "./bin/rails" ] && [ "${@: -1:1}" == "server" ]; then ...@@ -145,11 +147,11 @@ if [ "${@: -2:1}" == "./bin/rails" ] && [ "${@: -1:1}" == "server" ]; then
echo "✅ Database file is writable" echo "✅ Database file is writable"
else else
echo "❌ ERROR: Cannot write to database file. Check volume mount and permissions." echo "❌ ERROR: Cannot write to database file. Check volume mount and permissions."
# Try to fix permissions again with more aggressive approach # 注释掉可能导致权限错误的命令
echo "Attempting more aggressive permission fix..." # echo "Attempting more aggressive permission fix..."
chown -R rails:rails /rails/storage # chown -R rails:rails /rails/storage
chmod -R 777 /rails/storage # chmod -R 777 /rails/storage
chmod 666 /rails/storage/*.sqlite3 # chmod 666 /rails/storage/*.sqlite3
# Try to create an empty database structure # Try to create an empty database structure
echo "Attempting to initialize empty database..." echo "Attempting to initialize empty database..."
...@@ -225,11 +227,11 @@ EOL ...@@ -225,11 +227,11 @@ EOL
echo "⚠️ Database preparation attempt $i failed, retrying..." echo "⚠️ Database preparation attempt $i failed, retrying..."
# Try to fix permissions again # 注释掉可能导致权限错误的命令
echo "Fixing permissions again..." # echo "Fixing permissions again..."
chmod -R 777 /rails/storage # chmod -R 777 /rails/storage
chmod 666 /rails/storage/*.sqlite3 # chmod 666 /rails/storage/*.sqlite3
chown -R rails:rails /rails/storage # chown -R rails:rails /rails/storage
sleep 5 sleep 5
done done
...@@ -243,7 +245,7 @@ EOL ...@@ -243,7 +245,7 @@ EOL
fi fi
# Build Vite assets if needed # Build Vite assets if needed
if [ ! -d "/rails/public/vite" ] || [ -z "$(ls -A /rails/public/vite)" ] || [ "$FORCE_VITE_BUILD" = "true" ]; then if [ ! -d "/rails/public/vite" ] || [ -z "$(ls -A /rails/public/vite 2>/dev/null || echo empty)" ] || [ "$FORCE_VITE_BUILD" = "true" ]; then
echo "Building Vite assets..." echo "Building Vite assets..."
bundle exec vite build bundle exec vite build
echo "✅ Vite assets built" echo "✅ Vite assets built"
......
...@@ -7,7 +7,10 @@ image: mumumumushu/img_manager ...@@ -7,7 +7,10 @@ image: mumumumushu/img_manager
# Deploy to these servers. # Deploy to these servers.
servers: servers:
web: web:
- 45.78.59.154 hosts:
- 45.78.59.154
labels:
traefik.http.routers.app.rule: Host(`img.mumumumushu.com`)
# job: # job:
# hosts: # hosts:
# - 192.168.0.1 # - 192.168.0.1
...@@ -45,8 +48,8 @@ env: ...@@ -45,8 +48,8 @@ env:
GIT_BRANCH: main GIT_BRANCH: main
# Force rebuild flags (set to true when you want to force rebuild) # Force rebuild flags (set to true when you want to force rebuild)
FORCE_BUNDLE_INSTALL: true FORCE_BUNDLE_INSTALL: false
FORCE_NPM_INSTALL: true FORCE_NPM_INSTALL: false
FORCE_VITE_BUILD: true FORCE_VITE_BUILD: true
# Database configuration # Database configuration
...@@ -123,6 +126,8 @@ asset_path: false ...@@ -123,6 +126,8 @@ asset_path: false
# Configure the image builder. # Configure the image builder.
builder: builder:
arch: amd64 arch: amd64
# cache:
# type: registry # 使用注册表缓存
# # Build image via remote server (useful for faster amd64 builds on arm64 computers) # # Build image via remote server (useful for faster amd64 builds on arm64 computers)
# remote: ssh://docker@docker-builder-server # remote: ssh://docker@docker-builder-server
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment