Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ stages:
- components
- !reference [.release-coordinator:canary:stages]

workflow:
name: $PIPELINE_NAME
rules:
- if: $CI_PIPELINE_SOURCE == "push"
variables:
PIPELINE_NAME: "Build pyxis image for $CI_COMMIT_SHORT_SHA"
- if: $PIPELINE_NAME != null

default:
image: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
tags:
Expand Down
28 changes: 28 additions & 0 deletions .gitlab/ci/release-coordinator.canary.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
.release-coordinator:canary:stages:
- release-coordinator:canary:notify-start
- release-coordinator:canary:build
- release-coordinator:canary:publish
- release-coordinator:canary:notify-finish

.release-coordinator:canary:
rules:
- if: $RELEASE_COORDINATOR == "canary"

release-coordinator:canary:notify-start:
extends:
- .release-coordinator:canary
stage: release-coordinator:canary:notify-start
script:
- bin/pyxis internal notify_new_coordinator --coordinator-pipeline-id $CI_PIPELINE_ID
variables:
DRY_RUN: "false"

release-coordinator:canary:tmp-branch:
extends:
- .release-coordinator:canary
Expand Down Expand Up @@ -55,6 +66,14 @@ release-coordinator:canary:publish:
- echo "Publishing approved"
when: manual

release-coordinator:canary:notify-publish-pending:
extends:
- .release-coordinator:canary
stage: release-coordinator:canary:publish
needs: !reference [release-coordinator:canary:publish, needs]
script:
- bin/pyxis internal release_notify_publish_pending

release-coordinator:canary:publish-containers:
extends:
- .release-coordinator:canary
Expand All @@ -76,3 +95,12 @@ release-coordinator:canary:publish-release:
- bin/pyxis internal release_canary_publish_release --coordinator-pipeline-id $CI_PIPELINE_ID
variables:
DRY_RUN: "false"

release-coordinator:canary:notify-finish:
extends:
- .release-coordinator:canary
stage: release-coordinator:canary:notify-finish
script:
- bin/pyxis internal notify_finish_coordinator --coordinator-pipeline-id $CI_PIPELINE_ID
variables:
DRY_RUN: "false"
48 changes: 48 additions & 0 deletions lib/pyxis/commands/internal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,54 @@ def release_canary_publish_tags
def release_canary_publish_release
Pyxis::Release::Canary.new.publish_release(options[:coordinator_pipeline_id])
end

desc 'release_notify_publish_pending', ''
method_option :coordinator_pipeline_id, required: true, type: :numeric
def release_notify_publish_pending
pipeline = GitlabClient.client.get_pipeline(
Project::Pyxis.api_gitlab_path,
options[:coordinator_pipeline_id]
).body
raise 'Pipeline not found' if pipeline.nil?

Pyxis::DiscordClient.new.send_notification(<<~DESC, :warn)
Coordinator pipeline awaiting approval for release publishing
#{"> #{pipeline.name}" if pipeline.name}
#{pipeline.web_url}
DESC
end

desc 'notify_new_coordinator', ''
method_option :coordinator_pipeline_id, required: true, type: :numeric
def notify_new_coordinator
pipeline = GitlabClient.client.get_pipeline(
Project::Pyxis.api_gitlab_path,
options[:coordinator_pipeline_id]
).body
raise 'Pipeline not found' if pipeline.nil?

Pyxis::DiscordClient.new.send_notification(<<~DESC)
New coordinator pipeline started
#{"> #{pipeline.name}" if pipeline.name}
#{pipeline.web_url}
DESC
end

desc 'notify_finish_coordinator', ''
method_option :coordinator_pipeline_id, required: true, type: :numeric
def notify_finish_coordinator
pipeline = GitlabClient.client.get_pipeline(
Project::Pyxis.api_gitlab_path,
options[:coordinator_pipeline_id]
).body
raise 'Pipeline not found' if pipeline.nil?

Pyxis::DiscordClient.new.send_notification(<<~DESC)
Coordinator pipeline has finished
#{"> #{pipeline.name}" if pipeline.name}
#{pipeline.web_url}
DESC
end
end
end
end
1 change: 1 addition & 0 deletions lib/pyxis/commands/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def create_canary
Project::Pyxis.api_gitlab_path,
Project::Pyxis.default_branch,
variables: {
PIPELINE_NAME: "Release build #{build_id} as canary",
RELEASE_COORDINATOR: 'canary',
BUILD_ID_TO_PROMOTE: build_id.to_s,
}
Expand Down
25 changes: 25 additions & 0 deletions lib/pyxis/discord_client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module Pyxis
class DiscordClient
LOG_CHANNEL = 1478849342101000222

COLOR_MAPPING = {
info: '#4caf50',
warn: '#ff8000',
error: '#f44336',
}.freeze

attr_reader :bot

def initialize
@bot = Discordrb::Bot.new(token: Pyxis::Environment.discord_bot_token)
end

def send_notification(message, severity = :info)
embed = Discordrb::Webhooks::Embed.new(description: message, color: COLOR_MAPPING[severity])

bot.send_message(LOG_CHANNEL, nil, false, [embed])
end
end
end
4 changes: 4 additions & 0 deletions lib/pyxis/gitlab_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ def create_pipeline(project_path_or_id, ref, variables: nil)
)
end

def get_pipeline(project_path_or_id, id)
get_json("/api/v4/projects/#{project_path_or_id}/pipelines/#{id}")
end

def list_pipeline_bridges(project_path_or_id, pipeline_id)
paginate_json("/api/v4/projects/#{project_path_or_id}/pipelines/#{pipeline_id}/bridges")
end
Expand Down
4 changes: 1 addition & 3 deletions lib/pyxis/managed_versioning/component_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ def find_container_version(jobs)
end

def load_pipeline(pipeline_id)
pipeline = GitlabClient.client.get_json(
"/api/v4/projects/#{Project::Reticulum.api_gitlab_path}/pipelines/#{pipeline_id}"
)
pipeline = GitlabClient.client.get_pipeline(Project::Reticulum.api_gitlab_path, pipeline_id)
return nil if pipeline.response.status == 404

[
Expand Down