Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/GDSC-KNU/3rd-sp-3-BE int…
Browse files Browse the repository at this point in the history
…o feat/channel-approve-api
  • Loading branch information
F-hiller committed May 25, 2024
2 parents 56f819b + 216bc36 commit cf05838
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 1 deletion.
81 changes: 81 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: SpringBoot deploy with Docker

on:
# after merge to main with pr
pull_request:
types: [ closed ]
branches: [ "develop" ]

jobs:
build-and-deploy:
runs-on: ubuntu-22.04
permissions:
contents: read

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Build with Gradle Wrapper
run: ./gradlew build -x test

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and Push Docker Image
run: |
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:${{ github.sha }} .
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:${{ github.sha }}
- name: Modify docker-compose.dev.yaml
run: |
sed -i "s|REPLACE_IMAGE_TAG|${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}:${{ github.sha }}|g" docker-compose.dev.yaml &&
sed -i "s|REPLACE_GOOGLE_CLIENT_ID|${{ secrets.GOOGLE_CLIENT_ID }}|g" docker-compose.dev.yaml &&
sed -i "s|REPLACE_GOOGLE_CLIENT_SECRET|${{ secrets.GOOGLE_CLIENT_SECRET }}|g" docker-compose.dev.yaml &&
sed -i "s|REPLACE_GOOGLE_REDIRECT_URI|${{ secrets.GOOGLE_REDIRECT_URI }}|g" docker-compose.dev.yaml &&
sed -i "s|REPLACE_JWT_SECRET|${{ secrets.JWT_SECRET }}|g" docker-compose.dev.yaml
- name: Send script to remote server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: "docker-compose.dev.yaml,script/deploy.sh"
target: /home/${{ secrets.REMOTE_USERNAME }}/gdsc-project

- name: SSH to remote server and run docker-compose
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /home/${{ secrets.REMOTE_USERNAME }}/gdsc-project/script
chmod +x deploy.sh
sudo ./deploy.sh
dependency-submission:
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

# Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies.
# See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md
- name: Generate and submit dependency graph
uses: gradle/actions/dependency-submission@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: SpringBoot test with Redis

on:
pull_request:
types: [ opened, synchronize, reopened ]
branches: [ "develop" ]

jobs:
test:
runs-on: ubuntu-22.04
services:
redis:
image: redis:latest
ports:
- 6379:6379

permissions:
contents: read

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Test with Gradle Wrapper
run: ./gradlew test
env:
REDIS_HOST: ${{ secrets.REDIS_HOST }}
REDIS_PORT: ${{ secrets.REDIS_PORT }}
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
GOOGLE_REDIRECT_URI: ${{ secrets.GOOGLE_REDIRECT_URI }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM amd64/amazoncorretto:17
WORKDIR /usr/src/app
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java", "-Duser.timezone=Asia/Seoul", "-jar", "app.jar"]
22 changes: 22 additions & 0 deletions docker-compose.dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '3'
services:
gradingx-redis:
image: redis:latest
container_name: redis
hostname: redis
expose:
- "6379"

gradingx-server:
image: REPLACE_IMAGE_TAG
environment:
- REDIS_HOST=localhost
- REDIS_PORT=6379
- GOOGLE_CLIENT_ID=REPLACE_GOOGLE_CLIENT_ID
- GOOGLE_CLIENT_SECRET=REPLACE_GOOGLE_CLIENT_SECRET
- GOOGLE_REDIRECT_URI=REPLACE_GOOGLE_REDIRECT_URI
- JWT_SECRET=REPLACE_JWT_SECRET
ports:
- "8080:8080"
depends_on:
- gradingx-redis
Empty file modified gradlew
100644 → 100755
Empty file.
7 changes: 7 additions & 0 deletions script/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

cd ..

docker-compose -f docker-compose.dev.yaml up --build -d

docker-compose -f docker-compose.dev.yaml ps
2 changes: 2 additions & 0 deletions src/test/java/gdsc/comunity/CommunityApplicationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

@SpringBootTest
@ActiveProfiles("test")
class CommunityApplicationTests {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.springframework.transaction.annotation.Transactional;

@Transactional
@ActiveProfiles("dev")
@ActiveProfiles("test")
@SpringBootTest(webEnvironment = WebEnvironment.MOCK)
class RefreshTokenRepositoryTest {

Expand Down

0 comments on commit cf05838

Please sign in to comment.