Skip to content

Commit

Permalink
šŸ’š ci/cd: ė°°ķ¬ ķ™˜ź²½ źµ¬ģ¶• (#61)
Browse files Browse the repository at this point in the history
šŸ’š ci/cd: ė°°ķ¬ ķ™˜ź²½ źµ¬ģ¶• (#61)
  • Loading branch information
DDonghyeo authored May 23, 2024
2 parents 7b28c99 + 22e601f commit 99986d5
Show file tree
Hide file tree
Showing 22 changed files with 466 additions and 7 deletions.
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}
89 changes: 89 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
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

zookeeper:
image: wurstmeister/zookeeper:latest
container_name: zookeeper
ports:
- "2181:2181"
-
kafka:
image: wurstmeister/kafka:latest
container_name: kafka
ports:
- "9092:9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: 127.0.0.1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
volumes:
- /var/run/docker.sock:/var/run/docker.sock
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"]
Loading

0 comments on commit 99986d5

Please sign in to comment.