Skip to content

Commit

Permalink
Merge pull request #115 from Project-NextPage/set/#114
Browse files Browse the repository at this point in the history
set : CI 구축
  • Loading branch information
kanguk01 authored Jun 19, 2024
2 parents fd97f49 + 2235e79 commit 5eb0b48
Show file tree
Hide file tree
Showing 4 changed files with 237 additions and 21 deletions.
109 changes: 109 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: CI

on:
push:
branches:
- main
- develop
pull_request:
branches:
- develop

jobs:
build-and-test:
runs-on: ubuntu-22.04

services:
postgres:
image: postgres:12.0-alpine
env:
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
POSTGRES_USER: ${{ secrets.POSTGRES_USERNAME }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-2${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-${{ runner.os }}-
- name: Create .env file
run: |
echo "POSTGRES_URL=jdbc:postgresql://localhost:5432/${{ secrets.POSTGRES_DB }}" >> src/main/resources/env.properties
echo "POSTGRES_USERNAME=${{ secrets.POSTGRES_USERNAME }}" >> src/main/resources/env.properties
echo "POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}" >> src/main/resources/env.properties
echo "NEO4J_URI=${{ secrets.SPRING_NEO4J_URI }}" >> src/main/resources/env.properties
echo "NEO4J_USERNAME=neo4j" >> src/main/resources/env.properties
echo "NEO4J_PASSWORD=${{ secrets.SPRING_NEO4J_PASSWORD }}" >> src/main/resources/env.properties
echo "AWS_SECRET_KEY=${{ secrets.AWS_SECRET_KEY }}" >> src/main/resources/env.properties
echo "AWS_ACCESS_KEY=${{ secrets.AWS_ACCESS_KEY }}" >> src/main/resources/env.properties
echo "AWS_BUCKET=${{ secrets.AWS_BUCKET }}" >> src/main/resources/env.properties
echo "NAVER_CLIENT_ID=${{ secrets.NAVER_CLIENT_ID }}" >> src/main/resources/env.properties
echo "NAVER_CLIENT_SECRET=${{ secrets.NAVER_CLIENT_SECRET }}" >> src/main/resources/env.properties
echo "NAVER_REDIRECT_URI=${{ secrets.NAVER_REDIRECT_URI }}" >> src/main/resources/env.properties
echo "GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }}" >> src/main/resources/env.properties
echo "GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }}" >> src/main/resources/env.properties
echo "JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }}" >> src/main/resources/env.properties
echo "JWT_EXPIRE_LENGTH=${{ secrets.JWT_EXPIRE_LENGTH }}" >> src/main/resources/env.properties
echo "GPT_API_KEY=${{ secrets.GPT_API_KEY }}" >> src/main/resources/env.properties
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'

- name: Wait for PostgreSQL to be ready
run: |
for i in {30..0}; do
if docker exec $(docker ps -q --filter name=postgres) pg_isready -U ${{ secrets.POSTGRES_USERNAME }} -d ${{ secrets.POSTGRES_DB }}; then
echo "PostgreSQL is ready"
break
fi
echo "Waiting for PostgreSQL..."
sleep 1
done
if [ $i -eq 0 ]; then
echo "PostgreSQL did not become ready in time"
docker logs $(docker ps -q --filter name=postgres)
exit 1
fi
- name: Build with Gradle
run: ./gradlew build

- name: Run Tests
run: ./gradlew test
env:
POSTGRES_URL: jdbc:postgresql://localhost:5432/${{ secrets.POSTGRES_DB }}
POSTGRES_USERNAME: ${{ secrets.POSTGRES_USERNAME }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
NEO4J_URI: ${{ secrets.SPRING_NEO4J_URI }}
NEO4J_USERNAME: neo4j
NEO4J_PASSWORD: ${{ secrets.SPRING_NEO4J_PASSWORD }}
AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }}
AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
AWS_BUCKET: ${{ secrets.AWS_BUCKET }}
NAVER_CLIENT_ID: ${{ secrets.NAVER_CLIENT_ID }}
NAVER_CLIENT_SECRET: ${{ secrets.NAVER_CLIENT_SECRET }}
NAVER_REDIRECT_URI: ${{ secrets.NAVER_REDIRECT_URI }}
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
JWT_SECRET_KEY: ${{ secrets.JWT_SECRET_KEY }}
JWT_EXPIRE_LENGTH: ${{ secrets.JWT_EXPIRE_LENGTH }}
GPT_API_KEY: ${{ secrets.GPT_API_KEY }}
90 changes: 90 additions & 0 deletions .github/workflows/ciwithreport.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: CI with Coverage

on:
workflow_dispatch:

jobs:
build-and-test-with-coverage:
runs-on: ubuntu-22.04
services:
postgres:
image: postgres:12.0-alpine
env:
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
POSTGRES_USER: ${{ secrets.POSTGRES_USERNAME }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-${{ runner.os }}-
- name: Create .env file
run: |
echo $SECRETS_CONTEXT | jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' > src/main/resources/env.properties
env:
SECRETS_CONTEXT: ${{ toJson(secrets) }}

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

- name: Wait for PostgreSQL to be ready
run: |
for i in {30..0}; do
if docker exec $(docker ps -q --filter name=postgres) pg_isready -U $POSTGRES_USER -d $POSTGRES_DB; then
echo "PostgreSQL is ready"
break
fi
echo "Waiting for PostgreSQL..."
sleep 1
done
if [ $i -eq 0 ]; then
echo "PostgreSQL did not become ready in time"
docker logs $(docker ps -q --filter name=postgres)
exit 1
fi
env:
POSTGRES_USER: ${{ secrets.POSTGRES_USERNAME }}
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}

- name: Build with Gradle
run: ./gradlew build

- name: Run Tests with Coverage
run: ./gradlew test jacocoTestReport
env:
SECRETS_CONTEXT: ${{ toJson(secrets) }}
$(echo $SECRETS_CONTEXT | jq -r 'to_entries|map("export \(.key)=\(.value|tostring)")|.[]')

- name: Store test results
if: always()
uses: actions/upload-artifact@v2
with:
name: test-results
path: build/test-results/test

- name: Store coverage results
if: always()
uses: actions/upload-artifact@v2
with:
name: coverage-report
path: build/reports/jacoco/test/html
19 changes: 18 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id 'io.spring.dependency-management' version '1.1.4'
id 'org.hibernate.orm' version '6.4.4.Final'
id 'org.graalvm.buildtools.native' version '0.9.28'
id 'jacoco'
}

