Skip to content

Commit

Permalink
Merge pull request #23 from kookmin-sw/feature/21
Browse files Browse the repository at this point in the history
Feature/21
  • Loading branch information
begong313 authored Mar 25, 2024
2 parents 7d58177 + d2c5a46 commit 3bd31ae
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 3 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/feature.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build for feature branch

on:
push:
branches:
- feature/*
pull_request:
branches:
- feature/*

permissions:
contents: read


jobs:
build_only:
runs-on: ubuntu-latest # ubuntu 최신 버전에서 script를 실행

steps:

- uses: actions/checkout@v3

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

- name: Make application.properties
run: |
cd ./server/src/main/resources
touch ./application.properties
echo "${{ secrets.PROPERTIES }}" > ./application.properties
shell: bash

# gradle을 통해 소스를 빌드.
- name: Build with Gradle
run: |
cd server
chmod +x ./gradlew
./gradlew clean build -x test
- name: Docker build
run: |
cd server
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO }}:latest .
61 changes: 61 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Build And Deploy for main branch

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

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

steps:
- uses: actions/checkout@v3

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

- name: Make application.properties
run: |
cd ./server/src/main/resources
touch ./application.properties
echo "${{ secrets.PROPERTIES }}" > ./application.properties
shell: bash

- name: Build with Gradle
run: |
cd server
chmod +x ./gradlew
./gradlew clean build -x test
- name: Docker build & push to docker repo
run: |
cd server
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO }}:latest .
docker push ${{ secrets.DOCKER_REPO }}:latest
pull-and-deploy:
needs: build-and-push
runs-on: ubuntu-latest
steps:

- name: Pull & Deploy to server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_PUBLIC_IP }}
username: ubuntu
key: ${{ secrets.SSH_PRIVATE_KEY }}
envs: GITHUB_SHA
script: |
sudo docker rm -f $(docker ps -qa)
sudo docker pull ${{ secrets.DOCKER_REPO }}:latest
sudo docker image prune -f
sudo docker run -d --name server -p 80:8080 suhwani/capstone
2 changes: 2 additions & 0 deletions server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ out/

### VS Code ###
.vscode/

server/src/main/resources/*.properties
12 changes: 12 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM bellsoft/liberica-openjdk-alpine:17

# Gradle 빌드 명령 실행
CMD ["./gradlew", "clean", "build"]

# 빌드된 JAR 파일 복사
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar

EXPOSE 8080

ENTRYPOINT ["java","-jar","/app.jar"]
10 changes: 7 additions & 3 deletions server/src/main/resources/application-local.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# postgres setting
spring.datasource.url=jdbc:postgresql://localhost:5432/capstone
spring.datasource.username=suhwan_main
spring.datasource.password=tnrl0258!
# spring.datasource.url=jdbc:postgresql://localhost:5432/capstone
# spring.datasource.username=suhwan_main
# spring.datasource.password=tnrl0258!
spring.datasource.url=jdbc:postgresql://capstone.cb8wmwuccl1h.ap-northeast-2.rds.amazonaws.com:5432/test
spring.datasource.username=postgres
spring.datasource.password=databasepassword
spring.datasource.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect


# hibernate setting
spring.jpa.properties.hibernate.use_sql_comments=true
spring.jpa.properties.hibernate.format_sql=true
Expand Down

0 comments on commit 3bd31ae

Please sign in to comment.