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

CICD: 배포, 개발계 분리 적용 #238

Merged
merged 7 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 2 additions & 0 deletions .github/workflows/database.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
with:
host: ${{secrets.SSH_HOST}}
username: ${{secrets.SSH_USER}}
port: ${{secrets.SSH_PORT}}
key: ${{secrets.SSH_KEY}}
source: "docker-compose-db.yml, .env"
target: "~/app"
Expand All @@ -44,6 +45,7 @@ jobs:
with:
host: ${{secrets.SSH_HOST}}
username: ${{secrets.SSH_USER}}
port: ${{secrets.SSH_PORT}}
key: ${{secrets.SSH_KEY}}
script: |
cd ~/app
Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/database_dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
on:
push:
branches:
- develop
paths:
- docker-compose-db.yml
- db_config/*
- .github/workflows/database.yaml

jobs:
database-deploy:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read

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

-
name: Create .env file
run: |
echo "MYSQL_ROOT_PASSWORD=${{secrets.MYSQL_ROOT_PASSWORD}}" > .env
echo "MYSQL_USER=${{secrets.MYSQL_USER}}" >> .env
echo "MYSQL_PASSWORD=${{secrets.MYSQL_PASSWORD}}" >> .env
echo "MYSQL_DATABASE=${{secrets.MYSQL_DATABASE}}" >> .env

-
name: SCP Command to Transfer Files
uses: appleboy/scp-action@v0.1.4
with:
host: ${{secrets.SSH_HOST_DEV}}
username: ${{secrets.SSH_USER}}
key: ${{secrets.SSH_KEY}}
source: "docker-compose-db.yml, .env"
target: "~/app"
overwrite: true

-
name: SSH Remote Commands
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{secrets.SSH_HOST_DEV}}
username: ${{secrets.SSH_USER}}
key: ${{secrets.SSH_KEY}}
script: |
cd ~/app
source .env
docker-compose -f docker-compose-db.yml down
docker-compose -f docker-compose-db.yml up -d
4 changes: 3 additions & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ jobs:
with:
host: ${{secrets.SSH_HOST}}
username: ${{secrets.SSH_USER}}
port: ${{secrets.SSH_PORT}}
key: ${{secrets.SSH_KEY}}
source: "docker-compose-backend.yml, .env"
target: "~/app"
Expand All @@ -77,8 +78,9 @@ jobs:
with:
host: ${{secrets.SSH_HOST}}
username: ${{secrets.SSH_USER}}
port: ${{secrets.SSH_PORT}}
key: ${{secrets.SSH_KEY}}
script: | # TODO: Change to blue-green deployment
script: |
cd ~/app
source .env
docker-compose -f docker-compose-backend.yml down
Expand Down
86 changes: 86 additions & 0 deletions .github/workflows/deploy_dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
on:
push:
branches:
- develop
paths:
- docker-compose-backend.yml
- Dockerfile
- gradle.properties
- gradlew
- gradlew.bat
- build.gradle.kts
- settings.gradle.kts
- src/**
- gradle/**
- .github/workflows/deploy.yaml

jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read

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

- name: Setup Java JDK
uses: actions/setup-java@v3.12.0
with:
java-version: '21'
distribution: 'temurin'

- run: ./gradlew clean bootJar -x test

- name: Log in to the Container Registry
uses: docker/login-action@v2.2.0
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}

- name: Build and push Docker image
uses: docker/build-push-action@v4.1.1
with:
context: .
push: true
build-args: |
PROFILE=prod
tags: |
ghcr.io/wafflestudio/csereal-server/server_image:latest
ghcr.io/wafflestudio/csereal-server/server_image:${{github.sha}}

- name: Create .env file
run: |
echo "MYSQL_ROOT_PASSWORD=${{secrets.MYSQL_ROOT_PASSWORD}}" > .env
echo "MYSQL_USER=${{secrets.MYSQL_USER}}" >> .env
echo "MYSQL_PASSWORD=${{secrets.MYSQL_PASSWORD}}" >> .env
echo "MYSQL_DATABASE=${{secrets.MYSQL_DATABASE}}" >> .env
echo "PROFILE=dev" >> .env
echo "OIDC_CLIENT_SECRET=${{secrets.OIDC_CLIENT_SECRET}}" >> .env
echo "URL=${{secrets.URL_DEV}}" >> .env
# echo "SLACK_TOKEN=${{secrets.SLACK_TOKEN}}" >> .env
# echo "SLACK_CHANNEL=${{secrets.SLACK_CHANNEL}}" >> .env

- name: SCP Command to Transfer Files
uses: appleboy/scp-action@v0.1.4
with:
host: ${{secrets.SSH_HOST_DEV}}
username: ${{secrets.SSH_USER}}
key: ${{secrets.SSH_KEY}}
source: "docker-compose-backend.yml, .env"
target: "~/app"
overwrite: true
- name: SSH Remote Commands
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{secrets.SSH_HOST_DEV}}
username: ${{secrets.SSH_USER}}
key: ${{secrets.SSH_KEY}}
script: |
cd ~/app
source .env
docker-compose -f docker-compose-backend.yml down
docker-compose -f docker-compose-backend.yml pull
docker-compose -f docker-compose-backend.yml up -d
2 changes: 2 additions & 0 deletions .github/workflows/proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
with:
host: ${{secrets.SSH_HOST}}
username: ${{secrets.SSH_USER}}
port: ${{secrets.SSH_PORT}}
key: ${{secrets.SSH_KEY}}
source: "docker-compose-caddy.yml, .env, caddy/Caddyfile"
target: "~/proxy"
Expand All @@ -39,6 +40,7 @@ jobs:
with:
host: ${{secrets.SSH_HOST}}
username: ${{secrets.SSH_USER}}
port: ${{secrets.SSH_PORT}}
key: ${{secrets.SSH_KEY}}
script: |
cd ~/proxy
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/proxy_dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
on:
push:
branches:
- develop
paths:
- docker-compose-caddy.yml
- caddy/Caddyfile
- .github/workflows/proxy.yaml

jobs:
proxy-initialize:
runs-on: ubuntu-latest

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

-
name: Create .env file
run: |
echo "URL=${{secrets.URL_DEV}}" > .env
echo "LOCAL_IP=${{secrets.LOCAL_IP_DEV}}" >> .env

-
name: SCP Command to Transfer Files
uses: appleboy/scp-action@v0.1.4
with:
host: ${{secrets.SSH_HOST_DEV}}
username: ${{secrets.SSH_USER}}
key: ${{secrets.SSH_KEY}}
source: "docker-compose-caddy.yml, .env, caddy/Caddyfile"
target: "~/proxy"
overwrite: true

-
name: SSH Command to Run Docker Compose
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{secrets.SSH_HOST_DEV}}
username: ${{secrets.SSH_USER}}
key: ${{secrets.SSH_KEY}}
script: |
cd ~/proxy
source .env
docker-compose -f docker-compose-caddy.yml down
docker-compose -f docker-compose-caddy.yml up -d
12 changes: 6 additions & 6 deletions caddy/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
abort @backend_denied

# Backend
reverse_proxy /api/* host.docker.internal:8080 #host.docker.internal:8081 # For blue/green
reverse_proxy /api/* host.docker.internal:8080

# Old file serving
reverse_proxy /sites/default/files/* host.docker.internal:8080 #host.docker.internal:8081 # For blue/green
reverse_proxy /sites/default/files/* host.docker.internal:8080

# Login
reverse_proxy /oauth2/authorization/idsnucse host.docker.internal:8080 #host.docker.internal:8081 # For blue/green
reverse_proxy /oauth2/authorization/idsnucse host.docker.internal:8080

# Swagger
reverse_proxy /swagger-ui/* host.docker.internal:8080 #host.docker.internal:8081 # For blue/green
reverse_proxy /api-docs/* host.docker.internal:8080 #host.docker.internal:8081 # For blue/green
}
reverse_proxy /swagger-ui/* host.docker.internal:8080
reverse_proxy /api-docs/* host.docker.internal:8080
}
22 changes: 0 additions & 22 deletions docker-compose-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,3 @@ services:
- host.docker.internal:host-gateway
restart: always
image: ghcr.io/wafflestudio/csereal-server/server_image:latest
# TODO: Activate after implementing health check
# blue:
# container_name: csereal_server_blue
# build:
# context: ./
# args:
# PROFILE: ${PROFILE}
# ports:
# - 8081:8080
# volumes:
# - ./cse-files:/app/cse-files
# - ./attachment:/app/attachment
# environment:
# SPRING_DATASOURCE_URL: "jdbc:mysql://host.docker.internal:3306/${MYSQL_DATABASE}?serverTimezone=Asia/Seoul&useSSL=false&allowPublicKeyRetrieval=true"
# SPRING_DATASOURCE_USERNAME: ${MYSQL_USER}
# SPRING_DATASOURCE_PASSWORD: ${MYSQL_PASSWORD}
# OIDC_CLIENT_SECRET_DEV: ${OIDC_CLIENT_SECRET_DEV}
# URL: ${URL}
# extra_hosts:
# - host.docker.internal:host-gateway
# restart: always
# image: ghcr.io/wafflestudio/csereal-server/server_image:latest
48 changes: 41 additions & 7 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ spring:
active: local
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
properties:
hibernate:
dialect: com.wafflestudio.csereal.common.config.MySQLDialectCustom
servlet:
multipart:
enabled: true
Expand Down Expand Up @@ -50,9 +54,6 @@ spring:
ddl-auto: update
show-sql: true
open-in-view: false
properties:
hibernate:
dialect: com.wafflestudio.csereal.common.config.MySQLDialectCustom
security:
oauth2:
client:
Expand Down Expand Up @@ -80,11 +81,8 @@ spring:
config.activate.on-profile: prod
jpa:
hibernate:
ddl-auto: update # TODO: change to validate (or none) when save actual data to server
ddl-auto: validate
open-in-view: false
properties:
hibernate:
dialect: com.wafflestudio.csereal.common.config.MySQLDialectCustom
security:
oauth2:
client:
Expand Down Expand Up @@ -117,6 +115,42 @@ slack:
token: ${SLACK_TOKEN}
channel: ${SLACK_CHANNEL}

---
spring:
config.activate.on-profile: dev
jpa:
hibernate:
ddl-auto: update
show-sql: true
open-in-view: false
security:
oauth2:
client:
registration:
idsnucse:
client-id: cse-waffle-dev
client-secret: ${OIDC_CLIENT_SECRET}
authorization-grant-type: authorization_code
scope: openid, profile, email
redirect-uri: https://${URL}/api/v1/login/oauth2/code/idsnucse
provider:
idsnucse:
issuer-uri: https://id.snucse.org/o
jwk-set-uri: https://id.snucse.org/o/jwks

csereal:
upload:
path: /app/files/

oldFiles:
path: /app/cse-files/

endpoint:
backend: https://${URL}/api
frontend: https://${URL}

login-page: https://${URL}

---
spring:
config.activate.on-profile: test
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,17 @@
</root>
</springProfile>

<springProfile name="dev">
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
</springProfile>

<springProfile name="prod">
<root level="INFO">
<appender-ref ref="CONSOLE" />
<appender-ref ref="ASYNC_SLACK" />
</root>
</springProfile>

</configuration>
Loading