Skip to content

Commit

Permalink
Merge branch 'main' into simplify_ticket_system
Browse files Browse the repository at this point in the history
  • Loading branch information
oshiro3 authored Sep 17, 2023
2 parents b4acdb6 + 2cfc7bc commit 9473095
Show file tree
Hide file tree
Showing 29 changed files with 762 additions and 92 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v3
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Expand All @@ -33,7 +33,7 @@ jobs:

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: ${{ steps.login-ecr.outputs.registry }}/dreamkast-ecs
tags: |
Expand All @@ -54,7 +54,7 @@ jobs:
- name: Build
id: docker_build
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: ./
file: ./Dockerfile
Expand All @@ -71,10 +71,10 @@ jobs:
needs: ["build"]
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v3
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Expand All @@ -86,7 +86,7 @@ jobs:

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: ${{ steps.login-ecr.outputs.registry }}/dreamkast-ecs
tags: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gitops-prd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:

- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v1
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.PRIVATE_KEY }}

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v3
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gitops-stg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:

- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v1
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.PRIVATE_KEY }}

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v3
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/make-swagger-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ jobs:

- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v1
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.PRIVATE_KEY }}

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v3
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push-tag-by-releasebot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v1
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.PRIVATE_KEY }}
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ gem 'psych', '< 6'
gem "aws-sdk-ivs"
gem "aws-sdk-medialive"
gem "aws-sdk-mediapackage"
gem "aws-sdk-mediapackagev2"
gem "aws-sdk-ssm"

gem 'active_hash'
Expand Down
12 changes: 8 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ GEM
rake (>= 10.4, < 14.0)
ast (2.4.2)
aws-eventstream (1.2.0)
aws-partitions (1.628.0)
aws-partitions (1.817.0)
aws-record (2.7.0)
aws-sdk-dynamodb (~> 1.18)
aws-sdk-core (3.144.0)
aws-sdk-core (3.181.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.525.0)
aws-sigv4 (~> 1.1)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.5)
jmespath (~> 1, >= 1.6.1)
aws-sdk-dynamodb (1.76.0)
aws-sdk-core (~> 3, >= 3.127.0)
Expand All @@ -107,6 +107,9 @@ GEM
aws-sdk-mediapackage (1.56.0)
aws-sdk-core (~> 3, >= 3.127.0)
aws-sigv4 (~> 1.1)
aws-sdk-mediapackagev2 (1.5.0)
aws-sdk-core (~> 3, >= 3.177.0)
aws-sigv4 (~> 1.1)
aws-sdk-rails (3.6.3)
aws-record (~> 2)
aws-sdk-ses (~> 1)
Expand Down Expand Up @@ -702,6 +705,7 @@ DEPENDENCIES
aws-sdk-ivs
aws-sdk-medialive
aws-sdk-mediapackage
aws-sdk-mediapackagev2
aws-sdk-rails
aws-sdk-s3 (~> 1.14)
aws-sdk-ssm
Expand Down
11 changes: 11 additions & 0 deletions app/helpers/media_package_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,15 @@ def get_media_package_channels_from_aws(channel_ids = [])

channels.select { |channel| channel_ids.include?(channel.id) }
end

def resource_name
conference = streaming.conference
track = streaming.track

if review_app?
"review_app_#{review_app_number}_#{conference.abbr}_track#{track.name}"
else
"#{env_name}_#{conference.abbr}_track#{track.name}"
end
end
end
44 changes: 44 additions & 0 deletions app/helpers/media_package_v2_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'aws-sdk-mediapackagev2'

module MediaPackageV2Helper
def media_package_v2_client
creds = Aws::Credentials.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY'])
@client ||= if creds.set?
Aws::MediaPackageV2::Client.new(region: AWS_LIVE_STREAM_REGION, credentials: creds)
else
Aws::MediaPackageV2::Client.new(region: AWS_LIVE_STREAM_REGION)
end
end

def channel_group_name
conference = streaming.conference

if review_app?
"review_app_#{review_app_number}_#{conference.abbr}"
else
"#{env_name}_#{conference.abbr}"
end
end

def channel_name
conference = streaming.conference
track = streaming.track

if review_app?
"review_app_#{review_app_number}_#{conference.abbr}_track#{track.name}"
else
"#{env_name}_#{conference.abbr}_track#{track.name}"
end
end

def origin_endpoint_name
conference = streaming.conference
track = streaming.track

if review_app?
"review_app_#{review_app_number}_#{conference.abbr}_track#{track.name}"
else
"#{env_name}_#{conference.abbr}_track#{track.name}"
end
end
end
4 changes: 2 additions & 2 deletions app/jobs/create_media_package_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ def perform(*args)

