Skip to content

Commit 4c0b6e7

Browse files
authored
Merge pull request #257 from DevKor-github/codex/ec2-hosting
[codex] Prepare EC2 hosting
2 parents 405d32f + 2ca0d83 commit 4c0b6e7

6 files changed

Lines changed: 229 additions & 144 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 136 additions & 124 deletions
Large diffs are not rendered by default.

ontime-back/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM eclipse-temurin:17-jdk
1+
FROM eclipse-temurin:17-jre
22
RUN apt-get update && \
33
apt-get install -y tzdata && \
44
ln -snf /usr/share/zoneinfo/Asia/Seoul /etc/localtime && \
@@ -7,4 +7,4 @@ RUN apt-get update && \
77
rm -rf /var/lib/apt/lists/*
88
WORKDIR /app
99
COPY project.jar app.jar
10-
ENTRYPOINT ["java", "-jar", "/app/app.jar"]
10+
ENTRYPOINT ["java", "-jar", "/app/app.jar"]

ontime-back/EC2_DEPLOY.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# EC2 Deployment
2+
3+
This service deploys to Amazon EC2 through `.github/workflows/deploy.yml`.
4+
5+
## How to Deploy
6+
7+
1. Make sure the EC2 instance has Docker installed and the security group allows inbound traffic for the service port, currently `8080`.
8+
2. Add the required GitHub Actions secrets listed below.
9+
3. Run the `Deploy` workflow manually from GitHub Actions, or push to the `deploy` branch.
10+
11+
The workflow builds the Spring Boot jar, creates deploy-only config files from GitHub Secrets, uploads them to `/home/ubuntu/OnTime-back`, and restarts Docker Compose on the EC2 instance.
12+
13+
## Required EC2 Secrets
14+
15+
- `EC2_HOST`
16+
- `EC2_USER`
17+
- `EC2_SSH_KEY`
18+
19+
## Required Application Secrets
20+
21+
- `SPRING_APPLICATION_NAME`
22+
- `SPRING_DATASOURCE_URL`
23+
- `SPRING_DATASOURCE_USERNAME`
24+
- `SPRING_DATASOURCE_PASSWORD`
25+
- `SPRING_DATASOURCE_DRIVER_CLASS_NAME`
26+
- `SPRING_JPA_HIBERNATE_DDL_AUTO`
27+
- `JWT_SECRETKEY`
28+
- `JWT_ACCESS_EXPIRATION`
29+
- `JWT_REFRESH_EXPIRATION`
30+
- `JWT_ACCESS_HEADER`
31+
- `JWT_REFRESH_HEADER`
32+
- `GOOGLE_WEB_CLIENT_ID`
33+
- `GOOGLE_APP_CLIENT_ID`
34+
- `APPLE_CLIENT_ID`
35+
- `APPLE_LOGIN_KEY`
36+
- `APPLE_TEAM_ID`
37+
- `AUTHKEY_743M7R5W3W`
38+
- `SPRING_FLYWAY_URL`
39+
- `SPRING_FLYWAY_USER`
40+
- `SPRING_FLYWAY_PASSWORD`
41+
- `ONTIME_PUSH_FIREBASE_ADMINSDK`
42+
43+
## Optional Secrets
44+
45+
- `SPRING_JPA_DATABASE_PLATFORM` defaults to `org.hibernate.dialect.MySQL8Dialect`.
46+
- `FEATURE_APPLE_LOGIN_ENABLED` defaults to `true`.
47+
- Google and Kakao OAuth provider/registration secrets are included by the workflow when configured.
48+
49+
## Runtime Files on EC2
50+
51+
The deploy workflow writes these files under `/home/ubuntu/OnTime-back`:
52+
53+
- `project.jar`
54+
- `Dockerfile`
55+
- `docker-compose.yml`
56+
- `config/application.properties`
57+
- `secrets/firebase-adminsdk.json`
58+
- `secrets/AuthKey_743M7R5W3W.p8`
59+
60+
Do not commit local `application.properties`, Firebase service account JSON, Apple `.p8` keys, or `.env` files.

ontime-back/docker-compose.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
version: "3.8"
2-
31
services:
42
backend:
53
build:
64
context: .
7-
dockerfile: Dockerfile # Dockerfile 이름
8-
image: ontimedemo # 빌드된 백엔드 이미지
9-
container_name: ontime-container
5+
dockerfile: Dockerfile
6+
image: ontime-backend
7+
container_name: ontime-backend
8+
restart: unless-stopped
109
ports:
1110
- "8080:8080"
12-
- "8443:8443"
1311
volumes:
14-
- /home/ubuntu/OnTime-back/ontime-back/src/main/resources/:/app/src/main/resources/
15-
- /home/ubuntu/OnTime-back/ontime-back/src/main/resources/key/:/app/resources/key/
12+
- ./config/application.properties:/app/config/application.properties:ro
13+
- ./secrets/firebase-adminsdk.json:/app/secrets/firebase-adminsdk.json:ro
14+
- ./secrets/AuthKey_743M7R5W3W.p8:/app/secrets/AuthKey_743M7R5W3W.p8:ro

ontime-back/src/main/java/devkor/ontime_back/config/FirebaseInitialization.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.google.firebase.FirebaseApp;
55
import com.google.firebase.FirebaseOptions;
66
import lombok.extern.slf4j.Slf4j;
7+
import org.springframework.beans.factory.annotation.Value;
78
import org.springframework.stereotype.Service;
89

910
import javax.annotation.PostConstruct;
@@ -13,23 +14,38 @@
1314
import java.io.InputStream;
1415

1516
@Service
17+
@Slf4j
1618
public class FirebaseInitialization {
1719

20+
private static final String DEFAULT_FIREBASE_RESOURCE = "ontime-c63f1-firebase-adminsdk-fbsvc-a043cdc829.json";
21+
22+
@Value("${firebase.service-account.path:}")
23+
private String serviceAccountPath;
24+
1825
@PostConstruct
1926
public void initialize() {
20-
try {
21-
InputStream serviceAccount = getClass().getClassLoader().getResourceAsStream("ontime-c63f1-firebase-adminsdk-fbsvc-a043cdc829.json");
22-
if (serviceAccount == null) {
23-
throw new FileNotFoundException("Resource not found: ontime-c63f1-firebase-adminsdk-fbsvc-a043cdc829.json");
24-
}
25-
27+
try (InputStream serviceAccount = openServiceAccount()) {
2628
FirebaseOptions options = new FirebaseOptions.Builder()
2729
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
2830
.build();
2931

30-
FirebaseApp.initializeApp(options);
32+
if (FirebaseApp.getApps().isEmpty()) {
33+
FirebaseApp.initializeApp(options);
34+
}
3135
} catch (IOException e) {
32-
e.printStackTrace();
36+
log.error("Failed to initialize Firebase", e);
37+
}
38+
}
39+
40+
private InputStream openServiceAccount() throws IOException {
41+
if (serviceAccountPath != null && !serviceAccountPath.isBlank()) {
42+
return new FileInputStream(serviceAccountPath);
43+
}
44+
45+
InputStream serviceAccount = getClass().getClassLoader().getResourceAsStream(DEFAULT_FIREBASE_RESOURCE);
46+
if (serviceAccount == null) {
47+
throw new FileNotFoundException("Resource not found: " + DEFAULT_FIREBASE_RESOURCE);
3348
}
49+
return serviceAccount;
3450
}
3551
}

ontime-back/src/main/java/devkor/ontime_back/global/oauth/apple/AppleLoginService.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ public AppleTokenResponseDto getAppleAccessTokenAndRefreshToken(String authCode)
187187
String clientSecret = generateClientSecret();
188188
log.info("getAppleAccessTokenAndRefreshToken");
189189
log.info("client_id: {}", clientId);
190-
log.info("client_secret: {}", clientSecret);
191190
MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>();
192191
requestBody.add("grant_type", "authorization_code");
193192
requestBody.add("code", authCode);
@@ -270,4 +269,3 @@ public boolean revokeToken(Long userId) throws Exception {
270269
}
271270
}
272271
}
273-

0 commit comments

Comments
 (0)