Commit 6f753f9e by Ivan

feat: healthy check

parent f19dae76
...@@ -73,10 +73,10 @@ ENTRYPOINT ["/rails/bin/docker-entrypoint"] ...@@ -73,10 +73,10 @@ ENTRYPOINT ["/rails/bin/docker-entrypoint"]
# Start server via Rails default port 3000 # Start server via Rails default port 3000
EXPOSE 3000 EXPOSE 3000
# 添加健康检查,使用简单的curl请求检查应用是否响应 # 添加健康检查,使用专门的健康检查端点
# 增加start-period到120秒,给应用更多启动时间 # 增加start-period到120秒,给应用更多启动时间
HEALTHCHECK --interval=10s --timeout=5s --start-period=120s --retries=10 \ HEALTHCHECK --interval=10s --timeout=5s --start-period=120s --retries=10 \
CMD curl -f http://localhost:3000/ || exit 1 CMD curl -f http://localhost:3000/health_check || exit 1
# 使用正确的路径启动Rails服务器,并指定端口为3000 # 使用正确的路径启动Rails服务器,并指定端口为3000
CMD ["/rails/code/bin/rails", "server", "-p", "3000", "-b", "0.0.0.0"] CMD ["/rails/code/bin/rails", "server", "-p", "3000", "-b", "0.0.0.0"]
class HealthCheckController < ApplicationController
# 跳过身份验证,确保健康检查可以在未登录状态下访问
skip_before_action :require_authentication, only: [:index]
def index
# 简单返回成功状态
render json: { status: "ok" }, status: :ok
end
end
...@@ -31,15 +31,15 @@ proxy: ...@@ -31,15 +31,15 @@ proxy:
# 使用域名而不是IP地址 # 使用域名而不是IP地址
host: img-manager.mumumumushu.com host: img-manager.mumumumushu.com
# 配置Traefik使用自定义端口 # 配置Traefik使用自定义端口
options: # options:
# 定义多个入口点,包括非80端口 # # 定义多个入口点,包括非80端口
traefik.entryPoints.web.address: ":80" # traefik.entryPoints.web.address: ":80"
traefik.entryPoints.websecure.address: ":443" # traefik.entryPoints.websecure.address: ":443"
# 启用HTTP自动跳转到HTTPS # # 启用HTTP自动跳转到HTTPS
traefik.http.middlewares.redirect-to-https.redirectscheme.scheme: "https" # traefik.http.middlewares.redirect-to-https.redirectscheme.scheme: "https"
traefik.http.routers.redirs.rule: "hostregexp(`{host:.+}`)" # traefik.http.routers.redirs.rule: "hostregexp(`{host:.+}`)"
traefik.http.routers.redirs.entrypoints: "web" # traefik.http.routers.redirs.entrypoints: "web"
traefik.http.routers.redirs.middlewares: "redirect-to-https" # traefik.http.routers.redirs.middlewares: "redirect-to-https"
# Credentials for your image host. # Credentials for your image host.
registry: registry:
...@@ -130,7 +130,7 @@ asset_path: false ...@@ -130,7 +130,7 @@ asset_path: false
# Deployment configuration for better reliability # Deployment configuration for better reliability
# 增加部署超时时间,给应用更多时间启动 # 增加部署超时时间,给应用更多时间启动
deploy_timeout: 300 deploy_timeout: 120
# 增加容器排水超时时间 # 增加容器排水超时时间
drain_timeout: 60 drain_timeout: 60
......
...@@ -30,8 +30,8 @@ Rails.application.configure do ...@@ -30,8 +30,8 @@ Rails.application.configure do
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true config.force_ssl = true
# Skip http-to-https redirect for the default health check endpoint. # Skip http-to-https redirect for health check endpoints.
# config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" || request.path == "/health_check" || request.path == "/session/new" } } }
# Log to STDOUT with the current request id as a default log tag. # Log to STDOUT with the current request id as a default log tag.
config.log_tags = [ :request_id ] config.log_tags = [ :request_id ]
......
Rails.application.routes.draw do Rails.application.routes.draw do
# 健康检查路由,用于Docker健康检查
get "health_check", to: "health_check#index"
# get "tags/index", to: "tags#index" # get "tags/index", to: "tags#index"
# get "tags/new", to: "tags#new" # get "tags/new", to: "tags#new"
# get "tags/create", to: "tags#create" # get "tags/create", to: "tags#create"
......
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