channel = MediaPackageChannel.new(conference:, track:)
logger.error("Failed to create MediaPackageChannel: #{channel.errors}") unless channel.save
channel.create_media_package_resources
channel.create_aws_resource

endpoint = MediaPackageOriginEndpoint.new(conference:, media_package_channel: channel)
logger.error("Failed to create MediaPackageChannel: #{endpoint.errors}") unless endpoint.save
endpoint.create_media_package_resources
endpoint.create_aws_resource
rescue => e
logger.error(e.message)
end
Expand Down
43 changes: 43 additions & 0 deletions app/jobs/create_streaming_aws_resources_job.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,62 @@
class CreateStreamingAwsResourcesJob < ApplicationJob
include EnvHelper
include MediaPackageV2Helper
include LogoutHelper

# queue_as :default
self.queue_adapter = :async

attr_reader :conference
attr_reader :track
attr_reader :streaming

def perform(*args)
# Rails.logger.level = Logger::DEBUG
logger.info('Perform CreateMediaPackageV2Job')
@streaming = args[0]
@conference = @streaming.conference
@track = @streaming.track

create_media_package_v2_resources
create_media_package_resources

@streaming.update!(status: 'created')
rescue => e
@streaming.update!(status: 'error')
logger.error(e.message)
logger.error(e.backtrace.join("\n"))
end

def create_media_package_v2_resources
logger.info('Perform CreateMediaPackageV2Job')


channel_group = MediaPackageV2ChannelGroup.find_or_create_by(streaming_id: @streaming.id, name: channel_group_name)
logger.info("channel group: #{channel_group}")
channel_group.create_aws_resource

channel = MediaPackageV2Channel.find_or_create_by(streaming_id: @streaming.id, media_package_v2_channel_group_id: channel_group.id, name: channel_name)
logger.info("channel: #{channel}")
channel.create_aws_resource

origin_endpoint = MediaPackageV2OriginEndpoint.find_or_create_by(streaming_id: @streaming.id, media_package_v2_channel_id: channel.id, name: origin_endpoint_name)
logger.info("origin endpoint: #{origin_endpoint}")
origin_endpoint.create_aws_resource
end

def create_media_package_resources
logger.info('Perform CreateMediaPackageJob')

channel = MediaPackageChannel.find_or_create_by(streaming_id: @streaming.id)
logger.info("channel: #{channel}")
channel.create_aws_resource

parameter = MediaPackageParameter.find_or_create_by(streaming_id: @streaming.id, media_package_channel_id: channel.id)
logger.info("parameter: #{parameter}")
parameter.create_aws_resources

endpoint = MediaPackageOriginEndpoint.find_or_create_by(streaming_id: @streaming.id, media_package_channel_id: channel.id)
logger.info("endpoint: #{endpoint}")
endpoint.create_aws_resource
end
end
6 changes: 5 additions & 1 deletion app/jobs/delete_media_package_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ class DeleteMediaPackageJob < ApplicationJob
def perform(*args)
logger.info('Perform DeleteMediaPackageJob')
channel = args[0]
channel.media_package_origin_endpoints.each(&:destroy)
channel.media_package_origin_endpoints.each do |oe|
oe.delete_aws_resource
oe.destroy
end
channel.media_package_harvest_jobs.each(&:destroy)
channel.delete_aws_resource
channel.destroy
rescue => e
logger.error(e.message)
Expand Down
24 changes: 24 additions & 0 deletions app/jobs/delete_streaming_aws_resources_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,33 @@ def perform(*args)
logger.info('Perform DeleteStreamingAwsResourcesJob')
@streaming = args[0]

delete_media_package_v2_resources
delete_media_package_resources

@streaming.update!(status: 'deleted')
rescue => e
logger.error(e.message)
logger.error(e.backtrace.join("\n"))
end

def delete_media_package_v2_resources
logger.info('Deleting MediaPackageV2 resources...')

@streaming.media_package_v2_origin_endpoint&.destroy!
@streaming.media_package_v2_channel&.destroy!
@streaming.media_package_v2_channel_group&.destroy!

logger.info('Deleted MediaPackageV2 resources...')
end

def delete_media_package_resources
logger.info('Deleting MediaPackage resources...')

@streaming.media_package_origin_endpoint&.destroy!
@streaming.media_package_parameter&.destroy!
@streaming.media_package_channel&.media_package_harvest_jobs&.each(&:destroy)
@streaming.media_package_channel&.destroy!

logger.info('Deleted MediaPackage resources...')
end
end
Loading

0 comments on commit 9473095

Please sign in to comment.