Skip to content

Commit

Permalink
[Deploy] Set up continuous integration and deployment pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnsugyeong committed May 15, 2024
1 parent c6bffa6 commit e95f1f9
Show file tree
Hide file tree
Showing 12 changed files with 364 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .ebextensions-dev/00-set-timezone.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
commands:
set_time_zone:
command: ln -f -s /usr/share/zoneinfo/Asia/Seoul /etc/localtime
64 changes: 64 additions & 0 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: waggle dev CI/CD

on:
push:
branches:
- dev

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.TOKEN }}
submodules: true

- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'adopt'

- name: Configure AWS credentials
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 }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Build with Gradle & Upload Image to ECR
run: ./gradlew -Pdev clean jib

- name: Get current time
uses: josStorer/get-current-time@v2
id: current-time
with:
format: YYYYMMDD_HH-mm-ss
utcOffset: "+09:00"

- name: Generate deployment package
run: |
mkdir -p deploy/.platform/nginx/conf.d
cp Dockerrun.aws.dev.json deploy/Dockerrun.aws.json
cp -r .ebextensions-dev deploy/.ebextensions
cp .platform/nginx/conf.d/proxy-dev.conf deploy/.platform/nginx/conf.d/proxy.conf
cd deploy && zip -r deploy.zip .
- name: Beanstalk Deploy
uses: einaregilsson/beanstalk-deploy@v21
with:
aws_access_key: ${{ secrets.DEV_AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.DEV_AWS_SECRET_ACCESS_KEY }}
application_name: waggle-dev
environment_name: Waggle-dev-env
version_label: waggle-dev-${{steps.current-time.outputs.formattedTime}}
region: ${{ secrets.DEV_AWS_REGION }}
deployment_package: deploy/deploy.zip
wait_for_environment_recovery: 300
28 changes: 28 additions & 0 deletions .platform/nginx/conf.d/proxy-dev.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
server {
listen 80;

location / {
proxy_pass http://localhost:8080;
proxy_set_header X-Real_IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}

location /ws/chat {
proxy_pass $service_url;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;

# WebSocket
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Origin "";

# Timeout settings for WebSocket
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
proxy_connect_timeout 60s;
}
}
81 changes: 81 additions & 0 deletions Dockerrun.aws.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"AWSEBDockerrunVersion": 2,
"containerDefinitions": [
{
"name": "app",
"image": "471112861132.dkr.ecr.ap-northeast-2.amazonaws.com/waggle-dev",
"essential": true,
"portMappings": [
{
"hostPort": 8080,
"containerPort": 8080
}
]
},
{
"name": "kafka",
"image": "wurstmeister/kafka:latest",
"essential": false,
"portMappings": [
{
"hostPort": 9092,
"containerPort": 9092
}
],
"environment": [
{
"name": "KAFKA_ADVERTISED_LISTENERS",
"value": "INSIDE://kafka:9092,OUTSIDE://localhost:9092"
},
{
"name": "KAFKA_LISTENER_SECURITY_PROTOCOL_MAP",
"value": "INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT"
},
{
"name": "KAFKA_INTER_BROKER_LISTENER_NAME",
"value": "INSIDE"
},
{
"name": "KAFKA_ZOOKEEPER_CONNECT",
"value": "zookeeper:2181"
}
],
"links": [
"zookeeper"
]
},
{
"name": "zookeeper",
"image": "wurstmeister/zookeeper:latest",
"essential": false,
"portMappings": [
{
"hostPort": 2181,
"containerPort": 2181
}
]
},
{
"name": "redis",
"image": "redis:latest",
"essential": false,
"portMappings": [
{
"hostPort": 6379,
"containerPort": 6379
}
]
},
{
"name": "mongo",
"image": "mongo:latest",
"essential": false,
"portMappings": [
{
"hostPort": 27017,
"containerPort": 27017
}
]
}
]
}
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'java'
id 'org.springframework.boot' version '3.0.6'
id 'io.spring.dependency-management' version '1.1.0'
id 'com.google.cloud.tools.jib' version '3.4.0'
}

