@@ -14,7 +14,7 @@ class Common
1414 CONTAINER_IMAGES_TO_RELEASE = Project . components + %i[ config-generator ]
1515
1616 def copy_container_images_to_release_registry ( component_info )
17- container_tag = info . find_container_tag_for_build_id
17+ container_tag = component_info . find_container_tag_for_build_id
1818 container_tags = component_info . find_manifests . map do |manifest |
1919 next nil unless CONTAINER_IMAGES_TO_RELEASE . include? ( manifest . first . to_sym )
2020
@@ -37,21 +37,22 @@ def copy_container_image_to_release_registry(tag)
3737 return if Pyxis ::GlobalStatus . dry_run?
3838
3939 success = system ( "crane copy #{ CI_BUILDS_PREFIX } #{ tag } #{ CONTAINER_RELEASE_PREFIX } #{ tag } " )
40- logger . error ( 'Failed to copy container image to release registry' , tag : tag )
40+ logger . error ( 'Failed to copy container image to release registry' , tag : tag ) unless success
4141 success
4242 end
4343 end
4444
4545 def with_release_registry_auth
46- return yield if File . exist? ( 'tmp/gitlab_token' )
46+ token_exists = File . exist? ( 'tmp/gitlab_token' )
47+ return yield if token_exists
4748
4849 logger . info ( 'Authentication with release registry' )
4950 File . write ( 'tmp/gitlab_token' , Pyxis ::Environment . gitlab_release_tools_token )
5051 success = system (
51- " crane auth login
52- -u #{ CONTAINER_RELEASE_PUBLISH_USER }
53- --password-stdin #{ CONTAINER_RELEASE_REGISTRY }
54- < tmp/gitlab_token"
52+ ' crane auth login ' \
53+ " -u #{ CONTAINER_RELEASE_PUBLISH_USER } " \
54+ " --password-stdin #{ CONTAINER_RELEASE_REGISTRY } " \
55+ ' < tmp/gitlab_token'
5556 )
5657
5758 unless success
@@ -61,9 +62,70 @@ def with_release_registry_auth
6162
6263 yield
6364 ensure
64- system ( "crane auth logout #{ CONTAINER_RELEASE_REGISTRY } " )
65- File . delete ( 'tmp/gitlab_token' )
66- logger . info ( 'Unauthenticated from release registry' )
65+ unless token_exists
66+ system ( "crane auth logout #{ CONTAINER_RELEASE_REGISTRY } " )
67+ File . delete ( 'tmp/gitlab_token' )
68+ logger . info ( 'Unauthenticated from release registry' )
69+ end
70+ end
71+
72+ def publish_github_release ( component_info , prerelease :)
73+ logger . info ( 'Starting release to codezero repository' , tag : component_info . find_container_tag_for_build_id )
74+
75+ release_version = component_info . find_container_tag_for_build_id
76+ reticulum_sha = component_info . execute ( filter_components : [ :reticulum ] ) [ :reticulum ]
77+
78+ compose_path = 'docker-compose/docker-compose.yml'
79+ env_path = 'docker-compose/.env'
80+
81+ codezero_compose_content = GithubClient . octokit . contents (
82+ Project ::Codezero . github_path ,
83+ path : compose_path
84+ )
85+ codezero_env_content = GithubClient . octokit . contents (
86+ Project ::Codezero . github_path ,
87+ path : env_path
88+ )
89+
90+ reticulum_compose_content = GithubClient . octokit . contents (
91+ Project ::Reticulum . github_path ,
92+ path : compose_path ,
93+ ref : reticulum_sha
94+ )
95+ reticulum_env_content = GithubClient . octokit . contents (
96+ Project ::Reticulum . github_path ,
97+ path : env_path ,
98+ ref : reticulum_sha
99+ )
100+
101+ reticulum_env = Base64 . decode64 reticulum_env_content . content
102+ reticulum_compose = Base64 . decode64 reticulum_compose_content . content
103+
104+ codezero_env = reticulum_env . sub ( 'IMAGE_TAG=' , "IMAGE_TAG=#{ release_version } " )
105+
106+ GithubClient . octokit . update_contents (
107+ Project ::Codezero . github_path ,
108+ env_path ,
109+ "Update compose env for #{ release_version } " ,
110+ codezero_env_content . sha ,
111+ codezero_env ,
112+ Project ::Codezero . default_branch
113+ )
114+ GithubClient . octokit . update_contents (
115+ Project ::Codezero . github_path ,
116+ compose_path ,
117+ "Update compose file for #{ release_version } " ,
118+ codezero_compose_content . sha ,
119+ reticulum_compose ,
120+ Project ::Codezero . default_branch
121+ )
122+
123+ GithubClient . octokit . create_release (
124+ Project ::Codezero . github_path ,
125+ release_version ,
126+ name : release_version ,
127+ prerelease : prerelease
128+ )
67129 end
68130 end
69131 end
0 commit comments