Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
210631ac
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
210631ac
编写于
11月 01, 2018
作者:
S
Shinya Maeda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add action to deployment
上级
9bd4b2e8
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
84 addition
and
7 deletion
+84
-7
app/models/concerns/deployable.rb
app/models/concerns/deployable.rb
+2
-1
app/models/deployment.rb
app/models/deployment.rb
+13
-0
app/services/update_deployment_service.rb
app/services/update_deployment_service.rb
+1
-5
db/migrate/20181030150739_add_action_to_deployments.rb
db/migrate/20181030150739_add_action_to_deployments.rb
+15
-0
db/migrate/20181030160939_add_index_on_action_to_deployments.rb
...rate/20181030160939_add_index_on_action_to_deployments.rb
+19
-0
db/post_migrate/20181030151224_fill_empty_action_in_deployments.rb
...igrate/20181030151224_fill_empty_action_in_deployments.rb
+30
-0
db/schema.rb
db/schema.rb
+4
-1
未找到文件。
app/models/concerns/deployable.rb
浏览文件 @
210631ac
...
...
@@ -21,7 +21,8 @@ module Deployable
sha:
sha
,
user:
user
,
deployable:
self
,
on_stop:
on_stop
).
tap
do
|
_
|
on_stop:
on_stop
,
action:
environment_action
).
tap
do
|
_
|
self
.
reload
# Reload relationships
end
end
...
...
app/models/deployment.rb
浏览文件 @
210631ac
...
...
@@ -4,6 +4,7 @@ class Deployment < ActiveRecord::Base
include
AtomicInternalId
include
IidRoutes
include
AfterCommitQueue
include
EnumWithNil
belongs_to
:project
,
required:
true
belongs_to
:environment
,
required:
true
...
...
@@ -55,6 +56,12 @@ class Deployment < ActiveRecord::Base
canceled:
4
}
enum_with_nil
action:
{
unknown_action:
nil
,
start:
1
,
stop:
2
}
def
self
.
last_for_environment
(
environment
)
ids
=
self
.
for_environment
(
environment
)
...
...
@@ -149,6 +156,12 @@ class Deployment < ActiveRecord::Base
finished_at
end
def
action
return
'start'
if
deployment
.
unknown_action?
super
end
def
formatted_deployment_time
deployed_at
&
.
to_time
&
.
in_time_zone
&
.
to_s
(
:medium
)
end
...
...
app/services/update_deployment_service.rb
浏览文件 @
210631ac
...
...
@@ -20,7 +20,7 @@ class UpdateDeploymentService
environment
.
external_url
=
expanded_environment_url
if
expanded_environment_url
environment
.
fire_state_event
(
action
)
environment
.
fire_state_event
(
deployment
.
action
)
break
unless
environment
.
save
break
if
environment
.
stopped?
...
...
@@ -46,8 +46,4 @@ class UpdateDeploymentService
def
environment_url
environment_options
[
:url
]
end
def
action
environment_options
[
:action
]
||
'start'
end
end
db/migrate/20181030150739_add_action_to_deployments.rb
0 → 100644
浏览文件 @
210631ac
# frozen_string_literal: true
class
AddActionToDeployments
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
up
add_column
:deployments
,
:action
,
:integer
,
limit:
2
end
def
down
remove_column
:deployments
,
:action
,
:integer
,
limit:
2
end
end
db/migrate/20181030160939_add_index_on_action_to_deployments.rb
0 → 100644
浏览文件 @
210631ac
# frozen_string_literal: true
class
AddIndexOnActionToDeployments
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
add_concurrent_index
:deployments
,
[
:environment_id
,
:action
]
add_concurrent_index
:deployments
,
[
:project_id
,
:action
]
end
def
down
remove_concurrent_index
:deployments
,
[
:environment_id
,
:action
]
remove_concurrent_index
:deployments
,
[
:project_id
,
:action
]
end
end
db/post_migrate/20181030151224_fill_empty_action_in_deployments.rb
0 → 100644
浏览文件 @
210631ac
# frozen_string_literal: true
class
FillEmptyActionInDeployments
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
DEPLOYMENT_ACTION_START
=
1
DEPLOYMENT_ACTION_STOP
=
2
def
up
ActiveRecord
::
Base
.
connection
.
execute
<<~
SQL
UPDATE
"deployments"
SET
"action" = (CASE WHEN (SELECT true
FROM ci_builds
WHERE ci_builds.id = deployments.deployable_id
AND ci_builds.options LIKE '%action: stop%') THEN
#{
DEPLOYMENT_ACTION_STOP
}
ELSE
#{
DEPLOYMENT_ACTION_START
}
END)
WHERE
"deployments"."action" IS NULL
SQL
end
def
down
# no-op
end
end
db/schema.rb
浏览文件 @
210631ac
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2018103
0135124
)
do
ActiveRecord
::
Schema
.
define
(
version:
2018103
1190559
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
@@ -826,13 +826,16 @@ ActiveRecord::Schema.define(version: 20181030135124) do
t
.
string
"on_stop"
t
.
integer
"status"
,
limit:
2
,
default:
2
,
null:
false
t
.
datetime_with_timezone
"finished_at"
t
.
integer
"action"
,
limit:
2
end
add_index
"deployments"
,
[
"created_at"
],
name:
"index_deployments_on_created_at"
,
using: :btree
add_index
"deployments"
,
[
"deployable_type"
,
"deployable_id"
],
name:
"index_deployments_on_deployable_type_and_deployable_id"
,
using: :btree
add_index
"deployments"
,
[
"environment_id"
,
"action"
],
name:
"index_deployments_on_environment_id_and_action"
,
using: :btree
add_index
"deployments"
,
[
"environment_id"
,
"id"
],
name:
"index_deployments_on_environment_id_and_id"
,
using: :btree
add_index
"deployments"
,
[
"environment_id"
,
"iid"
,
"project_id"
],
name:
"index_deployments_on_environment_id_and_iid_and_project_id"
,
using: :btree
add_index
"deployments"
,
[
"environment_id"
,
"status"
],
name:
"index_deployments_on_environment_id_and_status"
,
using: :btree
add_index
"deployments"
,
[
"project_id"
,
"action"
],
name:
"index_deployments_on_project_id_and_action"
,
using: :btree
add_index
"deployments"
,
[
"project_id"
,
"iid"
],
name:
"index_deployments_on_project_id_and_iid"
,
unique:
true
,
using: :btree
add_index
"deployments"
,
[
"project_id"
,
"status"
],
name:
"index_deployments_on_project_id_and_status"
,
using: :btree
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录