Day 16
Last updated
Was this helpful?
Last updated
Was this helpful?
ClientRegistrationRepository๋ฅผ ์์ฑํ๋ฉด clientId์ clientSecret๊ฐ ํ์์ธ๋ฐ ๋ก์ปฌ์์๋ application-oauth.properties๊ฐ ์์ด์ ๋ฌธ์ ๊ฐ ์์์ง๋ง
ํ์ฌ๋ EC2์์ ์งํ์ค์ด๋ฉด์ github์์ ๋ค์ด๋ก๋ ๋ฐ์ ํ๋ก์ ํธ๋ก ํ๋๋ฐ ๋ก์ปฌ์์ git์ ์ฌ๋ฆด ๋ application-oauth.properties๋ .gitignore๋ก ์ ์ธ๋์์ผ๋ก ๋นผ๋์์
์ ํ๋ฆฌ์ผ์ด์ ์ ์คํํ๊ธฐ ์ํด ๊ณต๊ฐ๋ ์ ์ฅ์์ clientId์ ClientSecret์ ์ฌ๋ฆด์๋ ์์ผ๋ ์๋ฒ์์ ์ง์ ์ด ์ค์ ๋ค์ ๊ฐ์ง๊ณ ์๋๋ก ํด์ผํจ
app๋๋ ํ ๋ฆฌ์ properties ํ์ผ์ ์์ฑ
vim /home/ec2-user/app/application-aouth.properties
๋ก ํ์ผ์ ์์ฑ, ์ฐ๋ค์์ ๋ก์ปฌ์์์ application-aouth.properties ํ์ผ์ ๊ทธ๋๋ก ๋ณต์ฌ ๋ถํ๋ฃ๊ธฐ๋ฅผ ํ๊ณ ์ ์ฅ์ข ๋ฃ๋ฅผ ํ๋ค์
๋ฐฉ๊ธ ์๋ฒ์์ ์์ฑํ application-aouth.properties์ ์ฐ๋๋ก deploy.sh๋ฅผ ์์
์ด๊ฒ์ ์ถ๊ฐ
-Dspring.config.location
์คํ๋ง ์ค์ ํ์ผ ์์น๋ฅผ ์ง์
๊ธฐ๋ณธ ์ต์ ๋ค์ ๋ด๊ณ ์๋ application.properties์ OAuth ์ค์ ๋ค์ ๋ด๊ณ ์๋ application-oauth.properties์ ์์น๋ฅผ ์ง์
classpath๊ฐ ๋ถ์ผ๋ฉด jar ์์ ์๋ resources ๋๋ ํ ๋ฆฌ๋ฅผ ๊ธฐ์ค์ผ๋ก ๊ฒฝ๋ก๊ฐ ์์ฑ๋จ
application-oauth.properties์ ์ ๋ ๊ฒฝ๋ก๋ฅผ ์ฌ์ฉ, ์ธ๋ถ์ ํ์ผ์ด ์๊ธฐ ๋๋ฌธ
RDS๋ MariaDB๋ฅผ ์ใ ์ค์ธ๋ฐ ์ฌ๊ธฐ์ ์คํ๋ง๋ถํธ ํ๋ก์ ํธ๋ฅผ ์คํํ๊ธฐ ์ํด์๋ ๋ช ๊ฐ์ง ์์ ์ด ํ์
ํ ์ด๋ธ ์์ฑ : H2์์ ์๋์ผ๋ก ์์ฑํด์ฃผ๋ ํ ์ด๋ธ๋ค์ MariaDB์์ ์ง์ ์ฟผ๋ฆฌ๋ฅผ ์ด์ฉํด ์์ฑ
ํ๋ก์ ํธ ์ค์ : ์๋ฐ ํ๋ก์ ํธ๊ฐ MariaDB์ ์ ๊ทผํ๋ ค๋ฉด ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋๋ผ์ด๋ฒ๊ฐ ํ์ํ๊ธฐ ๋๋ฌธ์ MariaDB์์ ์ฌ์ฉ ๊ฐ๋ฅํ ๋๋ผ์ด๋ฒ๋ฅผ ํ๋ก์ ํธ์ ์ถ๊ฐ
EC2(๋ฆฌ๋ ์ค) ์ค์ : ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ ์ ์ ๋ณด๋ ์ค์ํ๊ฒ ๋ณดํธํด์ผํ ์ ๋ณด์ด๋ค. ๋ง์ฝ ๊ณต๊ฐ๋๋ฉด ์ธ๋ถ์์ ๋ฐ์ดํฐ๋ฅผ ๋ชจ๋ ๊ฐ์ ธ๊ฐ ์ ์๊ธฐ ๋๋ฌธ์ด๋ค. ํ๋ก์ ํธ์์ ์ ์ ์ ๋ณด๋ฅผ ๊ฐ์ง๊ณ ์๋ค๋ฉด ๊นํ๋ธ์ ๊ฐ์ด ์คํ๋ ๊ณต๊ฐ์์ ๋๊ตฌ๋ ํดํนํ ์ํ์ด ์๋ค. ๊ทธ๋์ EC2 ์๋ฒ ๋ด๋ถ์์ ์ ์ ์ ๋ณด๋ฅผ ๊ด๋ฆฌํ๋๋ก ์ค์
RDSํ ์ด๋ธ์ ์์ฑ : ์ฌ๊ธฐ์๋ JPA๊ฐ ์ฌ์ฉ๋ ์ํฐํฐ ํ ์ด๋ธ๊ณผ ์คํ๋ง ์ธ์ ์ด ์ฌ์ฉ๋ ํ ์ด๋ธ 2๊ฐ์ง ์ข ๋ฅ๋ฅผ ์์ฑ
JPA๊ฐ ์ฌ์ฉํ ํ ์ด๋ธ์ ํ ์คํธ ์ฝ๋ ์ํ์, ๋ก๊ทธ๋ก ์์ฑ๋๋ ์ฟผ๋ฆฌ, schema-mysql.sqlํ์ผ์์์ ์ธ์ ํ ์ด๋ธ ์ฟผ๋ฆฌ๋ฅผ ๋ณต์ฌํด์ RDS์ ๋ฐ์
๋จผ์ MariaDB๋๋ผ์ด๋ฒ๋ฅผ build.gradle์ ๋ฑ๋ก
๊ทธ๋ฆฌ๊ณ ์๋ฒ์ ๊ตฌ๋๋ ํ๊ฒฝ์ ํ๋ ๊ตฌ์ฑํ๋ค.
src/main/resources์ application-real.propertiesํ์ผ์ ์ถ๊ฐ
application-real.properties๋ก ํ์ผ์ ๋ง๋ค๋ฉด profile=real์ธ ํ๊ฒฝ์ด ๊ตฌ์ฑ๋๋ค
์ค์ ๋ก ์ด์๋ ํ๊ฒฝ์ด๊ธฐ ๋๋ฌธ์ ๋ณด์/๋ก๊ทธ์ ์ด์๊ฐ ๋ ๋งํ ์ค์ ๋ค์ ๋ชจ๋ ์ ๊ฑฐํ๋ฉฐ RDS ํ๊ฒฝ profile ์ค์ ์ด ์ถ๊ฐ
์ด๋ ๊ฒ ํ๊ณ ํธ์ฌ
OAuth์ ๋ง์ฐฌ๊ฐ์ง๋ก RDS ์ ์ ์ ๋ณด๋ ๋ณดํธํด์ผํ ์ ๋ณด์ด๊ธฐ ๋๋ฌธ์ EC2 ์๋ฒ์ ์ง์ ์ค์ ํ์ผ์ ๋๋ค
app ๋๋ ํ ๋ฆฌ์ application-real-db.properties ํ์ผ์ ์์ฑ
spring.jpa.hibernate.ddl-auto=none
JPA๋ก ํ ์ด๋ธ์ด ์๋ ์์ฑ๋๋ ์ต์ ์ None(์์ฑํ์ง ์์)์ผ๋ก ์ง์
RDS์์๋ ์ค์ ๋ก ์ด์์ผ๋ก ์ฌ์ฉ๋ ํ ์ด๋ธ์ด๊ธฐ ๋๋ฌธ์ ์ ๋ ์คํ๋ง ๋ถํธ์์ ์๋ก ๋ง๋ค์ง ์๋๋ก ํด์ผํจ
์ด ์ต์ ์ ํ์ง ์์ผ๋ฉด ํ ์ด๋ธ์ด ๋ชจ๋ ์๋ก ์์ฑ๋ ์ ์์
์ฃผ์ํด์ผํจ
๋ง์ง๋ง์ผ๋ก deploy.sh๊ฐ real profile์ ์ฌ์ฉํ ์ ์๋๋ก ์ฝ๋์ถ๊ฐ
Dspring.profiles.active=real
application-real.properties๋ฅผ ํ์ฑํ
application-real.properties์ spring.profiles.include=oauth,real-db ์ต์ ๋๋ฌธ์ real-db ์ญ์ ํจ๊ป ํ์ฑํ ๋์์ ํฌํจ
์์๊พธ
์ด๋ ๊ฒ ๋จ๋ฉด์ ์๋ฌ๊ฐ ๋๋๊ฑธ๊น...
์ด๋ ๊ฒ ์ค์ ํ๊ณ ./deploy.sh ๋ก ์คํํ๊ณ ๋์ nohup.out ํ์ผ์ ์ด์ด