Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
img-manager
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ivan Lan
img-manager
Commits
6f753f9e
Commit
6f753f9e
authored
Mar 11, 2025
by
Ivan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: healthy check
parent
f19dae76
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
14 deletions
+25
-14
Dockerfile
Dockerfile
+2
-2
health_check_controller.rb
app/controllers/health_check_controller.rb
+9
-0
deploy.yml
config/deploy.yml
+10
-10
production.rb
config/environments/production.rb
+2
-2
routes.rb
config/routes.rb
+2
-0
No files found.
Dockerfile
View file @
6f753f9e
...
...
@@ -73,10 +73,10 @@ ENTRYPOINT ["/rails/bin/docker-entrypoint"]
# Start server via Rails default port 3000
EXPOSE
3000
# 添加健康检查,使用
简单的curl请求检查应用是否响应
# 添加健康检查,使用
专门的健康检查端点
# 增加start-period到120秒,给应用更多启动时间
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
CMD
["/rails/code/bin/rails", "server", "-p", "3000", "-b", "0.0.0.0"]
app/controllers/health_check_controller.rb
0 → 100644
View file @
6f753f9e
class
HealthCheckController
<
ApplicationController
# 跳过身份验证,确保健康检查可以在未登录状态下访问
skip_before_action
:require_authentication
,
only:
[
:index
]
def
index
# 简单返回成功状态
render
json:
{
status:
"ok"
},
status: :ok
end
end
config/deploy.yml
View file @
6f753f9e
...
...
@@ -31,15 +31,15 @@ proxy:
# 使用域名而不是IP地址
host
:
img-manager.mumumumushu.com
# 配置Traefik使用自定义端口
options
:
# 定义多个入口点,包括非80端口
traefik.entryPoints.web.address
:
"
:80"
traefik.entryPoints.websecure.address
:
"
:443"
# 启用HTTP自动跳转到HTTPS
traefik.http.middlewares.redirect-to-https.redirectscheme.scheme
:
"
https"
traefik.http.routers.redirs.rule
:
"
hostregexp(`{host:.+}`)"
traefik.http.routers.redirs.entrypoints
:
"
web"
traefik.http.routers.redirs.middlewares
:
"
redirect-to-https"
#
options:
#
# 定义多个入口点,包括非80端口
#
traefik.entryPoints.web.address: ":80"
#
traefik.entryPoints.websecure.address: ":443"
#
# 启用HTTP自动跳转到HTTPS
#
traefik.http.middlewares.redirect-to-https.redirectscheme.scheme: "https"
#
traefik.http.routers.redirs.rule: "hostregexp(`{host:.+}`)"
#
traefik.http.routers.redirs.entrypoints: "web"
#
traefik.http.routers.redirs.middlewares: "redirect-to-https"
# Credentials for your image host.
registry
:
...
...
@@ -130,7 +130,7 @@ asset_path: false
# Deployment configuration for better reliability
# 增加部署超时时间,给应用更多时间启动
deploy_timeout
:
30
0
deploy_timeout
:
12
0
# 增加容器排水超时时间
drain_timeout
:
60
...
...
config/environments/production.rb
View file @
6f753f9e
...
...
@@ -30,8 +30,8 @@ Rails.application.configure do
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config
.
force_ssl
=
true
# Skip http-to-https redirect for
the default health check endpoint
.
# config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up
" } } }
# Skip http-to-https redirect for
health check endpoints
.
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.
config
.
log_tags
=
[
:request_id
]
...
...
config/routes.rb
View file @
6f753f9e
Rails
.
application
.
routes
.
draw
do
# 健康检查路由,用于Docker健康检查
get
"health_check"
,
to:
"health_check#index"
# get "tags/index", to: "tags#index"
# get "tags/new", to: "tags#new"
# get "tags/create", to: "tags#create"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment