├── README.md ├── img ├── EnvironmentVar2.png ├── addService.png ├── buildv1.png ├── domain.png ├── empty.png ├── githubProject.png ├── githubRepo.png ├── login.png ├── mysql.png ├── mysqltabs.png ├── mysqlvariables.png ├── newProject.png ├── period.png └── springAppStructure.png ├── setup-en.md └── setup-es.md /README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot-railway Deploy setup 2 | Basic info to deploy a spring boot application on railway 3 | 4 | ## Setup 5 | 6 | ```setup-en.md``` contains english setup 7 | 8 | ```setup-es.md``` contiene setup en español 9 | -------------------------------------------------------------------------------- /img/EnvironmentVar2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeaCluster/springboot-railway-deploy/70e3b8abde8110ca298b872d7292e27324fabd04/img/EnvironmentVar2.png -------------------------------------------------------------------------------- /img/addService.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeaCluster/springboot-railway-deploy/70e3b8abde8110ca298b872d7292e27324fabd04/img/addService.png -------------------------------------------------------------------------------- /img/buildv1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeaCluster/springboot-railway-deploy/70e3b8abde8110ca298b872d7292e27324fabd04/img/buildv1.png -------------------------------------------------------------------------------- /img/domain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeaCluster/springboot-railway-deploy/70e3b8abde8110ca298b872d7292e27324fabd04/img/domain.png -------------------------------------------------------------------------------- /img/empty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeaCluster/springboot-railway-deploy/70e3b8abde8110ca298b872d7292e27324fabd04/img/empty.png -------------------------------------------------------------------------------- /img/githubProject.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeaCluster/springboot-railway-deploy/70e3b8abde8110ca298b872d7292e27324fabd04/img/githubProject.png -------------------------------------------------------------------------------- /img/githubRepo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeaCluster/springboot-railway-deploy/70e3b8abde8110ca298b872d7292e27324fabd04/img/githubRepo.png -------------------------------------------------------------------------------- /img/login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeaCluster/springboot-railway-deploy/70e3b8abde8110ca298b872d7292e27324fabd04/img/login.png -------------------------------------------------------------------------------- /img/mysql.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeaCluster/springboot-railway-deploy/70e3b8abde8110ca298b872d7292e27324fabd04/img/mysql.png -------------------------------------------------------------------------------- /img/mysqltabs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeaCluster/springboot-railway-deploy/70e3b8abde8110ca298b872d7292e27324fabd04/img/mysqltabs.png -------------------------------------------------------------------------------- /img/mysqlvariables.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeaCluster/springboot-railway-deploy/70e3b8abde8110ca298b872d7292e27324fabd04/img/mysqlvariables.png -------------------------------------------------------------------------------- /img/newProject.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeaCluster/springboot-railway-deploy/70e3b8abde8110ca298b872d7292e27324fabd04/img/newProject.png -------------------------------------------------------------------------------- /img/period.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeaCluster/springboot-railway-deploy/70e3b8abde8110ca298b872d7292e27324fabd04/img/period.png -------------------------------------------------------------------------------- /img/springAppStructure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KeaCluster/springboot-railway-deploy/70e3b8abde8110ca298b872d7292e27324fabd04/img/springAppStructure.png -------------------------------------------------------------------------------- /setup-en.md: -------------------------------------------------------------------------------- 1 | # Test 2 | 3 | ## EcommerceDB 4 | 5 | ### Desc 6 | 7 | This is a test Spring Boot app meant to be a base for future deploys on Railway 8 | 9 | Not ready for production 10 | > ?Could be ready for production 11 | 12 | ### Info 13 | ** 14 | There's an ```application-prod.yml``` file used to save basic production config data. This will have different info depending on the platform you're making the deploy. Check it for more context. What's in there however is specifically for railway. 15 | 16 | ## Part 1 17 | 18 | ### SETUP - railway account 19 | 20 | - Login or setup new railway account. 21 | ![Railway login screen](/img/login.png) 22 | - Recommended to be setup from github for easier access to repos. 23 | - [Railway.app](railway.app) 24 | 25 | ### SETUP - New project 26 | 27 | - Create a new project 28 | - Either from the top right icon or center action area 29 | ![New project screen](/img/newProject.png) 30 | - I recommend an empty project 31 | ![empty project screen](/img/empty.png) 32 | 33 | ### SETUP - Services 34 | 35 | 36 | ![Add Service](/img/addService.png) 37 | Services work as plugins you can add to your project. They vary from Database services such as ```Mysql, PostgreSQL, MongoDB``` all the way to ```Django, Laravel, DiscordJS bot, Kotlin, Vite, Vite + Vue + TS```, etc... For this project we'll be using ```Mysql``` and our own service ```(Spring Boot App)``` fetched directly from ```GitHub```. 38 | 39 | - Select add service -> Database -> Add MySQL 40 | ![Add Mysql](/img/mysql.png) 41 | 42 | - Your service might take some time to setup 43 | - Once created, click on your service. It will have several info tabs. 44 | - You can create tables directly from ```railway``` but we don't want that right now. 45 | ![MySQL tabs](/img/mysqltabs.png) 46 | 47 | ***Check this out*** 48 | 49 | - Travel to your Variables tab (might be in other tabs since this updates regularly). Once there, you'll realize that's all the info to make your connection from your API to your DB. 50 | - Keep it **private** 51 | ![Mysql Variables](/img/mysqlvariables.png) 52 | 53 | ## Parte 2 54 | 55 | ### Environment variables 56 | 57 | These properties define your DB/Service environment variables. They're necessary info for a proper connection between your APP and the DB. 58 | 59 | - Copy your info from railway given by the ```MySQL``` service and paste them in the format down bellow here, although it's not safe for your app because it will be visible from github. 60 | - All these environment variables are to be pasted in your service Variables before deploying 61 | - Save the bellow information in a .txt file or somewhere it won't get lost 62 | - Keep ```spring-profiles_active``` AND ```PROD_DB_NAME``` unmodified. 63 | - Watch out. Dont forget the first line. 64 | 65 | ```properties 66 | spring_profiles_active=prod 67 | PROD_DB_HOST=HOST_HERE 68 | PROD_DB_PORT=POST_HERE 69 | PROD_DB_NAME=railway 70 | PROD_DB_PASSWORD=PASSWORD_HERE 71 | PROD_DB_USERNAME=USER_HERE 72 | ``` 73 | --- 74 | 75 | ### SETUP - Spring Boot app 76 | --- 77 | 78 | ### SETUP - Spring Boot App - application-prod.yml 79 | 80 | - Check your app structure. It should look similar (although not quite the same) as the image bellow 81 | ![App structure](/img/springAppStructure.png) 82 | - Navigate untill you reach ```src/main/resources``` 83 | - Once there, create a new file inside ```/resources``` called ```application-prod.yml``` 84 | - Verify the extension 85 | 86 | - Copy and paste in there the following data 87 | ```yml 88 | spring: 89 | datasource: 90 | url: jdbc:mysql://${PROD_DB_HOST}:${PROD_DB_PORT}/${PROD_DB_NAME} 91 | username: ${PROD_DB_USERNAME} 92 | password: ${PROD_DB_PASSWORD} 93 | name: ecommerceDB 94 | 95 | sql: 96 | init: 97 | mode: always # you won't do this in prod, I'm just doing this for demo purposes 98 | ``` 99 | - Check tabulations. ```YAML``` files are weird 100 | 101 | 102 | ### SETUP - Spring Boot App - application.properties 103 | 104 | --- 105 | ### Optional 106 | - If you won't work locally, the following is server config for the ```application.properties``` file. 107 | - If you're still working both locally and remotely, this step can be skipped. 108 | --- 109 | 110 | - Update ```src/main/resources/application.properties``` and verify info. 111 | 112 | ```application.properties``` 113 | ```properties 114 | # spring.datasource.url= jdbc:mysql://localhost:3306/ecommercedb 115 | # The previous line is an example of a diff type of config for this file. 116 | spring.datasource.url= jdbc:mysql://${{ MYSQLUSER }}:${{ MYSQLPASSWORD }}@${{ MYSQLHOST }}:${{ MYSQLPORT }}/${{ MYSQLDATABASE }} 117 | spring.datasource.username=yourUser 118 | spring.datasource.password=yourPassword 119 | 120 | logging.level.org.hibernate.SQL=DEBUG 121 | ``` 122 | --- 123 | ### SETUP - Spring Boot App - Procfile 124 | 125 | This is a werid one. 126 | - On the root directory of your app. Create a new file **without** extension called ```Procfile``` 127 | - Triple check the name 128 | - Check the name and extension again 129 | 130 | Paste the following line inside 131 | ``` 132 | web: java -jar -Dserver.port=$PORT build/libs/ecommerceDB-0.0.1-SNAPSHOT.jar 133 | ``` 134 | 135 | - This is basic info for railway to identify the ```.jar``` file and the Port it should be working on. 136 | - It's important that the version ```0.0.1-SNAPSHOT.jar``` matches your project's 137 | - You can check inside ```build.gradle``` 138 | ```gradle 139 | version = '0.0.1-SNAPSHOT' 140 | ``` 141 | 142 | ## Part 3 143 | 144 | ### Github APP 145 | 146 | - Push your entire project on to a github repo 147 | - It can be public or private 148 | ![Github repository](/img/githubProject.png) 149 | 150 | - Leave it there 151 | 152 | ### Adding our App as a service 153 | 154 | - One of the few last steps is to add our App on railway as a service 155 | - Click on new service inside your railway project 156 | - Select GitHub repo and look for your Spring Boot App 157 | ![GitHub Repo](/img/githubRepo.png) 158 | - Once clicked it will begin a build and then a deploy 159 | - This first deploy will most likely fail due to environment variables not being Setup 160 | ![Build v1](/img/buildv1.png) 161 | - Click on your service and select the variables tab. 162 | - Once there, click on Raw Editor on the right handside 163 | - And paste our saved Environment Variables from MySLQ **Already edited and filled with your info** 164 | 165 | ```properties 166 | spring_profiles_active=prod 167 | PROD_DB_HOST=HOST_HERE 168 | PROD_DB_PORT=POST_HERE 169 | PROD_DB_NAME=railway 170 | PROD_DB_PASSWORD=PASSWORD_HERE 171 | PROD_DB_USERNAME=USER_HERE 172 | ``` 173 | 174 | It should look something like this: 175 | ![Environment Variables V2](/img/EnvironmentVar2.png) 176 | 177 | - Click on update Variables 178 | - Wait a bit and a new build should begin. 179 | 180 | 181 | ### Generate Domain 182 | 183 | - On your app menu inside railway, click on ```Settings``` 184 | - You'll see a button to generate a Domain. 185 | - Click on it 186 | - Now you can access you app from the web by accessing this url 187 | - All endpoints should be made after this initial URL 188 | 189 | ![domain](/img/domain.png) 190 | 191 | ## Other info 192 | 193 | - Check your available uptime hours on the top right corner 194 | - Be careful not to overdo this period 195 | ![Data period availability](/img/period.png) 196 | 197 | ## References 198 | 199 | [Spring boot Railway - Dan Vega](https://www.youtube.com/watch?v=5sVxvF47dcU&t=820s) 200 | -------------------------------------------------------------------------------- /setup-es.md: -------------------------------------------------------------------------------- 1 | # Test 2 | 3 | ## EcommerceDB 4 | 5 | ### Descripción 6 | 7 | Ésta es una aplicación Spring Boot a utilizar como base para deploys futuros en Railway 8 | 9 | No es una app lista para producción 10 | 11 | ### Info 12 | 13 | Hay un archivo llamado ```application-prod.yml``` utilizado para guardar configuración básica de producción. Éste archivo varará de contenido dependiento de la plataforma donde se haga el deploy. Se puede revisar para tener contexto. Su contenido en éste caso es epecíficamente para Railway 14 | 15 | 16 | ## Parte 1 17 | 18 | ### SETUP - Cuenta railway 19 | 20 | - Iniciar sesión o crear una nueva cuenta en railway 21 | - ![Railway login screen](/img/login.png) 22 | - Es recomendado crear cuenta desde GitHub para tener un más rápido acceso a repos. 23 | - [Railway.app](railway.app) 24 | 25 | ### SETUP - Nuevo proyecto 26 | 27 | - Crear un nuevo proyecto 28 | - Se puede hacer desde el botón en la parte superior derecha o dando click en el centro de la pantalla 29 | - ![New project screen](/img/newProject.png) 30 | - Recomiendo un proyecto vacío 31 | ![empty project screen](/img/empty.png) 32 | 33 | ### SETUP - Servicios 34 | 35 | ![Add Service](/img/addService.png) 36 | Los servicios trabajan similar a plugins que se agregan al proyecto. Pueden variar desde servicios de bases de datos como ```Mysql, PostgreSQL, MongoDB``` hasta ```Django, Laravel, DiscordJS bot, Kotlin, Vite, Vite + Vue + TS```, etc... Para éste proyecto se utilizará ```Mysql``` y nuestro propio servicio ```(Spring Boot App)``` el cual implementaremos directamente desde ```GitHub```. 37 | 38 | 39 | - Seleccionar agregar servicio -> Database -> Agregar MySQL 40 | ![Add Mysql](/img/mysql.png) 41 | 42 | - El servicio puede tardar en cofigurarse 43 | - Una vez creado, dar click en el servicio. Habrá varias tabs de información. 44 | - Se pueden crear tablas y DB directamente desde ```railway``` pero no lo necesitamos en este momento. 45 | ![MySQL tabs](/img/mysqltabs.png) 46 | 47 | ***Importante*** 48 | 49 | - Dar click en la tab de Variables (pueden estar en otras tabs ya que se actualiza de forma regular). Una vez ahí, trendremos toda la información para realizar nuestra conexión de la API hacia la BD. 50 | - Hay que mantener ésta información **privada** 51 | ![Mysql Variables](/img/mysqlvariables.png) 52 | 53 | ### Variables de entorno 54 | 55 | Éstas propiedades definen nuestro Servicio/BD. Son necesarias para una conexión apropiada entre nuestra APP y la BD. 56 | 57 | - Copia la info de railway dada por el serivcio ```MySQL``` y sustituye en el formato de abajo, ésto no es seguro para tu app ya que estará visible desde Github. 58 | - Todas las variables de entorno se pegarán en las VE de la App antes del deploy. 59 | - Guarda la información de abajo en un .txt o en algún lugar donde no se perderá 60 | - Mantén ```spring-profiles_active``` Y ```PROD_DB_NAME``` sin modificar. 61 | - Cuidado de no olvidar la primera linea 62 | 63 | ```properties 64 | spring_profiles_active=prod 65 | PROD_DB_HOST=HOST_HERE 66 | PROD_DB_PORT=POST_HERE 67 | PROD_DB_NAME=railway 68 | PROD_DB_PASSWORD=PASSWORD_HERE 69 | PROD_DB_USERNAME=USER_HERE 70 | ``` 71 | --- 72 | ### SETUP - Spring Boot App 73 | --- 74 | 75 | ### SETUP - Spring Boot App - application-prod.yml 76 | 77 | - Revisa la estructura de tu app en tu IDE. Debería ser similar (aunque no igual) a la imagen siguiente. 78 | ![App structure](/img/springAppStructure.png) 79 | - Navega hasta la carpeta ```src/main/resources``` 80 | - Una vez ahí, crea un nuevo archivo dentro de ```/resources``` llamado ```application-prod.yml``` 81 | - Verifica la extensión 82 | 83 | - Copia y pega dentro del archivo la siguente información 84 | ```yml 85 | spring: 86 | datasource: 87 | url: jdbc:mysql://${PROD_DB_HOST}:${PROD_DB_PORT}/${PROD_DB_NAME} 88 | username: ${PROD_DB_USERNAME} 89 | password: ${PROD_DB_PASSWORD} 90 | name: ecommerceDB 91 | 92 | sql: 93 | init: 94 | mode: always # you won't do this in prod, I'm just doing this for demo purposes 95 | ``` 96 | - Revisa la tabulación de los datos. Archivos ```YAML``` son extraños 97 | 98 | 99 | ### SETUP - Spring Boot App - application.properties 100 | --- 101 | ### Opcional 102 | - Si se dejará de trabajar de forma local la siguiente es la configuración para el archivo ```application.properties``` en el servidor. 103 | - En caso de continuar de forma local, se puede mantener el archivo sin modificar y saltar éste paso. 104 | 105 | --- 106 | - Actualiza el archivo ```src/main/resources/application.properties``` y verifica la información. 107 | ```application.properties``` 108 | ```properties 109 | # spring.datasource.url= jdbc:mysql://localhost:3306/ecommercedb 110 | # The previous line is an example of a diff type of config for this file. 111 | spring.datasource.url= jdbc:mysql://${{ MYSQLUSER }}:${{ MYSQLPASSWORD }}@${{ MYSQLHOST }}:${{ MYSQLPORT }}/${{ MYSQLDATABASE }} 112 | spring.datasource.username=yourUser 113 | spring.datasource.password=yourPassword 114 | 115 | logging.level.org.hibernate.SQL=DEBUG 116 | ``` 117 | --- 118 | ### SETUP - Spring Boot App - Procfile 119 | 120 | Atención al detalle 121 | - En el directorio root del proyecto (el inicio), crea un nuevo archivo **sin** extensión llamado ```Procfile``` 122 | - Revisa 3 veces el nombre 123 | - Revisa una vez mas el nombre y su extensión 124 | 125 | Pega lo siguiente dentro del archivo 126 | ``` 127 | web: java -jar -Dserver.port=$PORT build/libs/ecommerceDB-0.0.1-SNAPSHOT.jar 128 | ``` 129 | 130 | - Ésta es información básica para que railway identifique el archivo ```.jar``` y el puerto sobre el cuál debe trabajar. 131 | - Es importante que la versión ```0.0.1-SNAPSHOT.jar``` coincida con la de el proyecto. 132 | - Se puede verificar en ```build.gradle``` 133 | ```gradle 134 | version = '0.0.1-SNAPSHOT' 135 | ``` 136 | 137 | ## Parte 3 138 | 139 | ### Github App 140 | 141 | - Push de toda tu app a un repo de github 142 | - Puede ser pública o privada 143 | ![Github repository](/img/githubProject.png) 144 | 145 | - Mantén la app ahí 146 | 147 | ### Agregar nuestra app como servicio 148 | 149 | - Uno de los últimos pasos es agregar nuestra app a railway como un servicio 150 | - Da click en el botón de nuevo servicio dentro del proyecto en railway 151 | - Seleccionar Repo de Github y busca el repositorio con la app 152 | ![GitHub Repo](/img/githubRepo.png) 153 | - Una vez seleccionada comenzará a hacer un build y después intentará hacer deploy 154 | - Lo más seguro es que el deploy falle debido a la falta de configuración de variables de entorno 155 | ![Build v1](/img/buildv1.png) 156 | - Da click en el servicio y selecciona la tab de variabes. 157 | - Una vez ahí, selecciona Raw Editor de la parte derecha 158 | - Pega las variables de entorno guardadas de ```MySQL``` **Ya editadas y con la información dada en el servicio** 159 | 160 | ```properties 161 | spring_profiles_active=prod 162 | PROD_DB_HOST=HOST_HERE 163 | PROD_DB_PORT=POST_HERE 164 | PROD_DB_NAME=railway 165 | PROD_DB_PASSWORD=PASSWORD_HERE 166 | PROD_DB_USERNAME=USER_HERE 167 | ``` 168 | 169 | Debería verse algo así: 170 | ![Environment Variables V2](/img/EnvironmentVar2.png) 171 | 172 | - Da click en actualizar variables 173 | - Espera un poco y un nuevo build debería comenzar 174 | 175 | ### Generar dominio 176 | 177 | - En el menú de la app en railway, da click en ```Settings``` 178 | - Hay un botón para generar un dominio 179 | - Click 180 | - Ahora se puede acceder a la app desde la web por medio de éste URL 181 | - Todos los endpoints deben ser accedidos a partir de ésta URL inicial 182 | 183 | ![domain](/img/domain.png) 184 | 185 | ## Otra información 186 | 187 | - Revisar horas disponibles de actividad 188 | - Tener cuidado de no sobrepasar éstas horas 189 | ![Data period availability](/img/period.png) 190 | 191 | ## Referencias 192 | 193 | [Spring boot Railway - Dan Vega](https://www.youtube.com/watch?v=5sVxvF47dcU&t=820s) 194 | --------------------------------------------------------------------------------