Skip to content

Commit

Permalink
Merge pull request #96 from TeamPINGLE/feat/95
Browse files Browse the repository at this point in the history
[feat] 서버 분리 (개발 서버, 프로덕션 서버) - first trial
  • Loading branch information
tkdwns414 authored Jan 18, 2024
2 parents e82640a + a35d0ab commit c5f11fd
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 51 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/cd.yml → .github/workflows/dev-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: create secret config file
run: |
cd src/main/resources
echo "${{ secrets.APPLICATION }}" > ./application-dev.yml
echo "${{ secrets.APPLICATION_DEV }}" > ./application-dev.yml
- name: build with gradle
run: |
Expand All @@ -41,9 +41,9 @@ jobs:
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
file: ./Dockerfile-prod
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DEV_REPONAME }}

CD:
needs: [CI]
Expand All @@ -53,9 +53,9 @@ jobs:
- name: Docker Image Pull and Container Run
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.RELEASE_SERVER_HOST }}
username: ${{ secrets.RELEASE_SERVER_USERNAME }}
key: ${{ secrets.RELEASE_SERVER_KEY }}
host: ${{ secrets.DEV_SERVER_HOST }}
username: ${{ secrets.DEV_USERNAME }}
key: ${{ secrets.DEV_SERVER_KEY }}
script: |
cd ~
./deploy.sh
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml → .github/workflows/dev-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: create secret config file
run: |
cd src/main/resources
echo "${{ secrets.APPLICATION }}" > ./application-dev.yml
echo "${{ secrets.APPLICATION_DEV }}" > ./application-dev.yml
- name: build with gradle
run: |
Expand Down
61 changes: 61 additions & 0 deletions .github/workflows/prod-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: CD

on:
push:
branches: [ "main" ]

jobs:
CI:
runs-on: ubuntu-22.04

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

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

- name: create secret config file
run: |
cd src/main/resources
echo "${{ secrets.APPLICATION_PROD }}" > ./application-prod.yml
- name: build with gradle
run: |
chmod +x gradlew
./gradlew clean build -x test
- name: Set up Docker Buildx
uses: docker/[email protected]

- name: Login to Docker Hub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile-prod
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.PROD_REPONAME }}

CD:
needs: [CI]
runs-on: ubuntu-22.04

steps:
- name: Docker Image Pull and Container Run
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.PROD_SERVER_HOST }}
username: ${{ secrets.PROD_SERVER_USERNAME }}
key: ${{ secrets.PROD_SERVER_KEY }}
script: |
cd ~
./deploy.sh
29 changes: 29 additions & 0 deletions .github/workflows/prod-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CI

on:
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-22.04

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

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

- name: create secret config file
run: |
cd src/main/resources
echo "${{ secrets.APPLICATION_PROD }}" > ./application-prod.yml
- name: build with gradle
run: |
chmod +x gradlew
./gradlew clean build -x test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ out/
application-secret.properties
application-local.yml
application-dev.yml
application-prod.yml

### Java ###
# Compiled class file
Expand Down
File renamed without changes.
9 changes: 9 additions & 0 deletions Dockerfile-prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM gradle:8.5-jdk17 AS builder
COPY . /usr/src
WORKDIR /usr/src
RUN gradle wrapper --gradle-version 8.5
RUN ./gradlew clean build -x test

FROM openjdk:17-jdk-alpine
COPY --from=builder /usr/src/build/libs/pingleserver-0.0.1-SNAPSHOT.jar /usr/app/app.jar
ENTRYPOINT ["java", "-jar", "/usr/app/app.jar", "--spring.profiles.active=prod"]

This file was deleted.

6 changes: 6 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ spring:
profiles:
active: dev

---

spring:
profiles:
active: prod

---

0 comments on commit c5f11fd

Please sign in to comment.