Skip to content
Merged

test #13

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
54 changes: 54 additions & 0 deletions cd-bot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require 'json'
require 'net/http'
require 'uri'
require 'time'

def lambda_handler(event:, context:)
detail = event['detail']
pipeline = detail['pipeline']
stage = detail['stage']
state = detail['state']
region = event['region']

kst_time = Time.now.getlocal('+09:00').strftime("%Y-%m-%d %H:%M:%S KST")

color = case state
when 'Succeeded' then 0x2ECC71 # 초록
when 'Failed' then 0xE74C3C # 빨강
when 'InProgress'then 0x3498DB # 파랑
else 0x95A5A6 # 회색
end

embed = {
title: "CodePipeline Stage 업데이트",
description: "**Pipeline:** `#{pipeline}`\n" \
"**Stage:** `#{stage}`\n" \
"**State:** `#{state}`",
color: color,
footer: {
text: "AWS Region: #{region} | #{kst_time}"
}
}

webhook_url = ENV['DISCORD_WEBHOOK_URL']
uri = URI.parse(webhook_url)

header = { 'Content-Type': 'application/json' }
payload = {
content:"<@&1315864971426529281>,
username: "AWS CodePipeline Notifier",
avatar_url: "https://a0.awsstatic.com/libra-css/images/logos/aws_logo_smile_1200x630.png",
embeds: [embed]
}

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri, header)
request.body = payload.to_json

response = http.request(request)
puts "Discord 응답 코드: #{response.code}"

{ statusCode: 200, body: 'Success' }
end

96 changes: 96 additions & 0 deletions pipline.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"pipeline": {
"name": "flooding-pipeline",
"pipelineType": "V2",
"roleArn": "arn:aws:iam::588738598492:role/service-role/AWSCodePipelineServiceRole-ap-northeast-2-flooding-pipline",
"artifactStore": {
"type": "S3",
"location": "codepipeline-ap-northeast-2-ea312f5d3183-4ea7-a0be-8bf648f7daeb"
},
"stages": [
{
"name": "Source",
"actions": [
{
"name": "GitHub_Source",
"actionTypeId": {
"category": "Source",
"owner": "AWS",
"provider": "CodeStarSourceConnection",
"version": "1"
},
"outputArtifacts": [
{
"name": "SourceArtifact"
}
],
"configuration": {
"ConnectionArn": "arn:aws:codeconnections:ap-northeast-2:588738598492:connection/b07906f7-2023-4175-b1d4-db4d7c051de7",
"FullRepositoryId": "flooding-kr/flooding-baceknd",
"BranchName": "main",
"DetectChanges": "true"
},
"runOrder": 1
}
]
},
{
"name": "Build",
"actions": [
{
"name": "ECR_Build_And_Publish",
"actionTypeId": {
"category": "Build",
"owner": "AWS",
"provider": "ECR",
"version": "1"
},
"inputArtifacts": [
{
"name": "SourceArtifact"
}
],
"outputArtifacts": [
{
"name": "BuildArtifact"
}
],
"region": "ap-northeast-2",
"configuration": {
"RepositoryName": "flooding-ecr",
"ImageTag": "latest",
"DockerfilePath": "Dockerfile"
},
"runOrder": 1
}
]
},
{
"name": "Deploy",
"actions": [
{
"name": "CodeDeploy",
"actionTypeId": {
"category": "Deploy",
"owner": "AWS",
"provider": "CodeDeploy",
"version": "1"
},
"inputArtifacts": [
{
"name": "SourceArtifact"
}
],
"configuration": {
"ApplicationName": "flooding-deploy",
"DeploymentGroupName": "flooding-dg"
},
"runOrder": 1
}
]
}
],
"version": 1
}
}

12 changes: 12 additions & 0 deletions scripts/appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 0.0
os: linux
files:
- source: /
destination: /var/www/html
hooks:
ApplicationStop:
- location: scripts/stop_server.sh
BeforeInstall:
- location: scripts/install_dependencies.sh
ApplicationStart:
- location: scripts/start_server.sh
Loading
Loading