Skip to content

Commit 895b9e9

Browse files
authored
Merge pull request #13 from flooding-kr/new
test
2 parents f10615b + 4c3b1f7 commit 895b9e9

6 files changed

Lines changed: 643 additions & 0 deletions

File tree

cd-bot.rb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
require 'json'
2+
require 'net/http'
3+
require 'uri'
4+
require 'time'
5+
6+
def lambda_handler(event:, context:)
7+
detail = event['detail']
8+
pipeline = detail['pipeline']
9+
stage = detail['stage']
10+
state = detail['state']
11+
region = event['region']
12+
13+
kst_time = Time.now.getlocal('+09:00').strftime("%Y-%m-%d %H:%M:%S KST")
14+
15+
color = case state
16+
when 'Succeeded' then 0x2ECC71 # 초록
17+
when 'Failed' then 0xE74C3C # 빨강
18+
when 'InProgress'then 0x3498DB # 파랑
19+
else 0x95A5A6 # 회색
20+
end
21+
22+
embed = {
23+
title: "CodePipeline Stage 업데이트",
24+
description: "**Pipeline:** `#{pipeline}`\n" \
25+
"**Stage:** `#{stage}`\n" \
26+
"**State:** `#{state}`",
27+
color: color,
28+
footer: {
29+
text: "AWS Region: #{region} | #{kst_time}"
30+
}
31+
}
32+
33+
webhook_url = ENV['DISCORD_WEBHOOK_URL']
34+
uri = URI.parse(webhook_url)
35+
36+
header = { 'Content-Type': 'application/json' }
37+
payload = {
38+
content:"<@&1315864971426529281>,
39+
username: "AWS CodePipeline Notifier",
40+
avatar_url: "https://a0.awsstatic.com/libra-css/images/logos/aws_logo_smile_1200x630.png",
41+
embeds: [embed]
42+
}
43+
44+
http = Net::HTTP.new(uri.host, uri.port)
45+
http.use_ssl = true
46+
request = Net::HTTP::Post.new(uri.request_uri, header)
47+
request.body = payload.to_json
48+
49+
response = http.request(request)
50+
puts "Discord 응답 코드: #{response.code}"
51+
52+
{ statusCode: 200, body: 'Success' }
53+
end
54+

pipline.json

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"pipeline": {
3+
"name": "flooding-pipeline",
4+
"pipelineType": "V2",
5+
"roleArn": "arn:aws:iam::588738598492:role/service-role/AWSCodePipelineServiceRole-ap-northeast-2-flooding-pipline",
6+
"artifactStore": {
7+
"type": "S3",
8+
"location": "codepipeline-ap-northeast-2-ea312f5d3183-4ea7-a0be-8bf648f7daeb"
9+
},
10+
"stages": [
11+
{
12+
"name": "Source",
13+
"actions": [
14+
{
15+
"name": "GitHub_Source",
16+
"actionTypeId": {
17+
"category": "Source",
18+
"owner": "AWS",
19+
"provider": "CodeStarSourceConnection",
20+
"version": "1"
21+
},
22+
"outputArtifacts": [
23+
{
24+
"name": "SourceArtifact"
25+
}
26+
],
27+
"configuration": {
28+
"ConnectionArn": "arn:aws:codeconnections:ap-northeast-2:588738598492:connection/b07906f7-2023-4175-b1d4-db4d7c051de7",
29+
"FullRepositoryId": "flooding-kr/flooding-baceknd",
30+
"BranchName": "main",
31+
"DetectChanges": "true"
32+
},
33+
"runOrder": 1
34+
}
35+
]
36+
},
37+
{
38+
"name": "Build",
39+
"actions": [
40+
{
41+
"name": "ECR_Build_And_Publish",
42+
"actionTypeId": {
43+
"category": "Build",
44+
"owner": "AWS",
45+
"provider": "ECR",
46+
"version": "1"
47+
},
48+
"inputArtifacts": [
49+
{
50+
"name": "SourceArtifact"
51+
}
52+
],
53+
"outputArtifacts": [
54+
{
55+
"name": "BuildArtifact"
56+
}
57+
],
58+
"region": "ap-northeast-2",
59+
"configuration": {
60+
"RepositoryName": "flooding-ecr",
61+
"ImageTag": "latest",
62+
"DockerfilePath": "Dockerfile"
63+
},
64+
"runOrder": 1
65+
}
66+
]
67+
},
68+
{
69+
"name": "Deploy",
70+
"actions": [
71+
{
72+
"name": "CodeDeploy",
73+
"actionTypeId": {
74+
"category": "Deploy",
75+
"owner": "AWS",
76+
"provider": "CodeDeploy",
77+
"version": "1"
78+
},
79+
"inputArtifacts": [
80+
{
81+
"name": "SourceArtifact"
82+
}
83+
],
84+
"configuration": {
85+
"ApplicationName": "flooding-deploy",
86+
"DeploymentGroupName": "flooding-dg"
87+
},
88+
"runOrder": 1
89+
}
90+
]
91+
}
92+
],
93+
"version": 1
94+
}
95+
}
96+

scripts/appspec.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 0.0
2+
os: linux
3+
files:
4+
- source: /
5+
destination: /var/www/html
6+
hooks:
7+
ApplicationStop:
8+
- location: scripts/stop_server.sh
9+
BeforeInstall:
10+
- location: scripts/install_dependencies.sh
11+
ApplicationStart:
12+
- location: scripts/start_server.sh

0 commit comments

Comments
 (0)