group = 'com'
Expand Down Expand Up @@ -85,4 +86,20 @@ hibernate {
enhancement {
enableAssociationManagement = true
}
}
}

jacoco {
toolVersion = "0.8.7"
}

test {
finalizedBy jacocoTestReport
}

jacocoTestReport {
reports {
xml.required = true
html.required = true
}
}

40 changes: 20 additions & 20 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,26 @@ services:
- npage

# 스프링 로컬로 실행 시 주석 처리하고 DB만 도커 빌드
springboot:
build:
context: .
dockerfile: Dockerfile
restart: always
depends_on:
- neo4j
- postgresql
ports:
- 8080:8080
container_name: springboot
environment:
SPRING_DATASOURCE_URL: ${SPRING_DATASOURCE_URL}
SPRING_DATASOURCE_USERNAME: ${SPRING_DATASOURCE_USERNAME}
SPRING_DATASOURCE_PASSWORD: ${SPRING_DATASOURCE_PASSWORD}
SPRING_PROFILES_ACTIVE: ${SPRING_PROFILES_ACTIVE}
NEO4J_URI: ${SPRING_NEO4J_URI}
NEO4J_PASSWORD: ${SPRING_NEO4J_PASSWORD}
networks:
- npage
# springboot:
# build:
# context: .
# dockerfile: Dockerfile
# restart: always
# depends_on:
# - neo4j
# - postgresql
# ports:
# - 8080:8080
# container_name: springboot
# environment:
# SPRING_DATASOURCE_URL: ${SPRING_DATASOURCE_URL}
# SPRING_DATASOURCE_USERNAME: ${SPRING_DATASOURCE_USERNAME}
# SPRING_DATASOURCE_PASSWORD: ${SPRING_DATASOURCE_PASSWORD}
# SPRING_PROFILES_ACTIVE: ${SPRING_PROFILES_ACTIVE}
# NEO4J_URI: ${SPRING_NEO4J_URI}
# NEO4J_PASSWORD: ${SPRING_NEO4J_PASSWORD}
# networks:
# - npage

# Monitoring
grafana:
Expand Down

0 comments on commit 5eb0b48

Please sign in to comment.