Skip to content

Commit

Permalink
environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
while1618 committed Dec 22, 2024
1 parent 7e8e588 commit 42020e8
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 39 deletions.
45 changes: 34 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@

### Run

To run the application via docker, you'll need to create `.env` file in `frontend/svelte-kit` with
the following data:

```bash
JWT_SECRET=secret
API_URL=http://bootstrapbugz-api:8080/v1
```

Then run docker-compose from the root directory:
Just run docker-compose from the root directory:

```bash
docker-compose up --build -d
Expand All @@ -25,9 +17,40 @@ You can find the application on the following urls:

- ui: http://localhost:5174
- api: http://localhost:8081/v1/users
- swagger-ui: http://localhost:8081/swagger-ui/index.html
- api-docs: http://localhost:8081/swagger-ui/index.html

Login credentials:

- username: user/admin
- password: qwerty123
- password: qwerty123


### Environment variables

| Variable | Description | Default |
| ------------------------ | --------------------------------------------------------------------- | -------------------------------- |
| APP_NAME | Name of the app that will be used in the application | BootstrapBugZ |
| API_URL | URL on which API is running | http://bootstrapbugz-api:8080/v1 |
| UI_URL | URL on which UI is running | http://bootstrapbugz-ui:5173 |
| UI_PORT | Port on which you'll find UI running | 5173 |
| EXPOSED_UI_PORT | Port on which UI will be exposed when running via docker | 5174 |
| SERVER_PORT | Port on which you'll find API running | 8080 |
| EXPOSED_SERVER_PORT | Port on which API will be exposed when running via docker | 8081 |
| POSTGRES_HOST | Host on which postgres is running, used when locally starting the API | localhost |
| POSTGRES_PORT | Port on which you'll find postgres running | 5432 |
| EXPOSED_POSTGRES_PORT | Port on which postgres will be exposed when running via docker | 5433 |
| POSTGRES_DATABASE | Name of the postgres database | bootstrapbugz |
| POSTGRES_USERNAME | Postgres username | postgres |
| POSTGRES_PASSWORD | Postgres password | root |
| REDIS_HOST | Host on which redis is running, used when locally starting the API | 127.0.0.1 |
| REDIS_PORT | Port on which you'll find redis running | 6379 |
| EXPOSED_REDIS_PORT | Port on which redis will be exposed when running via docker | 6380 |
| REDIS_DATABASE | Name of the redis database | 0 |
| REDIS_PASSWORD | Redis password | root |
| MAIL_HOST | SMTP host | smtp.mailgun.org |
| MAIL_PORT | SMTP port | 587 |
| MAIL_USERNAME | SMTP username | username |
| MAIL_PASSWORD | SMTP password | password |
| JWT_SECRET | Secret used to sign jwt | secret |
| SPRING_SECURITY_PASSWORD | Password used for auto-generated users | qwerty123 |
| HTTP_PROTOCOL | http protocol | http |
32 changes: 23 additions & 9 deletions backend/spring-boot/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@ services:
image: bootstrapbugz-api:1.0.0
build: .
ports:
- "8081:8080"
- "${EXPOSED_SERVER_PORT:-8081}:${SERVER_PORT:-8080}"
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres/${POSTGRES_DATABASE:-bootstrapbugz}
APP_NAME: ${APP_NAME:-BootstrapBugZ}
SERVER_PORT: ${SERVER_PORT:-8080}
UI_URL: ${UI_URL:-http://localhost:5173}
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:${POSTGRES_PORT:-5432}/${POSTGRES_DATABASE:-bootstrapbugz}
SPRING_DATASOURCE_USERNAME: ${POSTGRES_USERNAME:-postgres}
SPRING_DATASOURCE_PASSWORD: ${POSTGRES_PASSWORD:-root}
SPRING_DATA_REDIS_HOST: ${REDIS_HOST:-redis}
SPRING_DATA_REDIS_DATABASE: ${REDIS_DATABASE:-0}
SPRING_DATA_REDIS_HOST: redis
SPRING_DATA_REDIS_PORT: ${REDIS_PORT:-6379}
SPRING_DATA_REDIS_PASSWORD: ${REDIS_PASSWORD:-root}
SPRING_SECURITY_USER_PASSWORD: ${SPRING_SECURITY_PASSWORD:-qwerty123}
SPRING_MAIL_HOST: ${MAIL_HOST:-smtp.mailgun.org}
SPRING_MAIL_PORT: ${MAIL_PORT:-587}
SPRING_MAIL_USERNAME: ${MAIL_USERNAME:-username}
SPRING_MAIL_PASSWORD: ${MAIL_PASSWORD:-password}
JWT_SECRET: ${JWT_SECRET:-secret}
depends_on:
- postgres
- redis
Expand All @@ -21,7 +31,7 @@ services:
"CMD",
"curl",
"-f",
"${PROTOCOL:-http}://localhost:8080/actuator/health",
"${HTTP_PROTOCOL:-http}://localhost:${SERVER_PORT:-8080}/actuator/health",
]
start_period: 10s
interval: 30s
Expand All @@ -31,8 +41,9 @@ services:
container_name: postgres
image: postgres:17.2-alpine
ports:
- "5433:5432"
- "${EXPOSED_POSTGRES_PORT:-5433}:${POSTGRES_PORT:-5432}"
environment:
PGPORT: ${POSTGRES_PORT:-5432}
POSTGRES_DB: ${POSTGRES_DATABASE:-bootstrapbugz}
POSTGRES_USER: ${POSTGRES_USERNAME:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-root}
Expand All @@ -42,7 +53,7 @@ services:
"CMD",
"pg_isready",
"-U",
"postgres",
"${POSTGRES_USERNAME:-postgres}",
"-d",
"${POSTGRES_DATABASE:-bootstrapbugz}",
]
Expand All @@ -54,17 +65,20 @@ services:
container_name: redis
image: redis:7.4.1
ports:
- "6380:6379"
command: redis-server --requirepass ${REDIS_PASSWORD:-root}
- "${EXPOSED_REDIS_PORT:-6380}:${REDIS_PORT:-6379}"
command: redis-server --port ${REDIS_PORT:-6379} --requirepass ${REDIS_PASSWORD:-root}
environment:
- REDIS_DISABLE_COMMANDS=FLUSHDB,FLUSHALL
REDIS_DATABASE: ${REDIS_DATABASE:-0}
REDIS_PASSWORD: ${REDIS_PASSWORD:-root}
healthcheck:
test:
[
"CMD",
"redis-cli",
"-h",
"localhost",
"-p",
"${REDIS_PORT:-6379}",
"-a",
"${REDIS_PASSWORD:-root}",
"ping",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void sendEmail(EmailService emailService, Environment environment, User u
throws IOException, MessagingException {
final var template =
new ClassPathResource("templates/email/reset-password.html").getInputStream();
final var link = environment.getProperty("ui.app.url") + "/auth/reset-password?token=" + token;
final var link = environment.getProperty("ui.url") + "/auth/reset-password?token=" + token;
final var body =
CharStreams.toString(new InputStreamReader(template, StandardCharsets.UTF_8))
.replace("${name}", user.getUsername())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void sendEmail(EmailService emailService, Environment environment, User u
throws IOException, MessagingException {
final var template =
new ClassPathResource("templates/email/verify-email.html").getInputStream();
final var link = environment.getProperty("ui.app.url") + "/auth/verify-email?token=" + token;
final var link = environment.getProperty("ui.url") + "/auth/verify-email?token=" + token;
final var body =
CharStreams.toString(new InputStreamReader(template, StandardCharsets.UTF_8))
.replace("${name}", user.getUsername())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"description": "Application name."
},
{
"name": "ui.app.url",
"name": "ui.url",
"type": "java.lang.String",
"description": "UI application URL."
},
Expand Down
6 changes: 3 additions & 3 deletions backend/spring-boot/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# app
app.name=BootstrapBugZ
ui.app.url=${UI_APP_URL:http://localhost:5173}
server.port=${API_PORT:8080}
app.name=${APP_NAME:BootstrapBugZ}
server.port=${SERVER_PORT:8080}
ui.url=${UI_URL:http://localhost:5173}
# database
spring.sql.init.platform=postgres
spring.datasource.url=jdbc:postgresql://${POSTGRES_HOST:localhost}:${POSTGRES_PORT:5432}/${POSTGRES_DATABASE:bootstrapbugz}
Expand Down
47 changes: 34 additions & 13 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,24 @@ services:
context: ./backend/spring-boot
dockerfile: Dockerfile
ports:
- "8081:8080"
- "${EXPOSED_SERVER_PORT:-8081}:${SERVER_PORT:-8080}"
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres/${POSTGRES_DATABASE:-bootstrapbugz}
APP_NAME: ${APP_NAME:-BootstrapBugZ}
SERVER_PORT: ${SERVER_PORT:-8080}
UI_URL: ${UI_URL:-http://bootstrapbugz-ui:5173}
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:${POSTGRES_PORT:-5432}/${POSTGRES_DATABASE:-bootstrapbugz}
SPRING_DATASOURCE_USERNAME: ${POSTGRES_USERNAME:-postgres}
SPRING_DATASOURCE_PASSWORD: ${POSTGRES_PASSWORD:-root}
SPRING_DATA_REDIS_HOST: ${REDIS_HOST:-redis}
SPRING_DATA_REDIS_DATABASE: ${REDIS_DATABASE:-0}
SPRING_DATA_REDIS_HOST: redis
SPRING_DATA_REDIS_PORT: ${REDIS_PORT:-6379}
SPRING_DATA_REDIS_PASSWORD: ${REDIS_PASSWORD:-root}
SPRING_SECURITY_USER_PASSWORD: ${SPRING_SECURITY_PASSWORD:-qwerty123}
SPRING_MAIL_HOST: ${MAIL_HOST:-smtp.mailgun.org}
SPRING_MAIL_PORT: ${MAIL_PORT:-587}
SPRING_MAIL_USERNAME: ${MAIL_USERNAME:-username}
SPRING_MAIL_PASSWORD: ${MAIL_PASSWORD:-password}
JWT_SECRET: ${JWT_SECRET:-secret}
depends_on:
- postgres
- redis
Expand All @@ -23,7 +33,7 @@ services:
"CMD",
"curl",
"-f",
"${PROTOCOL:-http}://localhost:8080/actuator/health",
"${HTTP_PROTOCOL:-http}://localhost:${SERVER_PORT:-8080}/actuator/health",
]
start_period: 10s
interval: 30s
Expand All @@ -33,8 +43,9 @@ services:
container_name: postgres
image: postgres:17.2-alpine
ports:
- "5433:5432"
- "${EXPOSED_POSTGRES_PORT:-5433}:${POSTGRES_PORT:-5432}"
environment:
PGPORT: ${POSTGRES_PORT:-5432}
POSTGRES_DB: ${POSTGRES_DATABASE:-bootstrapbugz}
POSTGRES_USER: ${POSTGRES_USERNAME:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-root}
Expand All @@ -44,7 +55,7 @@ services:
"CMD",
"pg_isready",
"-U",
"postgres",
"${POSTGRES_USERNAME:-postgres}",
"-d",
"${POSTGRES_DATABASE:-bootstrapbugz}",
]
Expand All @@ -56,17 +67,20 @@ services:
container_name: redis
image: redis:7.4.1
ports:
- "6380:6379"
command: redis-server --requirepass ${REDIS_PASSWORD:-root}
- "${EXPOSED_REDIS_PORT:-6380}:${REDIS_PORT:-6379}"
command: redis-server --port ${REDIS_PORT:-6379} --requirepass ${REDIS_PASSWORD:-root}
environment:
- REDIS_DISABLE_COMMANDS=FLUSHDB,FLUSHALL
REDIS_DATABASE: ${REDIS_DATABASE:-0}
REDIS_PASSWORD: ${REDIS_PASSWORD:-root}
healthcheck:
test:
[
"CMD",
"redis-cli",
"-h",
"localhost",
"-p",
"${REDIS_PORT:-6379}",
"-a",
"${REDIS_PASSWORD:-root}",
"ping",
Expand All @@ -81,14 +95,21 @@ services:
build:
context: ./frontend/svelte-kit
dockerfile: Dockerfile
env_file:
- ./frontend/svelte-kit/.env
environment:
JWT_SECRET: ${JWT_SECRET:-secret}
API_URL: ${API_URL:-http://bootstrapbugz-api:8080/v1}
ports:
- "5174:5173"
- "${EXPOSED_UI_PORT:-5174}:${UI_PORT:-5173}"
depends_on:
- bootstrapbugz-api
healthcheck:
test: ["CMD", "curl", "-f", "${PROTOCOL:-http}://localhost:5173"]
test:
[
"CMD",
"curl",
"-f",
"${HTTP_PROTOCOL:-http}://localhost:${UI_PORT:-5173}",
]
start_period: 10s
interval: 30s
retries: 3

0 comments on commit 42020e8

Please sign in to comment.