Skip to content
Merged
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
Binary file removed .DS_Store
Binary file not shown.
43 changes: 17 additions & 26 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ name: Deploy with Docker Hub

on:
push:
branches: [main, develop]
pull_request:
branches: [main]
branches: [ develop, main ]

env:
DOCKER_IMAGE: leeeunda/blockcloud-server

jobs:
test:
runs-on: ubuntu-latest
continue-on-error: true # ๊ธ‰๋ฐฐํฌ์šฉ(ํ…Œ์ŠคํŠธ ์‹คํŒจํ•ด๋„ ๋‹ค์Œ ์ง„ํ–‰)
continue-on-error: true
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Set up JDK 21
uses: actions/setup-java@v4
Expand All @@ -37,73 +37,64 @@ jobs:
build-and-push:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }} # <<< CHANGE(secrets): Docker Hub ID
password: ${{ secrets.DOCKER_PASSWORD }} # <<< CHANGE(secrets): Docker Hub PAT/๋น„๋ฒˆ
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# ๋งŒ์•ฝ EC2๊ฐ€ Graviton(ARM64)์ด๋ฉด platform ์ง€์ • ํ•„์š”
# with: platforms: linux/arm64
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ env.DOCKER_IMAGE }}:latest
${{ env.DOCKER_IMAGE }}:${{ github.sha }}
${{ env.DOCKER_IMAGE }}:${{ github.ref_name }}
${{ env.DOCKER_IMAGE }}:pr-${{ github.event.number }}
${{ env.DOCKER_IMAGE }}:${{ github.event.pull_request.head.sha }}
${{ env.DOCKER_IMAGE }}:${{ github.event.pull_request.head.ref }}
cache-from: type=gha
cache-to: type=gha,mode=max
# platforms: linux/amd64 # <<< CHANGE(์˜ต์…˜): EC2๊ฐ€ x86_64๋ฉด ์œ ์ง€, ARM์ด๋ฉด linux/arm64 ๋กœ
# platforms: linux/amd64 # Graviton์ด๋ฉด linux/arm64

deploy-to-ec2:
needs: build-and-push
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Deploy to EC2 (pull & replace container)
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.EC2_HOST }} # <<< CHANGE(secrets): EC2 ํผ๋ธ”๋ฆญ ๋„๋ฉ”์ธ/IP
username: ${{ secrets.EC2_USER }} # <<< CHANGE(secrets): ์ผ๋ฐ˜ ubuntu
key: ${{ secrets.EC2_SSH_KEY }} # <<< CHANGE(secrets): PEM ๋ณธ๋ฌธ
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
set -e
IMAGE="${{ env.DOCKER_IMAGE }}:${{ github.sha }}"
echo "Pull $IMAGE"
IMAGE="${{ env.DOCKER_IMAGE }}:${{ github.event.pull_request.head.sha }}"
docker pull "$IMAGE"

echo "Stop & remove old container"
docker stop blockcloud-app || true
docker rm blockcloud-app || true

echo "Run new container (bind only localhost)"
docker run -d \
--name blockcloud-app \
--restart unless-stopped \
--env-file /srv/app/.env \
-p 127.0.0.1:8080:8080 \
"$IMAGE"

echo "Health check"
# <<< CHANGE(ํ•„์š”์‹œ): ์•ก์ถ”์—์ดํ„ฐ ๊ฒฝ๋กœ๊ฐ€ ๋‹ค๋ฅด๋ฉด ์•„๋ž˜ URL ์ˆ˜์ •
for i in {1..20}; do
for i in {1..30}; do
if curl -fsS http://127.0.0.1:8080/actuator/health >/dev/null 2>&1; then
echo "UP"
exit 0
fi
sleep 3
done

echo "App failed to start. Logs:"
docker logs --tail=200 blockcloud-app || true
exit 1
44 changes: 0 additions & 44 deletions Dockerfile

This file was deleted.

30 changes: 18 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,34 @@ repositories {
}

dependencies {
// Spring Boot Starters
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'

// MySQL ์˜์กด์„ฑ
// Database
runtimeOnly 'com.mysql:mysql-connector-j'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'

// API Documentation
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0'

// JWT
implementation 'io.jsonwebtoken:jjwt-api:0.12.3'
implementation 'io.jsonwebtoken:jjwt-impl:0.12.3'
implementation 'io.jsonwebtoken:jjwt-jackson:0.12.3'

// Lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

// Test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'com.h2database:h2'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
testImplementation("com.h2database:h2")

//oauth2
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'

//JWT ํ† ํฐ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
implementation 'io.jsonwebtoken:jjwt-api:0.12.3'
implementation 'io.jsonwebtoken:jjwt-impl:0.12.3'
implementation 'io.jsonwebtoken:jjwt-jackson:0.12.3'
}

tasks.named('test') {
Expand Down Expand Up @@ -86,4 +91,5 @@ jacocoTestCoverageVerification {
}
}
}

check.dependsOn jacocoTestCoverageVerification
108 changes: 0 additions & 108 deletions scripts/deploy.sh

This file was deleted.