์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- Kuring
- XCTest
- ๋ฐฑ์ค
- SnapKit
- swift
- realm
- ํ๋ก๊ทธ๋๋จธ์ค
- RxSwift
- reactorkit
- arkit
- ios
- CollectionView
- Flutter
- designpattern
- tableView
- SwiftUI
- combine
- ํจ์คํธ์บ ํผ์ค
- rxcocoa
- visionOS
- Lv2
- BOJ
- BFS
- raywenderlich
- MVVM
- TCA
- Swfit
- Xcode
- node.js
- UIKit
- Today
- Total
lgvv98
[Vapor] Vapor + heroku ๋ณธ๋ฌธ
Vapor + heroku
์ง์ ์๋ฒ ๊ฐ๋ฐ์ ์ฃผ๋ํด๋ณด๊ณ ์ถ์ด์ Vapor๋ฅผ ํ์ตํ๊ณ heroku๋ฅผ ํตํด ๋ฐฐํฌํด ๋ณด์์ต๋๋ค.
์๋ฒ ๊ฐ๋ฐ ๊ฒฝํ์ด ์ ๋ฌดํด์ ๋ฌธ์๋ฅผ ์ฝ๊ณ , ์ดํดํ๊ณ ๋ง๋๋๋ฐ ์๊ฐ์ด ๋ง์ด ๊ฑธ๋ ค์ ๋ค์๋ฒ์ ๋ ์์ฝ๊ฒ ํ๊ธฐ ์ํด์ ๊ธฐ๋กํด ๋๋ ค๊ณ ํฉ๋๋ค.
๊ฐ๋ฐํ๊ฒฝ
- Xcode 13.4.1
1. Vapor ์ค์นํ๊ธฐ
ํฐ๋ฏธ๋์ ์๋์ ์ฝ๋๋ฅผ ์ ๋ ฅ
brew install vapor
2. Vapor ํ๋ก์ ํธ ์์ฑ
ํฐ๋ฏธ๋์ ์์๋๋ก ์ ๋ ฅ.
// 1. ํฐ๋ฏธ๋์ vapor ํ๋ก์ ํธ ์์ฑ
vapor new { ํ๋ก์ ํธ ์ด๋ฆ } // ex. vapor new vaportest
// 2. y, 1, y ์์๋ก ์
๋ ฅ
// 3. ์์ฑ๋ ํ์ผ ๋ด๋ถ๋ก ์ด๋
cd { ํ๋ก์ ํธ ์ด๋ฆ }
// 4. vapor Xcode ์ด๊ธฐ
vapor xcode
// 5. ์์ค์ฝ๋ ์ฐ ํ ๋น๋ ํ ์คํ
// 6. ์คํ์ด ๋ ํ ํฌ๋กฌ ์ฐฝ์ localhost:8080
6๋ฒ ๊ณผ์ ์ดํ, ๋ธ๋ผ์ฐ์ ์ ๊ฒฐ๊ณผ๊ฐ ํ์๋๋ฉด ์ฑ๊ณต
3. ๊ฐ์ฅ ์ค์ํ ๊ฒ์ ๋์๋ณด๋!
๋์๋ณด๋์์ Reource - Add-ons์น์ ์์ postgres ์ ํ ํ Heroku Postgres๋ฅผ ์ ํํ๊ณ Hobby Dev - Free ํ๋์ ์ ํํ๊ณ ์๋ฃํ๋ฉด ๋๋ค.
๋ค์ ๋ก์ปฌ๋ก ๋์์์ ํฐ๋ฏธ๋์
4. Heroku CLI ์ค์น
brew install heroku/brew/heroku
5. heroku login
heroku login
์ ์์ ์ผ๋ก ๋ก๊ทธ์ธ ๋๋์ง ํ์ธํ๋ ค๋ฉด,
heroku auth:whoami
6. git
๋์๋ณด๋์ ์ค์ ํ ์ฑ ์ด๋ฆ์ ๋ฃ์ด์ค๋ค.
์ฌ๊ธฐ์ git์ด๋ผ๊ณ ํ๋ฉด์ heroku๊ฐ git์ ์ด์ฉํ๋ค๋ ๊ฑฐ์ง, ๋ด๊ฐ ๊นํ์ git์ ๊ตณ์ด ์์ฌ๋ ค๋ ๋ผ.
๊ทธ๋ฌ๋๊น heroku์ฉ ๊น๊ณผ ์ฝ๋๋ฅผ ์ํ ๋์ git์ด ๋ฐ๋ก ์๋ค๊ณ ์๊ฐํ๋ฉด ๋๋ค.
heroku git:remote { ๋์๋ณด๋์ ์ง์ ํ heroku ์ฑ ์ด๋ฆ }
7. ๋น๋ํฉ ์ค์
heroku buildpacks:set vapor/vapor
8. .swift-version ์์ฑ ๋ฐ Profile ์์ฑ
echo "5.2.4" > .swift-version
echo "web: Run serve --env production" \
"--hostname 0.0.0.0 --port \$PORT" > Procfile
9. PostgreSQL ์ค์
์ฑ์ด ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ ๊ทผํ ์ ์๋๋ก ์ค์ ํ๋ค.
heroku config
๋ง์ฝ ์ค์ ์ด ์ ์์ ์ผ๋ก ๋์๋ค๋ฉด, ๋ช ๋ น์ด๋ฅผ ์ ๋ ฅํ์ ๋
=== { ๋์๋ณด๋์ ๋ฑ๋กํ ์ฑ ์ด๋ฆ } Config VarsDATABASE_URL: postgres:// { ... }
์ ์ฒ๋ผ ๋ํ๋๋ค.
๋ง์ฝ ์ ๋๋ก ๋ํ๋์ง ์๋๋ค๋ฉด 3๋ฒ ๊ณผ์ ์ ์ํํ์ง ์์๋์ง ํ์ธ์ด ํ์ํ๋ค.
10. configure.swift ํ์ผ์ ๋ค์์ ์ฝ๋๋ฅผ ์ถ๊ฐํฉ๋๋ค.
import Fluent
import FluentPostgresDriver
import Leaf
import Vapor
// configures your application
public func configure(_ app: Application) throws {
// uncomment to serve files from /Public folder
app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
if let databaseURL = Environment.get("DATABASE_URL"), var postgresConfig = PostgresConfiguration(url: databaseURL) {
postgresConfig.tlsConfiguration = .forClient(certificateVerification: .none)
app.databases.use(.postgres(
configuration: postgresConfig
), as: .psql)
} else {
// ...
}
app.databases.use(.postgres(
hostname: Environment.get("DATABASE_HOST") ?? "localhost",
port: Environment.get("DATABASE_PORT").flatMap(Int.init(_:)) ?? PostgresConfiguration.ianaPortNumber,
username: Environment.get("DATABASE_USERNAME") ?? "vapor_username",
password: Environment.get("DATABASE_PASSWORD") ?? "vapor_password",
database: Environment.get("DATABASE_NAME") ?? "vapor_database"
), as: .psql)
app.migrations.add(CreateTodo())
app.views.use(.leaf)
// register routes
try routes(app)
}
์ ์ฝ๋์ฒ๋ผ ์์ฑํฉ๋๋ค.
๋ง์ง๋ง์ผ๋ก ๋ฐฐํฌ!
heroku๋ ๊ธฐ๋ณธ์ ์ผ๋ก master ๋ธ๋์น์ ๋ฐฐํฌ
git push heroku master
์ด ๊ณผ์ ์์ ์ฝ๊ฐ์ ์๊ฐ์ผ ๊ฑธ๋ฆผ
์ดํ ์ฝ๋๊ฐ ๋ณ๊ฒฝ๋์๋ค๋ฉด
git add *
git commit -m "์ปค๋ฐ ๋ฉ์์ง"
git push heroku master
์ปค๋ฐํ๊ณ ํธ์ํ๋ฉด ๋๋ค.
๋ค์์ ํฌ์คํธ ๋งจ์ผ๋ก
https://{๋์๋ณด๋ ์ฑ ์ด๋ฆ}.herokuapp.com/...
๐จ ์ด์
heroku ps:scale web=1 ์ ๋ ฅ์, Couldn't find that process type, Heroku๊ฐ ๋ํ๋ฌ์ ๋ ์ฌ์ฉ
์๋์ฒ๋ผ ํด๋ ๋์์ผ๋, ์ ์ ๊ฒฝ์ฐ์๋ heroku ๋์๋ณด๋์์ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์ ๋๋ก ์ค์ ํ์ง ์์์ ๋ํ๋๋ ๋ฌธ์ ์์ต๋๋ค.
heroku config๋ฅผ ํ์ ๋ ์๋ฌด๊ฒ๋ ๋ํ
https://www.appsloveworld.com/django/100/149/couldnt-find-that-process-type-web-error-on-heroku
(์ฐธ๊ณ )
https://yagom.net/courses/start-vapor/lessons/vapor-app-%eb%b0%b0%ed%8f%ac%ed%95%98%ea%b8%b0/
https://hururuek-chapchap.tistory.com/128?category=933474