首先需要在 GitHub 上建立两个仓库,一个 公有,一个 私有

公有 仓库用于存放 Hexo 生成的静态文件以部署 GitHub Pages

私有 仓库用于存放未经编译的 Hexo 文件。

示例:starudream/blog-page 为我的 公有 仓库,starudream/blog 是我的 私有 仓库。

然后在 https://github.com/settings/tokens 申请 PAT,并将其加入私有仓库的 Secrets

最后在 私有 仓库内创建文件 .github/workflows/deploy.yml,修改相应内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
name: Deploy
on:
push:
branches:
- master
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 1
- name: Checkout Page
uses: actions/[email protected]
with:
fetch-depth: 1
repository: starudream/blog-page
path: .deploy_git
token: ${{ secrets.PAGE_PAT }}
- name: Cache
uses: actions/[email protected]
with:
path: node_modules
key: ${{ runner.os }}-${{ hashFiles('**/package.json') }}
- name: Node
uses: actions/[email protected]
with:
node-version: 12
- name: Build
run: |
npm install hexo-cli -g && npm install && npm run build
- name: Deploy
run: |
rm -rf .deploy_git/* && cp -rf public/* .deploy_git/
git config --global user.name starudream
git config --global user.email [email protected]
message=$(git log -1 --pretty=format:%s)
cd .deploy_git
git add -A
git commit -m "$message"
git push

基于 gitlab-ee:12.6.4-ee

创建 ruby docker 镜像

1
docker run -it --rm ruby /bin/bash

生成许可证

1
gem install gitlab-license
1
cat > license.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
require "openssl"
require "gitlab/license"

key_pair = OpenSSL::PKey::RSA.generate(2048)
File.open("license_key", "w") { |f| f.write(key_pair.to_pem) }

public_key = key_pair.public_key
File.open("license_key.pub", "w") { |f| f.write(public_key.to_pem) }

private_key = OpenSSL::PKey::RSA.new File.read("license_key")
Gitlab::License.encryption_key = private_key

license = Gitlab::License.new
license.licensee = {
"Name" => "none",
"Company" => "none",
"Email" => "[email protected]",
}
license.starts_at = Date.new(2020, 1, 1) # 开始时间
license.expires_at = Date.new(2050, 1, 1) # 结束时间
license.notify_admins_at = Date.new(2049, 12, 1)
license.notify_users_at = Date.new(2049, 12, 1)
license.block_changes_at = Date.new(2050, 1, 1)
license.restrictions = {
active_user_count: 10000,
}

puts "License:"
puts license

data = license.export
puts "Exported license:"
puts data
File.open("GitLabBV.gitlab-license", "w") { |f| f.write(data) }

public_key = OpenSSL::PKey::RSA.new File.read("license_key.pub")
Gitlab::License.encryption_key = public_key

data = File.read("GitLabBV.gitlab-license")
$license = Gitlab::License.import(data)

puts "Imported license:"
puts $license

unless $license
raise "The license is invalid."
end

if $license.restricted?(:active_user_count)
active_user_count = 10000
if active_user_count > $license.restrictions[:active_user_count]
raise "The active user count exceeds the allowed amount!"
end
end

if $license.notify_admins?
puts "The license is due to expire on #{$license.expires_at}."
end

if $license.notify_users?
puts "The license is due to expire on #{$license.expires_at}."
end

module Gitlab
class GitAccess
def check(cmd, changes = nil)
if $license.block_changes?
return build_status_object(false, "License expired")
end
end
end
end

puts "This instance of GitLab Enterprise Edition is licensed to:"
$license.licensee.each do |key, value|
puts "#{key}: #{value}"
end

if $license.expired?
puts "The license expired on #{$license.expires_at}"
elsif $license.will_expire?
puts "The license will expire on #{$license.expires_at}"
else
puts "The license will never expire."
end
1
ruby license.rb

生成 GitLabBV.gitlab-license license_key license_key.pub 这三个文件。

使用许可证

license_key.pub 文件替换 /opt/gitlab/embedded/service/gitlab-rails/.license_encryption_key.pub

GitLabBV.gitlab-license 即是许可证,填入 ${address}/admin/license 地址并重启。

修改等级

1
2
3
4
5
6
7
8
9
10
11
--- /opt/gitlab/embedded/service/gitlab-rails/ee/app/models/license.rb
+++ /opt/gitlab/embedded/service/gitlab-rails/ee/app/models/license.rb
@@ -367,7 +367,7 @@
end

def plan
- restricted_attr(:plan).presence || STARTER_PLAN
+ restricted_attr(:plan).presence || ULTIMATE_PLAN
end

def edition

修改完成后使用 gitlab-ctl reconfigure 重新加载配置。

参考

  • https://www.rubydoc.info/gems/gitlab-license/1.0.0/file/README.md

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
--- a/themes/next/layout/_scripts/pjax.swig
+++ b/themes/next/layout/_scripts/pjax.swig
@@ -15,8 +15,8 @@ var pjax = new Pjax({
scrollTo : !CONFIG.bookmark.enable
});

-window.addEventListener('pjax:success', () => {
- document.querySelectorAll('script[pjax], script#page-configurations, #pjax script').forEach(element => {
+window.addEventListener('pjax:success', function() {
+ document.querySelectorAll('script[pjax], script#page-configurations, #pjax script').forEach(function(element) {
var code = element.text || element.textContent || element.innerHTML || '';
var parent = element.parentNode;
parent.removeChild(element);

--- a/themes/next/layout/_third-party/comments/disqus.swig
+++ b/themes/next/layout/_third-party/comments/disqus.swig
@@ -41,7 +41,7 @@
// load directly when there's no a scrollbar
window.addEventListener('load', loadComments, false);
} else {
- var disqus_scroll = () => {
+ var disqus_scroll = function() {
// offsetTop may changes because of manually resizing browser window or lazy loading images.
var offsetTop = document.getElementById('comments').offsetTop - window.innerHeight;
var scrollTop = window.scrollY;

--- a/themes/next/layout/_third-party/quicklink.swig
+++ b/themes/next/layout/_third-party/quicklink.swig
@@ -3,12 +3,12 @@
<script src="{{ quicklink_uri }}"></script>
<script>
{%- if page.quicklink.delay %}
- window.addEventListener('load', () => {
+ window.addEventListener('load', function() {
{%- endif %}
quicklink({
timeout: {{ page.quicklink.timeout }},
priority: {{ page.quicklink.priority }},
- ignores: [uri => uri.includes('#'),uri => uri == '{{ url | replace('index.html', '') }}',{{ page.quicklink.ignores }}]
+ ignores: [function(uri) { return uri.includes('#') }, function(uri) { return uri === '{{ url | replace('index.html', '') }}' }, {{ page.quicklink.ignores }}]
});
{%- if page.quicklink.delay %}
});

安装 docker 并拉取相关镜像

  • gitlab/gitlab-ce

  • gitlab/gitlab-runner

1
2
docker pull gitlab/gitlab-ce
docker pull gitlab/gitlab-runner

运行 docker 镜像

  • GitLab CE
1
2
3
4
5
6
7
8
9
10
docker run -d \
--name gitlab \
--restart always \
-p 127.0.0.1:50080:80 \
-p 127.0.0.1:50022:22 \
-m 2048m \
-v /opt/docker/gitlab/config:/etc/gitlab \
-v /opt/docker/gitlab/logs:/var/log/gitlab \
-v /opt/docker/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest
1
2
3
4
5
6
7
8
docker run -d \
--name gitlab-runner \
--link gitlab:gitlab \
--restart always \
-m 1024m \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /opt/docker/gitlab-runner/config:/etc/gitlab-runner \
gitlab/gitlab-runner:latest
  • GitLab EE
1
2
3
4
5
6
7
8
9
10
11
docker run -d \
--name gitlab \
--restart always \
-p 127.0.0.1:50080:80 \
-p 127.0.0.1:50022:22 \
-m 2048m \
-v /opt/docker/gitlab/config:/etc/gitlab \
-v /opt/docker/gitlab/logs:/var/log/gitlab \
-v /opt/docker/gitlab/data:/var/opt/gitlab \
-v /opt/docker/gitlab/.license_encryption_key.pub:/opt/gitlab/embedded/service/gitlab-rails/.license_encryption_key.pub \
gitlab/gitlab-ee:latest

注册 gitlab-runner

1
2
3
docker exec -it gitlab-runner gitlab-runner register
# 之后访问地址 http://code.52xckl.cn/admin/runners 配置即可
# 配置地址可以使用 http://gitlab 内网

参考文档

  • gitlab

  • gitlab-runner

安装 npm 以及 asar

1
2
# download: https://nodejs.org/en/
npm i -g asar

解压 GitKraken 的资源文件

1
2
# 安装目录\gitkraken\app-x.x.x\resources
asar extract ./app.asar ./tmp/

修改 static/index.js 文件(注意备份)

下面是 v6.5.1 之后的版本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
--- static/index.js
+++ static/index.js
@@ -1,6 +1,27 @@
// Warning: You almost certainly do *not* want to edit this code -
// instead, you want to edit src/js/main.jsx instead
+
+function PatchSnapshot() {
+ const edmLiteD = snapshotResult.customRequire('@axosoft/edm-lite-d/src/d.js');
+ snapshotResult.customRequire.cache['@axosoft/edm-lite-d/src/d.js'] = {
+ exports: function() {
+ let response = JSON.parse(edmLiteD(...arguments).toString('utf8'));
+ if ('licenseExpiresAt' in response || 'licensedFeatures' in response) {
+ response = {
+ ...response,
+ availableTrialDays: null,
+ licenseExpiresAt: 8640000000000000,
+ licensedFeatures: ['pro']
+ };
+ }
+ return Buffer.from(JSON.stringify(response), 'utf8');
+ }
+ };
+}
+
(function() {
+ PatchSnapshot();
+
const Perf = snapshotResult.customRequire('./src/js/utils/Performance.js');
Perf.timeEnd('loading monaco scripts');
Perf.time('index.js pre-bootstrap');

下面是 v6.5.1 之前的版本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
--- static/index.js
+++ static/index.js
@@ -1,7 +1,29 @@
// Warning: You almost certainly do *not* want to edit this code -
// instead, you want to edit src/js/main.jsx instead

+function XhrPromiseReduxProxy() {
+ const xhrPromiseRedux = snapshotResult.customRequire(
+ 'xhr-promise-redux/dist/index.js'
+ );
+ xhrPromiseRedux._post = xhrPromiseRedux.post;
+ xhrPromiseRedux.post = async (url, options) => {
+ const res = await xhrPromiseRedux._post(url, options);
+ if (url.match(/https:\/\/.*api.gitkraken.com\/phone-home/)) {
+ res.body.availableTrialDays = null;
+ res.body.code = 0;
+ res.body.features = [];
+ res.body.individualAccessState = null;
+ res.body.licenseExpiresAt = 8640000000000000;
+ res.body.licensedFeatures = ['pro'];
+ res.body.proAccessState = null;
+ }
+ return res;
+ };
+}
+
(function() {
+ XhrPromiseReduxProxy();
+
const Perf = snapshotResult.customRequire('./src/js/utils/Performance.js');
Perf.timeEnd('loading monaco scripts');
Perf.time('index.js pre-bootstrap');

重新打包

1
asar pack ./tmp/ app.asar