Commit 385817a1 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'zj-save-environment-deployment-refs' into 'master'

Save a fetchable ref per deployement

cc @DouweM @ayufan

See merge request !6618
parents 88fa5916 901c994b
...@@ -8,6 +8,7 @@ v 8.13.0 (unreleased) ...@@ -8,6 +8,7 @@ v 8.13.0 (unreleased)
- Replaced the check sign to arrow in the show build view. !6501 - Replaced the check sign to arrow in the show build view. !6501
- Add a /wip slash command to toggle the Work In Progress status of a merge request. !6259 (tbalthazar) - Add a /wip slash command to toggle the Work In Progress status of a merge request. !6259 (tbalthazar)
- Speed-up group milestones show page - Speed-up group milestones show page
- Keep refs for each deployment
- Log LDAP lookup errors and don't swallow unrelated exceptions. !6103 (Markus Koller) - Log LDAP lookup errors and don't swallow unrelated exceptions. !6103 (Markus Koller)
- Add more tests for calendar contribution (ClemMakesApps) - Add more tests for calendar contribution (ClemMakesApps)
- Avoid database queries on Banzai::ReferenceParser::BaseParser for nodes without references - Avoid database queries on Banzai::ReferenceParser::BaseParser for nodes without references
......
...@@ -11,7 +11,7 @@ class Deployment < ActiveRecord::Base ...@@ -11,7 +11,7 @@ class Deployment < ActiveRecord::Base
delegate :name, to: :environment, prefix: true delegate :name, to: :environment, prefix: true
after_save :keep_around_commit after_save :create_ref
def commit def commit
project.commit(sha) project.commit(sha)
...@@ -29,8 +29,8 @@ class Deployment < ActiveRecord::Base ...@@ -29,8 +29,8 @@ class Deployment < ActiveRecord::Base
self == environment.last_deployment self == environment.last_deployment
end end
def keep_around_commit def create_ref
project.repository.keep_around(self.sha) project.repository.create_ref(ref, ref_path)
end end
def manual_actions def manual_actions
...@@ -76,4 +76,10 @@ class Deployment < ActiveRecord::Base ...@@ -76,4 +76,10 @@ class Deployment < ActiveRecord::Base
where.not(id: self.id). where.not(id: self.id).
take take
end end
private
def ref_path
File.join(environment.ref_path, 'deployments', id.to_s)
end
end end
...@@ -47,4 +47,8 @@ class Environment < ActiveRecord::Base ...@@ -47,4 +47,8 @@ class Environment < ActiveRecord::Base
def update_merge_request_metrics? def update_merge_request_metrics?
self.name == "production" self.name == "production"
end end
def ref_path
"refs/environments/#{Shellwords.shellescape(name)}"
end
end end
...@@ -997,6 +997,10 @@ class Repository ...@@ -997,6 +997,10 @@ class Repository
Gitlab::Popen.popen(args, path_to_repo) Gitlab::Popen.popen(args, path_to_repo)
end end
def create_ref(ref, ref_path)
fetch_ref(path_to_repo, ref, ref_path)
end
def update_branch_with_hooks(current_user, branch) def update_branch_with_hooks(current_user, branch)
update_autocrlf_option update_autocrlf_option
......
...@@ -14,6 +14,19 @@ Defining environments in a project's `.gitlab-ci.yml` lets developers track ...@@ -14,6 +14,19 @@ Defining environments in a project's `.gitlab-ci.yml` lets developers track
Deployments are created when [jobs] deploy versions of code to [environments]. Deployments are created when [jobs] deploy versions of code to [environments].
### Checkout deployments locally
Since 8.13, a reference in the git repository is saved for each deployment. So
knowing what the state is of your current environments is only a `git fetch`
away.
In your git config, append the `[remote "<your-remote>"]` block with an extra
fetch line:
```
fetch = +refs/environments/*:refs/remotes/origin/environments/*
```
## Defining environments ## Defining environments
You can create and delete environments manually in the web interface, but we You can create and delete environments manually in the web interface, but we
......
...@@ -320,6 +320,16 @@ describe Repository, models: true do ...@@ -320,6 +320,16 @@ describe Repository, models: true do
end end
end end
describe '#create_ref' do
it 'redirects the call to fetch_ref' do
ref, ref_path = '1', '2'
expect(repository).to receive(:fetch_ref).with(repository.path_to_repo, ref, ref_path)
repository.create_ref(ref, ref_path)
end
end
describe "#changelog" do describe "#changelog" do
before do before do
repository.send(:cache).expire(:changelog) repository.send(:cache).expire(:changelog)
......
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