Skip to content
Open
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
250 changes: 166 additions & 84 deletions .github/workflows/backend-cd.yml
Original file line number Diff line number Diff line change
@@ -1,84 +1,166 @@
name: ✨ Linkiving backend CD ✨

on:
workflow_dispatch:
pull_request:
types: [ closed ]
branches:
- main

jobs:
backend-docker-build-and-push:
if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request' }}
runs-on: ubuntu-latest

steps:
- name: ✨ Checkout repository
uses: actions/checkout@v3

- name: ✨ JDK 17 설정
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: ✨ Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

- name: 🗂️ Make config
run: |
# src/main/resources 경로 이동
mkdir -p ./src/main/resources
cd ./src/main/resources

# yml 파일 생성

touch ./application.yml
echo "$APPLICATION" > ./application.yml

env:
APPLICATION: ${{ secrets.APPLICATION }}
shell: bash

- name: ✨ Gradlew 권한 설정
run: chmod +x ./gradlew

- name: ✨ Jar 파일 빌드
run: |
./gradlew bootJar

- name: ✨ DockerHub에 로그인
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}

- name: ✨ Docker Image 빌드 후 DockerHub에 Push
uses: docker/build-push-action@v4
with:
context: .
file: ./docker/Dockerfile
push: true
platforms: linux/amd64
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPOSITORY }}:latest

backend-docker-pull-and-run:
runs-on: [ self-hosted, prod ]
needs: [ backend-docker-build-and-push ]
if: ${{ needs.backend-docker-build-and-push.result == 'success' && (github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true) }}

steps:
- name: ✨ Checkout repository
uses: actions/checkout@v5

- name: ✨ 배포 스크립트 실행
run: |
chmod +x deploy.sh
./deploy.sh
name: ✨ Linkiving backend local bundle CD ✨

on:
workflow_dispatch:
push:
branches:
- main
pull_request:
branches:
- main

permissions:
contents: read

concurrency:
group: backend-local-bundle-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build-local-bundle:
runs-on: ubuntu-latest

steps:
- name: ✨ Checkout repository
uses: actions/checkout@v5

- name: ✨ JDK 17 설정
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: ✨ Gradle caching
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