group = 'com.example'
Expand Down Expand Up @@ -105,6 +106,12 @@ tasks.named("jar") {
enabled = false
}

if (project.hasProperty('dev')) {
apply from: project.file('profile-dev.gradle')
} else if (project.hasProperty('prod')) {
apply from: project.file('profile-prod.gradle')
}

clean {
delete file('src/main/generated')
}
37 changes: 37 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: '3.8'
services:
app:
image: 471112861132.dkr.ecr.ap-northeast-2.amazonaws.com/waggle-dev
ports:
- "8080:8080"
depends_on:
- kafka
- redis
- mongo

kafka:
image: wurstmeister/kafka:latest
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_LISTENERS: INSIDE://kafka:9092,OUTSIDE://localhost:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
depends_on:
- zookeeper

zookeeper:
image: wurstmeister/zookeeper:latest
ports:
- "2181:2181"

redis:
image: redis:latest
ports:
- "6379:6379"

mongo:
image: mongo:latest
ports:
- "27017:27017"
20 changes: 20 additions & 0 deletions profile-dev.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
jib {
from {
image = "amazoncorretto:17.0.4-al2"
platforms {
platform {
architecture = "amd64"
os = "linux"
}
}
}
to {
image = "471112861132.dkr.ecr.ap-northeast-2.amazonaws.com/waggle-dev"
tags = ["latest", "${project.name}-" + System.currentTimeMillis()]
}
container {
creationTime = "USE_CURRENT_TIMESTAMP"
jvmFlags = ['-Dspring.profiles.active=dev', '-XX:+UseContainerSupport']
ports = ['8080']
}
}
9 changes: 3 additions & 6 deletions src/main/java/com/example/waggle/global/util/DateUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import java.util.Locale;

public class DateUtil {
public static void main(String[] args) {

}

public static final int SEC = 60;
public static final int MIN = 60;
Expand All @@ -19,9 +16,9 @@ public static void main(String[] args) {

/**
* x초전, x분전, x시간 전m, x일 전, x개월전, x년전
*
* @param 날짜
* @return 분 표시
*
*/
public static String simpleStoryTimeFormat(LocalDateTime tempDate) {
long curTime = System.currentTimeMillis();
Expand All @@ -32,7 +29,7 @@ public static String simpleStoryTimeFormat(LocalDateTime tempDate) {

String msg = null;

if (diffTime < SEC){
if (diffTime < SEC) {
msg = diffTime + "초 전";
} else if ((diffTime /= SEC) < MIN) {
msg = diffTime + "분 전";
Expand All @@ -43,7 +40,7 @@ public static String simpleStoryTimeFormat(LocalDateTime tempDate) {
} else if ((diffTime /= DAY) < MONTH) {
msg = (diffTime) + "개월 전";
} else {
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
String curYear = sdf.format(curTime);
String passYear = sdf.format(tempDate);
int diffYear = Integer.parseInt(curYear) - Integer.parseInt(passYear);
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/example/waggle/global/util/MediaUtil.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package com.example.waggle.global.util;

import com.example.waggle.domain.board.persistence.entity.Board;
import com.example.waggle.global.service.aws.AwsS3Service;
import com.example.waggle.domain.member.persistence.entity.Member;
import com.example.waggle.domain.pet.persistence.entity.Pet;
import com.example.waggle.domain.schedule.persistence.entity.Team;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;

import com.example.waggle.global.service.aws.AwsS3Service;
import java.util.List;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@Component
public class MediaUtil {

private static final String SERVER_URI = "https://waggle-bucket.s3.ap-northeast-2.amazonaws.com/";
private static final String SERVER_URI = "https://waggle-dev-s3.s3.ap-northeast-2.amazonaws.com/";
private static final String DEFAULT_MEMBER_PROFILE_IMG = "6d40e0b9-e675-45ce-ad84-c2032bfbb185.png";
private static final String DEFAULT_PET_PROFILE_IMG = "1c463c40-a8df-405b-bbda-7b8c3763d886.png";

Expand Down
Loading

0 comments on commit e95f1f9

Please sign in to comment.