Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐Ÿ’š ci/cd: ๋ฐฐํฌ ํ™˜๊ฒฝ ๊ตฌ์ถ• (#61) #62

Merged
merged 30 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9511718
๐Ÿ“docs : config-service environment
DDonghyeo May 23, 2024
6ce0640
๐Ÿ“docs : modified api-gateway's port
DDonghyeo May 23, 2024
0b15260
๐Ÿ“docs : ์‰˜ ์Šคํฌ๋ฆฝํŠธ ์ž‘์„ฑ
DDonghyeo May 23, 2024
84cd889
๐Ÿ“docs : docker-compose ๊ตฌ์„ฑ
DDonghyeo May 23, 2024
d8583ee
Create ci.yml
DDonghyeo May 23, 2024
a7fd8d5
๐Ÿ“docs : CI ํ…Œ์ŠคํŠธ
DDonghyeo May 23, 2024
550bdd8
๐Ÿ“docs : Update apiDocs.yml
DDonghyeo May 23, 2024
f941c1a
๐Ÿ“docs : Update apiDocs.yml
DDonghyeo May 23, 2024
04187d8
๐Ÿ“docs : Update ci.yml
DDonghyeo May 23, 2024
c920b5b
๐Ÿ“docs : Update ci.yml
DDonghyeo May 23, 2024
ad08b78
๐Ÿ“docs : Update ci.yml
DDonghyeo May 23, 2024
d67fca2
๐Ÿ“docs : Update ci.yml
DDonghyeo May 23, 2024
6f920db
๐Ÿ“docs : Update ci.yml
DDonghyeo May 23, 2024
59b9a45
๐Ÿ“docs : Update ci.yml
DDonghyeo May 23, 2024
4c71e29
๐Ÿ“docs : ci.yml Complete
DDonghyeo May 23, 2024
b8e2915
๐Ÿ“docs : build.gradle jar disabled
DDonghyeo May 23, 2024
886471d
๐Ÿ“docs : Dockerfile
DDonghyeo May 23, 2024
0a0ec8d
๐Ÿ“docs : Create cd.yml
DDonghyeo May 23, 2024
a9a6203
๐Ÿ“docs : Dockerfile ์ˆ˜์ •
DDonghyeo May 23, 2024
506c1e3
๐Ÿ“docs : Update cd.yml
DDonghyeo May 23, 2024
68d1522
๐Ÿ“ Update cd.yml
DDonghyeo May 23, 2024
7a9d8c8
๐Ÿ“docs: Update cd.yml
DDonghyeo May 23, 2024
d19caff
๐Ÿ“docs : Update cd.yml
DDonghyeo May 23, 2024
44f0a24
๐Ÿ“docs : Update cd.yml removed space
DDonghyeo May 23, 2024
5532fe8
๐Ÿ“docs : Update cd.yml
DDonghyeo May 23, 2024
1f16faf
๐Ÿ“docs : deploy.sh ์ˆ˜์ •
DDonghyeo May 23, 2024
1b336bc
๐Ÿ“docs : Complete script
DDonghyeo May 23, 2024
d9a377f
๐Ÿ“docs : Update cd.yml
DDonghyeo May 23, 2024
85c82d5
โ™ป๏ธ refactor : Exclude DataSource
DDonghyeo May 23, 2024
22e601f
๐Ÿ“docs : Zookeeper, Kafka ํ™˜๊ฒฝ ์ถ”๊ฐ€
DDonghyeo May 23, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/apiDocs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: API Docs Integration
name: api-docs-integration

on:
push:
Expand Down
143 changes: 143 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
name: Backend CI/CD with Gradle

on:
# workflow_dispatch:
# inputs:
# service:
# description: 'Choose Service to deploy. Default is all.'
# required: true
# default: 'all'
# type: choice
# options:
# - all
# - api-gateway
# - noti-service
# - user-service
# - weather-service
push:
branches:
- prod

jobs:
build:
runs-on: ubuntu-latest

#Checkout : ์ฝ”๋“œ ๊ฐ€์ ธ์˜ค๊ธฐ
steps:
- name: Checkout
uses: actions/checkout@v3

#Setting JDK
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'temurin'

#gradlew chmod
- name: Grant execute permission for gradlew
run: |
chmod +x ./apiGateway-service/gradlew
chmod +x ./config-service/gradlew
chmod +x ./Eureka/gradlew
chmod +x ./noti-service/gradlew
chmod +x ./user-service/gradlew
chmod +x ./weather-service/gradlew

# DockerHub Login
- name: Docker Hub Login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

#Config-Service Build & Docker Push
- name: Build with Gradle - config
run: |
cd config-service
./gradlew clean build -x test
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/waither-config .
docker push ${{ secrets.DOCKERHUB_USERNAME }}/waither-config
env:
CONFIG_GIT_URI: ${{ secrets.CONFIG_GIT_URI }}
CONFIG_PASSPHRASE: ${{ secrets.CONFIG_PASSPHRASE }}
CONFIG_PRIVATE_KEY: ${{ secrets.CONFIG_PRIVATE_KEY }}

#Config-Service Run
- name: Run config-service
run: |
./gradlew bootRun &
cd ..
#Wait 5 sec
- name: Wait for config-service to start
run: sleep 5

#apiGateway-Service Build & Docker Push
- name: Build with Gradle - apiGateway
run: |
cd apiGateway-service
./gradlew clean build -x test
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/waither-gateway .
docker push ${{ secrets.DOCKERHUB_USERNAME }}/waither-gateway
cd ..

#Eureka Build & Docker Push
- name: Build with Gradle - Eureka
run: |
cd Eureka
./gradlew clean build -x test
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/waither-eureka .
docker push ${{ secrets.DOCKERHUB_USERNAME }}/waither-eureka
cd ..

#Noti-Service Build & Docker Push
- name: Build with Gradle - noti-service
run: |
cd noti-service
./gradlew clean build -x test
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/waither-noti .
docker push ${{ secrets.DOCKERHUB_USERNAME }}/waither-noti
cd ..

#User-Service Build & Docker Push
- name: Build with Gradle - user-service
run: |
cd user-service
./gradlew clean build -x test
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/waither-user .
docker push ${{ secrets.DOCKERHUB_USERNAME }}/waither-user
cd ..

#Weather-Service Build & Docker Push
- name: Build with Gradle - weather-service
run: |
cd weather-service
./gradlew clean build -x test
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/waither-weather .
docker push ${{ secrets.DOCKERHUB_USERNAME }}/waither-weather
cd ..

deploy:
name : Connect to EC2 and re-run container
needs : build
runs-on : ubuntu-latest
steps:
- name: Deploy to Server
uses: appleboy/[email protected]
env:
SERVICE_NAME: all
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
password: ${{ secrets.EC2_PASSWORD }}
port: ${{ secrets.EC2_SSH_PORT }}
timeout: 60s
script: |
export CONFIG_GIT_URI=${{ secrets.CONFIG_GIT_URI }}
export CONFIG_PASSPHRASE=${{ secrets.CONFIG_PASSPHRASE }}
export CONFIG_PRIVATE_KEY=${{ secrets.CONFIG_PRIVATE_KEY_DIR }}
export DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}

bash /home/docker_init.sh
bash /home/common.sh
bash /home/deploy.sh
63 changes: 63 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Backend CI

on:
pull_request:
branches:
- prod
- develop

jobs:
build-test:
runs-on: ubuntu-latest

steps:
- name: action checkout
uses: actions/checkout@v3

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

- name: Grant execute permission for gradlew
run: |
chmod +x ./config-service/gradlew
chmod +x ./noti-service/gradlew
chmod +x ./user-service/gradlew
chmod +x ./weather-service/gradlew

- name: Build with Gradle - config
run: |
cd config-service
./gradlew clean build -x test
env:
CONFIG_GIT_URI: ${{ secrets.CONFIG_GIT_URI }}
CONFIG_PASSPHRASE: ${{ secrets.CONFIG_PASSPHRASE }}
CONFIG_PRIVATE_KEY: ${{ secrets.CONFIG_PRIVATE_KEY }}

- name: Run config-service
run: |
./gradlew bootRun &
cd ..

- name: Wait for config-service to start
run: sleep 5

- name: Build with Gradle - noti-service
run: |
cd noti-service
./gradlew clean build -x test
cd ..

- name: Build with Gradle - user-service
run: |
cd user-service
./gradlew clean build -x test
cd ..

- name: Build with Gradle - weather-service
run: |
cd weather-service
./gradlew clean build -x test
cd ..
5 changes: 5 additions & 0 deletions Eureka/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM openjdk:17-jdk

ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java", "-Dspring.profiles.active=prod", "-Duser.timezone=Asia/Seoul" , "-jar", "app.jar"]
4 changes: 4 additions & 0 deletions Eureka/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ java {
sourceCompatibility = '17'
}

