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: 3 additions & 5 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches: [ develop, main ]

env:
DOCKER_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/tech-blog
DOCKER_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/tech-fork

jobs:
docker-build:
Expand All @@ -21,7 +21,7 @@ jobs:
- name: Download JAR from CI
uses: actions/download-artifact@v4
with:
name: tech-blog-jar
name: tech-fork-jar
path: build/libs/
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
Expand Down Expand Up @@ -51,8 +51,6 @@ jobs:
DB_URL: ${{ secrets.DB_URL }}
DB_USERNAME: ${{ secrets.DB_USERNAME }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
REDIS_HOST: redis
REDIS_PORT: 6379
REDIS_PASSWORD: ${{ secrets.REDIS_PASSWORD }}

steps:
Expand All @@ -74,7 +72,7 @@ jobs:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
envs: DOCKER_IMAGE,BRANCH,SPRING_PROFILES_ACTIVE,DB_URL,DB_USERNAME,DB_PASSWORD,REDIS_HOST,REDIS_PORT,REDIS_PASSWORD
envs: DOCKER_IMAGE,BRANCH,SPRING_PROFILES_ACTIVE,DB_URL,DB_USERNAME,DB_PASSWORD,REDIS_PASSWORD
script: |
cd ~/deploy
chmod +x deploy.sh
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ jobs:
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: tech-blog-jar
name: tech-fork-jar
path: build/libs/*.jar
retention-days: 3
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ dependencies {
// implementation 'org.springframework.boot:spring-boot-starter-security'
// testImplementation 'org.springframework.security:spring-security-test'

// implementation 'org.springframework.boot:spring-boot-starter-data-elasticsearch'
implementation 'org.springframework.boot:spring-boot-starter-data-elasticsearch'
// implementation 'org.springframework.ai:spring-ai-advisors-vector-store'
// implementation 'org.springframework.ai:spring-ai-starter-vector-store-elasticsearch'

Expand Down
33 changes: 28 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3.8'
services:
app:
image: ${DOCKER_IMAGE}:${BRANCH}
container_name: tech-blog-app
container_name: tech-fork-app
restart: always
ports:
- "8080:8080"
Expand All @@ -12,17 +12,16 @@ services:
- DB_URL=${DB_URL}
- DB_USERNAME=${DB_USERNAME}
- DB_PASSWORD=${DB_PASSWORD}
- REDIS_HOST=${REDIS_HOST}
- REDIS_PORT=${REDIS_PORT}
- REDIS_PASSWORD=${REDIS_PASSWORD}
networks:
- app-network
depends_on:
- redis
- elasticsearch

redis:
image: redis:7-alpine
container_name: tech-blog-redis
container_name: tech-fork-redis
restart: always
ports:
- "6379:6379"
Expand All @@ -32,9 +31,33 @@ services:
volumes:
- redis-data:/data

elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.11.0
container_name: tech-fork-elasticsearch
restart: always
ports:
- "9200:9200"
- "9300:9300"
environment:
- discovery.type=single-node
- xpack.security.enabled=false
- "ES_JAVA_OPTS=-Xms1g -Xmx1g"
networks:
- app-network
volumes:
- elasticsearch-data:/usr/share/elasticsearch/data
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536

networks:
app-network:
driver: bridge

volumes:
redis-data:
redis-data:
elasticsearch-data:
33 changes: 23 additions & 10 deletions infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,29 @@ resource "aws_instance" "app" {
amazon-linux-extras install -y nginx1

echo "===== Create Application Directories ====="
mkdir -p /opt/tech-blog
mkdir -p /var/log/tech-blog
mkdir -p /opt/tech-fork
mkdir -p /var/log/tech-fork

useradd -r -s /bin/false tech-blog || true
chown -R tech-blog:tech-blog /opt/tech-blog
chown -R tech-blog:tech-blog /var/log/tech-blog
useradd -r -s /bin/false tech-fork || true
chown -R tech-fork:tech-fork /opt/tech-fork
chown -R tech-fork:tech-fork /var/log/tech-fork

echo "===== Install Git ====="
yum install -y git

echo "===== Install Docker ====="
yum install -y docker
systemctl start docker
systemctl enable docker
usermod -aG docker ec2-user

echo "===== Install Docker Compose ====="
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

echo "===== Nginx Configuration ====="
cat > /etc/nginx/conf.d/tech-blog.conf <<'NGINX'
cat > /etc/nginx/conf.d/tech-fork.conf <<'NGINX'
upstream springapp {
server 127.0.0.1:8080 fail_timeout=0;
}
Expand All @@ -267,8 +278,8 @@ resource "aws_instance" "app" {

client_max_body_size 10M;

access_log /var/log/nginx/tech-blog-access.log;
error_log /var/log/nginx/tech-blog-error.log;
access_log /var/log/nginx/tech-fork-access.log;
error_log /var/log/nginx/tech-fork-error.log;

# Cloudflare Real IP
set_real_ip_from 173.245.48.0/20;
Expand Down Expand Up @@ -365,7 +376,7 @@ resource "aws_instance" "app" {
"files": {
"collect_list": [
{
"file_path": "/var/log/tech-blog/*.log",
"file_path": "/var/log/tech-fork/*.log",
"log_group_name": "/aws/ec2/${var.project_name}-${var.environment}/application",
"log_stream_name": "{instance_id}",
"timezone": "Asia/Seoul"
Expand All @@ -377,7 +388,7 @@ resource "aws_instance" "app" {
"timezone": "Asia/Seoul"
},
{
"file_path": "/var/log/nginx/tech-blog-*.log",
"file_path": "/var/log/nginx/tech-fork-*.log",
"log_group_name": "/aws/ec2/${var.project_name}-${var.environment}/nginx",
"log_stream_name": "{instance_id}",
"timezone": "Asia/Seoul"
Expand All @@ -402,6 +413,8 @@ resource "aws_instance" "app" {
touch /var/log/user-data-complete.txt
EOF

user_data_replace_on_change = true

tags = {
Name = "${var.project_name}-${var.environment}-app-server"
}
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/techfork/global/config/ElasticsearchConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.techfork.global.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.elc.ElasticsearchConfiguration;

@Configuration
public class ElasticsearchConfig extends ElasticsearchConfiguration {

@Value("${elasticsearch.host:localhost}")
private String elasticsearchHost;

@Value("${elasticsearch.port:9200}")
private int elasticsearchPort;

@Override
public ClientConfiguration clientConfiguration() {
return ClientConfiguration.builder()
.connectedTo(elasticsearchHost + ":" + elasticsearchPort)
.build();
}
}
6 changes: 5 additions & 1 deletion src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ spring:
max-active: 16
max-idle: 8
min-idle: 0
max-wait: 5s
max-wait: 5s

elasticsearch:
host: elasticsearch
port: 9200