- name: 🗂️ Create local application profile
shell: bash
run: |
mkdir -p ./src/main/resources
cat <<'EOF' > ./src/main/resources/application-local.yml
spring:
datasource:
driver-class-name: org.postgresql.Driver
url: ${DB_URL:jdbc:postgresql://localhost:5432/linkiving_local}
username: ${DB_USERNAME:linkiving}
password: ${DB_PASSWORD:linkiving}

data:
redis:
host: ${REDIS_HOST:localhost}
port: ${REDIS_PORT:6379}
ssl:
enabled: ${REDIS_SSL_ENABLED:false}
repositories:
enabled: false

jpa:
database: postgresql
hibernate:
ddl-auto: update
show-sql: true
open-in-view: false
properties:
hibernate:
format_sql: true
use_sql_comments: true

security:
oauth2:
client:
registration:
google:
redirect-uri: ${GOOGLE_REDIRECT_URI:http://localhost:8080/login/oauth2/code/google}
client-id: ${GOOGLE_CLIENT_ID:local-google-client-id}
client-secret: ${GOOGLE_CLIENT_SECRET:local-google-client-secret}
scope:
- email
- profile
client-name: linkiving
authorization-grant-type: authorization_code

cloud:
aws:
s3:
bucket: ${AWS_S3_BUCKET:linkiving-local}
credentials:
access-key: ${AWS_ACCESS_KEY:local-access-key}
secret-key: ${AWS_SECRET_KEY:local-secret-key}
region:
static: ${AWS_REGION:ap-northeast-2}
stack:
auto: false

logging:
level:
org.hibernate.SQL: debug
org.hibernate.orm.jdbc.bind: trace

security:
jwt:
secret: ${JWT_SECRET:local-jwt-secret-local-jwt-secret-local-jwt-secret-local-jwt-secret}
access-token-valid-minute: 60
refresh-token-valid-month: 6

app:
oauth2:
success-redirect-url: http://localhost:3000/home
failure-redirect-url: http://localhost:3000/
cors:
allowed-origins:
- http://localhost:3000
extension-allowed-origins:
- ${CHROME_EXTENSION_ORIGIN:chrome-extension://replace-me}
cookie:
domain: ${COOKIE_DOMAIN:}
link:
default-image-url: ${DEFAULT_IMAGE_URL:https://linkiving-s3.s3.ap-northeast-2.amazonaws.com/static/default-thumbnail.png}

feign:
client:
config:
default:
connectTimeout: 5000
readTimeout: 5000
loggerLevel: FULL

summary:
worker:
sleep-duration: 1s

ai:
server:
url: ${AI_SERVER_URL:http://api.linkiving.com:5678}

linkiving:
default-image:
url: "https://linkiving-s3.s3.ap-northeast-2.amazonaws.com/static/default-thumbnail.png"
EOF

- name: ✨ Executable permissions
run: chmod +x ./gradlew ./scripts/prepare-local-bundle.sh

- name: ✨ Jar 파일 빌드
run: ./gradlew bootJar

- name: 🐳 Build local Docker bundle
env:
BUNDLE_VERSION: ${{ github.event_name == 'pull_request' && format('pr-{0}-{1}', github.event.pull_request.number, github.sha) || format('main-{0}', github.sha) }}
IMAGE_TAG: linkiving-local:${{ github.sha }}
run: ./scripts/prepare-local-bundle.sh

- name: 📦 Upload local bundle artifact
uses: actions/upload-artifact@v4
with:
name: linkiving-core-local-bundle-${{ github.run_number }}
path: |
dist/*.zip
dist/*.sha256
retention-days: 14
93 changes: 93 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: 🚀 Linkiving backend release deploy 🚀

on:
push:
tags:
- 'v*'

permissions:
contents: write

concurrency:
group: backend-release-${{ github.ref }}
cancel-in-progress: false

jobs:
backend-docker-build-and-push:
runs-on: ubuntu-latest

steps:
- name: ✨ Checkout repository
uses: actions/checkout@v5

- name: ✨ JDK 17 설정
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: ✨ Gradle caching
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

- name: 🗂️ Make production config
shell: bash
env:
APPLICATION: ${{ secrets.APPLICATION }}
run: |
mkdir -p ./src/main/resources
printf '%s' "$APPLICATION" > ./src/main/resources/application.yml

- name: ✨ Gradlew 권한 설정
run: chmod +x ./gradlew

- name: ✨ Jar 파일 빌드
run: ./gradlew bootJar

- name: ✨ DockerHub에 로그인
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}

- name: ✨ Docker image 빌드 후 DockerHub에 push
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/Dockerfile
push: true
platforms: linux/amd64
tags: |
${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPOSITORY }}:${{ github.ref_name }}
${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPOSITORY }}:latest

backend-docker-pull-and-run:
runs-on: [ self-hosted, prod ]
needs: [ backend-docker-build-and-push ]
if: ${{ needs.backend-docker-build-and-push.result == 'success' }}

steps:
- name: ✨ Checkout repository
uses: actions/checkout@v5

- name: ✨ 배포 스크립트 실행
run: |
chmod +x deploy.sh
./deploy.sh

create-release:
runs-on: ubuntu-latest
needs: [ backend-docker-pull-and-run ]
if: ${{ needs.backend-docker-pull-and-run.result == 'success' }}

steps:
- name: 📝 Create GitHub release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ out/

### Spring
*.yml
!.github/workflows/*.yml
!docker/local-bundle/*.yml
.editorconfig
6 changes: 6 additions & 0 deletions docker/local-bundle/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM amazoncorretto:17-alpine-jdk

COPY app.jar /app.jar

EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app.jar"]
25 changes: 25 additions & 0 deletions docker/local-bundle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# linkiving-core local bundle

## Included files

- `docker-compose.yml`
- `linkiving-core-local-image.tar.gz`

## Run

```bash
docker load -i linkiving-core-local-image.tar.gz
docker compose up -d
```

## Verify

```bash
curl -fsS http://localhost:8080/health-check
```

## Stop

```bash
docker compose down -v
```
Loading
Loading