jar {
enabled = false
}

repositories {
mavenCentral()
}
Expand Down
5 changes: 5 additions & 0 deletions apiGateway-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM openjdk:17-jdk

ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java", "-Dspring.profiles.active=prod", "-Duser.timezone=Asia/Seoul" , "-jar", "app.jar"]
4 changes: 4 additions & 0 deletions apiGateway-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ java {
sourceCompatibility = '17'
}

jar {
enabled = false
}

repositories {
mavenCentral()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

@SpringBootApplication
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class ApiGatewayServiceApplication {

public static void main(String[] args) {
Expand Down
2 changes: 1 addition & 1 deletion apiGateway-service/src/main/resources/bootstrap.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
server:
port: 8000
port: 80

spring:
application:
Expand Down
5 changes: 5 additions & 0 deletions config-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM openjdk:17-jdk

ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java", "-Dspring.profiles.active=prod", "-Duser.timezone=Asia/Seoul" , "-jar", "app.jar"]
4 changes: 4 additions & 0 deletions config-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ java {
sourceCompatibility = '17'
}

jar {
enabled = false
}

repositories {
mavenCentral()
}
Expand Down
10 changes: 9 additions & 1 deletion config-service/src/main/resources/bootstrap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@ spring:
profiles:
active: dev
application:
name: config-service
name: config-service
cloud:
config:
server:
git:
uri: ${CONFIG_GIT_URI}
ignore-local-ssh-settings: true
passphrase: ${CONFIG_PASSPHRASE}
private-key: ${CONFIG_PRIVATE_KEY}
74 changes: 74 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
version: '3'

services:

# nginx:
# container_name: nginx
# image: nginx:latest
# ports:
# - "80:80"
# volumes:
# - /home/ec2-user/nginx.conf:/etc/nginx/nginx.conf
# depends_on:
# - "db"
# restart: always #ํ•ญ์ƒ ์žฌ์‹คํ–‰

api-gateway:
container_name: api-gateway
image: ${DOCKERHUB_USERNAME}/waither-gateway
expose:
- "8000"
restart: always
volumes:
- /home/ec2-user/logs/api-gateway:/logs

config:
container_name: config
image: ${DOCKERHUB_USERNAME}/waither-config
expose:
- "8888"
environment:
CONFIG_GIT_URI : ${CONFIG_GIT_URI}
CONFIG_PASSPHRASE : ${CONFIG_PASSPHRASE}
CONFIG_PRIVATE_KEY : ${CONFIG_PRIVATE_KEY}
restart: always
volumes:
- /home/ec2-user/logs/config:/logs

eureka:
container_name: eureka
image: ${DOCKERHUB_USERNAME}/waither-eureka
expose:
- "8761"
restart: always
volumes:
- /home/ec2-user/logs/eureka:/logs

user-service:
container_name: user-service
image: ${DOCKERHUB_USERNAME}/waither-user
expose:
- "8080"
restart: unless-stopped #์ˆ˜๋™์œผ๋กœ ์ค‘์ง€๋˜์ง€ ์•Š๋Š” ์ด์ƒ ํ•ญ์ƒ ์žฌ์‹คํ–‰
volumes:
- /home/ec2-user/logs/user-service:/logs

weather-service:
container_name: weather-service
image: ${DOCKERHUB_USERNAME}/waither-weather
expose:
- "8081"
restart: unless-stopped
volumes:
- /home/ec2-user/logs/weather-service:/logs

noti-service:
container_name: noti-service
image: ${DOCKERHUB_USERNAME}/waither-noti
expose:
- "8082"
restart: unless-stopped
volumes:
- /home/ec2-user/logs/noti-service:/logs


5 changes: 5 additions & 0 deletions noti-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM openjdk:17-jdk

ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java", "-Dspring.profiles.active=prod", "-Duser.timezone=Asia/Seoul" , "-jar", "app.jar"]
4 changes: 4 additions & 0 deletions noti-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ java {
sourceCompatibility = '17'
}

jar {
enabled = false
}

repositories {
mavenCentral()
}
Expand Down
Loading
Loading