-
Notifications
You must be signed in to change notification settings - Fork 0
Create Week10 Mission #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
hardwoong
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GitHub Actionsμ AWS EC2λ₯Ό μ΄μ©ν CI/CD λ°°ν¬, κ·Έλ¦¬κ³ EC2 νκ²½μμμ Google λ‘κ·ΈμΈ λ¬Έμ ν΄κ²°κΉμ§ λͺ¨λ μ ν΄κ²°νμ ¨μ΅λλ€.
1. CI/CD λ°°ν¬ νμ΄νλΌμΈ ꡬμΆ
GitHub Actionsμ AWS EC2λ₯Ό μ°λνμ¬ μλ λ°°ν¬ μμ€ν μ ꡬμΆνμ ¨μ΅λλ€. μ½λλ₯Ό νΈμνλ©΄ μλμΌλ‘ λ°°ν¬λλ νκ²½μ νλ‘μ νΈ νκ²½μμ νΈλ¦¬νκ² μμ©ν©λλ€.
- GitHub Actions μν¬νλ‘μ°λ₯Ό ν΅ν μλ λ°°ν¬ μμ€ν ꡬμΆ
- EC2 μΈμ€ν΄μ€μ μλ λ°°ν¬λλ νμ΄νλΌμΈ ꡬμ±
- λ°°ν¬ νκ²½μμ μ ν리μΌμ΄μ μ΄ μ μμ μΌλ‘ λμ
2. Google λ‘κ·ΈμΈ λ°°ν¬ νκ²½ λ¬Έμ ν΄κ²°
EC2 λ°°ν¬ νκ²½μμ Google λ‘κ·ΈμΈμ΄ λμνμ§ μμλ λ¬Έμ λ₯Ό μ ν΄κ²°νμ
¨μ΅λλ€. googleStrategy.jsλ₯Ό 보λ callbackURLμ΄ μλ κ²½λ‘λ‘ μ€μ λμ΄ μμ΄, νμ¬ νΈμ€νΈμ μλμΌλ‘ λ§€νλμ΄ κ°λ°/νλ‘λμ
νκ²½ λͺ¨λμμ λμν μ μλλ‘ μ ꡬμ±λμ΄ μμ΅λλ€!
ν΄κ²° λ°©λ²:
- Google OAuth 리λ€μ΄λ νΈ URIλ₯Ό μλ κ²½λ‘(
/api/v1/auth/google/callback)λ‘ μ€μ - Google Cloud Consoleμμ ν΄λΉ λλ©μΈμ 리λ€μ΄λ νΈ URIλ‘ λ±λ‘
- μλ κ²½λ‘λ₯Ό μ¬μ©νλ©΄ νμ¬ νΈμ€νΈμ μλμΌλ‘ λ§€νλμ΄ νκ²½μ λ°λΌ μ μ°νκ² λμν©λλ€
μ½λ ꡬμ±:
// src/middlewares/passport/googleStrategy.js
export const googleStrategy = new GoogleStrategy(
{
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: '/api/v1/auth/google/callback', // μλ κ²½λ‘ μ¬μ©
scope: ['email', 'profile'],
},
async (accessToken, refreshToken, profile, done) => {
// ...
}
);νΉν μΈμμ μΈ μ :
- μλ κ²½λ‘λ₯Ό μ¬μ©νμ¬ νκ²½μ λ°λΌ μ μ°νκ² λμνλλ‘ κ΅¬μ±ν μ μ΄ μ’μ΅λλ€!
- Google λ‘κ·ΈμΈ μ κΈ°μ‘΄ μ¬μ©μμ μ 보λ₯Ό μ λ°μ΄νΈνλ λ‘μ§μ΄ ν¬ν¨λμ΄ μμ΅λλ€
λ°°ν¬ νκ²½μμμ Google OAuth μ€μ
ν΅μ¬ ν¬μΈνΈ:
- Google OAuthλ IP μ£Όμμ ν¬νΈ λ²νΈ νν(
43.201.11.212:3000)μ 리λ€μ΄λ νΈ URIλ₯Ό μ§μνμ§ μμ΅λλ€ - λ°λΌμ λλ©μΈμ μ¬μ©νλ κ²μ΄ νμμ λλ€
- μλ κ²½λ‘λ₯Ό μ¬μ©νλ©΄ νμ¬ νΈμ€νΈμ μλμΌλ‘ λ§€νλμ΄ κ°λ°/νλ‘λμ νκ²½ λͺ¨λμμ λμν©λλ€
callbackURLμ μλ κ²½λ‘λ‘ μ€μ νκ³ , Google Cloud Consoleμμλ λλ©μΈ ννλ‘ λ±λ‘ν΄μΌ ν©λλ€
νμ¬ μ€μ :
callbackURL: '/api/v1/auth/google/callback'; // μλ κ²½λ‘ μ¬μ©μ΄ μ€μ μ΄ μ¬λ°λ₯΄κ² μ μ©λμ΄ Google λ‘κ·ΈμΈμ΄ μ μμ μΌλ‘ λμνκ³ μμ΅λλ€!
λλ©μΈ μ€μ κ³Όμ :
-
λλ©μΈ DNS μ€μ
- λλ©μΈ μ 곡μ 체(μ: λ΄λλ©μΈνκ΅)μμ λλ©μΈμ A λ μ½λλ₯Ό EC2 μΈμ€ν΄μ€μ νΌλΈλ¦ IP μ£Όμλ‘ μ€μ
- μ΄λ κ² νλ©΄ λλ©μΈμ΄ EC2 μΈμ€ν΄μ€λ₯Ό κ°λ¦¬ν€κ² λ©λλ€
-
Google Cloud Console μ€μ
- Google Cloud Consoleμμ OAuth 리λ€μ΄λ νΈ URIλ₯Ό λλ©μΈ ννλ‘ λ±λ‘
- μ:
http://your-domain.com/api/v1/auth/google/callbackλλhttps://your-domain.com/api/v1/auth/google/callback - IP μ£Όμ ννλ Google OAuthμμ μ§μνμ§ μμΌλ―λ‘ λλ©μΈμ μ¬μ©ν΄μΌ ν©λλ€
-
μ ν리μΌμ΄μ μ½λ
- EC2 νκ²½μμλ μ½λ λ³κ²½μ΄ νμ μμ΅λλ€
callbackURL: "/api/v1/auth/google/callback"λ‘ μλ κ²½λ‘λ₯Ό μ¬μ©νλ©΄, νμ¬ λλ©μΈμ μλμΌλ‘ λ§€νλ©λλ€
κ°μ μ΄ νμν μ
1. updateUserInfo ν¨μκ° importλμ§ μμμ΅λλ€
λ¬Έμ μ :
googleStrategy.jsμμ updateUserInfo ν¨μλ₯Ό μ¬μ©νκ³ μμ§λ§, importλμ§ μμμ΅λλ€.
// src/middlewares/passport/googleStrategy.js
} else {
user = await updateUserInfo(user.id,{
name: name,
snsId: snsId,
})
}κ°μ λ°©μ:
updateUserInfo ν¨μλ₯Ό importνκ±°λ, ν΄λΉ ν¨μλ₯Ό ꡬνν΄μΌ ν©λλ€.
// src/middlewares/passport/googleStrategy.js
import { Strategy as GoogleStrategy } from 'passport-google-oauth20';
import { findByEmail } from '../../repositories/auth.repository.js';
import {
SocialRegisterService,
updateUserInfo,
} from '../../services/auth.service.js'; // updateUserInfo μΆκ°
import { Provider } from '@prisma/client';λλ updateUserInfo ν¨μκ° auth.service.jsμ μλ€λ©΄, ν΄λΉ ν¨μλ₯Ό ꡬνν΄μΌ ν©λλ€.
λ§λ¬΄λ¦¬
μ΄λ² λ―Έμ μ ν΅ν΄ μ€μ νλ‘λμ νκ²½ λ°°ν¬μ μ κ³Όμ μ κ²½ννμ ¨μ΅λλ€. CI/CD νμ΄νλΌμΈ ꡬμΆλΆν° λλ©μΈ μ€μ , OAuth μΈμ¦κΉμ§ λͺ¨λ λ€λ£¨μ ¨μ΅λλ€!
νΉν Google OAuth 리λ€μ΄λ νΈ URIλ₯Ό μλ κ²½λ‘λ‘ μ€μ νμ¬ νκ²½μ λ°λΌ μ μ°νκ² λμνλλ‘ κ΅¬μ±νμ μ μ΄ μΈμμ μ λλ€. Google λ‘κ·ΈμΈ μ κΈ°μ‘΄ μ¬μ©μ μ 보λ₯Ό μ λ°μ΄νΈνλ λ‘μ§μ ν¬ν¨νμ μ λ μ’μ΅λλ€!
μ¬λ¬ λ²μ μλ λμ μ±κ³΅ν GitHub Actions μν¬νλ‘μ°λ κ³ μ λ§μΌμ ¨μ΅λλ€!
μ°Έκ³ μ¬ν
HTTPS μ€μ κΆμ₯:
- νμ¬ HTTPλ‘ λμνκ³ μλ€λ©΄, νλ‘λμ νκ²½μμλ HTTPSλ₯Ό μ¬μ©νλ κ²μ΄ 보μμ μμ ν©λλ€
- AWS Certificate Manager(ACM)λ₯Ό μ¬μ©νμ¬ SSL/TLS μΈμ¦μλ₯Ό λ°κΈλ°κ³ , Application Load Balancerλ CloudFrontμ μ°λνμ¬ HTTPSλ₯Ό μ μ©ν μ μμ΅λλ€
- λλ Let's Encryptλ₯Ό μ¬μ©νμ¬ λ¬΄λ£ SSL μΈμ¦μλ₯Ό λ°κΈλ°μ μλ μμ΅λλ€ (μ λ μ΄ λ°©λ²μ λ μ νΈν©λλ€! λ νΈν΄μ..)
보μ κ·Έλ£Ή νμΈ:
- AWS EC2 보μ κ·Έλ£Ή μ€μ μμ HTTPS(443 ν¬νΈ)κ° μ΄λ €μλμ§ νμΈνμΈμ
- νμνλ€λ©΄ HTTP(80 ν¬νΈ)λ μ΄μ΄λλ, κ°λ₯νλ©΄ HTTPSλ‘ λ¦¬λ€μ΄λ νΈνλ κ²μ κΆμ₯ν©λλ€
νκ²½ λ³μ κ΄λ¦¬:
- κ°λ° νκ²½κ³Ό νλ‘λμ νκ²½μ μ€μ μ νκ²½ λ³μλ‘ κ΄λ¦¬νλ κ²μ κΆμ₯ν©λλ€
- νμ¬ μλ κ²½λ‘λ₯Ό μ¬μ©νκ³ μμ΄
callbackURLμ νκ²½ λ³μλ‘ κ΄λ¦¬ν νμκ° μμ§λ§, λ€λ₯Έ μ€μ λ€(μ:GOOGLE_CLIENT_ID,GOOGLE_CLIENT_SECRET)μ νκ²½ λ³μλ‘ κ΄λ¦¬νλ κ²μ΄ μ’μ΅λλ€
PM2 λλ νλ‘μΈμ€ λ§€λμ μ¬μ©:
- νλ‘λμ νκ²½μμλ PM2λ λ€λ₯Έ νλ‘μΈμ€ λ§€λμ λ₯Ό μ¬μ©νμ¬ μ ν리μΌμ΄μ μ κ΄λ¦¬νλ κ²μ κΆμ₯ν©λλ€
- systemd μλΉμ€λ₯Ό μ¬μ©νλ κ²λ μ’μ μ νμ λλ€
- μ΄λ κ² νλ©΄ μλ² μ¬μμ μμλ μ ν리μΌμ΄μ μ΄ μλμΌλ‘ μ€νλκ³ , λ‘κ·Έ κ΄λ¦¬λ νΈλ¦¬ν©λλ€
λͺ¨λν°λ§ λ° λ‘κ·Έ κ΄λ¦¬:
- λ°°ν¬ νκ²½μμλ μ ν리μΌμ΄μ λ‘κ·Έλ₯Ό λͺ¨λν°λ§νλ κ²μ΄ μ€μν©λλ€
- systemdμ
journalctlμ μ¬μ©νμ¬ λ‘κ·Έλ₯Ό νμΈν μ μμ΅λλ€ - μ:
journalctl -u your-service-name -f(μ€μκ° λ‘κ·Έ νμΈ)
π£οΈ μ΄μ λ²νΈ
closed #91
π λ―Έμ λ²νΈ
10μ£Όμ°¨ Misson 1
π ꡬν μ¬ν
π μ€ν¬λ¦°μ·
β 체ν¬λ¦¬μ€νΈ
π€ μ§λ¬Έ μ¬ν