Compare commits

...

4 Commits

Author SHA1 Message Date
2e2e75fe87 fix: update JwtService to handle default expiration and add tests for token generation
All checks were successful
Build And Publish Production Image / Build And Publish Production Image (push) Successful in 39s
2026-03-28 03:40:03 -03:00
8f508034d5 fix: update Docker configuration for image source and enhance logging in supervisord
All checks were successful
Build And Publish Production Image / Build And Publish Production Image (push) Successful in 14s
2026-03-28 03:32:08 -03:00
7108aff54d fix: add access and error log configuration for Nginx
All checks were successful
Build And Publish Production Image / Build And Publish Production Image (push) Successful in 39s
2026-03-28 03:26:50 -03:00
b0a4278699 fix: update stack deployment to use production Docker Compose file 2026-03-28 03:25:35 -03:00
8 changed files with 57 additions and 8 deletions

View File

@@ -132,7 +132,7 @@ jobs:
echo "Existing stack found with id=${STACK_ID}; sending update request" echo "Existing stack found with id=${STACK_ID}; sending update request"
PAYLOAD=$(jq -n \ PAYLOAD=$(jq -n \
--rawfile stack_file docker-compose.yml \ --rawfile stack_file docker-compose.prod.yml \
'{StackFileContent: $stack_file, Env: [], Prune: false, PullImage: false}') '{StackFileContent: $stack_file, Env: [], Prune: false, PullImage: false}')
APPLY_HTTP_CODE=$(curl -sS -X PUT \ APPLY_HTTP_CODE=$(curl -sS -X PUT \
@@ -150,7 +150,7 @@ jobs:
PAYLOAD=$(jq -n \ PAYLOAD=$(jq -n \
--arg name "${STACK_NAME}" \ --arg name "${STACK_NAME}" \
--rawfile stack_file docker-compose.yml \ --rawfile stack_file docker-compose.prod.yml \
'{Name: $name, StackFileContent: $stack_file, Env: [], FromAppTemplate: false}') '{Name: $name, StackFileContent: $stack_file, Env: [], FromAppTemplate: false}')
APPLY_HTTP_CODE=$(curl -sS -X POST \ APPLY_HTTP_CODE=$(curl -sS -X POST \

View File

@@ -14,8 +14,10 @@ import java.util.Date
@Service @Service
class JwtService( class JwtService(
@Value("\${app.jwt.secret}") val secret: String, @Value("\${app.jwt.secret}") val secret: String,
@Value("\${app.jwt.expiration-ms}") val expirationMs: Long @Value("\${app.jwt.expiration-ms:86400000}") expirationMsRaw: String
) { ) {
private val expirationMs: Long = expirationMsRaw.toLongOrNull() ?: 86400000L
private val signingKey by lazy { private val signingKey by lazy {
Keys.hmacShaKeyFor(secret.toByteArray(Charsets.UTF_8)) Keys.hmacShaKeyFor(secret.toByteArray(Charsets.UTF_8))
} }

View File

@@ -40,7 +40,7 @@ class AuthServiceTest {
fun should_returnValidClaims_when_jwtTokenParsed() { fun should_returnValidClaims_when_jwtTokenParsed() {
val realJwtService = JwtService( val realJwtService = JwtService(
secret = "test-secret-key-for-testing-only-must-be-at-least-32-characters", secret = "test-secret-key-for-testing-only-must-be-at-least-32-characters",
expirationMs = 86400000L expirationMsRaw = "86400000"
) )
val token = realJwtService.generateToken() val token = realJwtService.generateToken()
@@ -51,7 +51,7 @@ class AuthServiceTest {
fun should_returnFalse_when_expiredTokenValidated() { fun should_returnFalse_when_expiredTokenValidated() {
val realJwtService = JwtService( val realJwtService = JwtService(
secret = "test-secret-key-for-testing-only-must-be-at-least-32-characters", secret = "test-secret-key-for-testing-only-must-be-at-least-32-characters",
expirationMs = 1L expirationMsRaw = "1"
) )
val token = realJwtService.generateToken() val token = realJwtService.generateToken()

View File

@@ -0,0 +1,26 @@
package com.condado.newsletter.service
import io.jsonwebtoken.Jwts
import io.jsonwebtoken.security.Keys
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
class JwtServiceTest {
private val secret = "12345678901234567890123456789012"
@Test
fun should_generate_token_when_expiration_is_empty() {
val jwtService = JwtService(secret, "")
val token = jwtService.generateToken()
val claims = Jwts.parser()
.verifyWith(Keys.hmacShaKeyFor(secret.toByteArray(Charsets.UTF_8)))
.build()
.parseSignedClaims(token)
.payload
assertTrue(claims.expiration.after(claims.issuedAt))
}
}

View File

@@ -1,6 +1,6 @@
services: services:
condado-newsletter: condado-newsletter:
image: sancho41/condado-newsletter:latest image: gitea.lab:80/sancho41/condado-newsletter:latest
container_name: condado-newsletter container_name: condado-newsletter
restart: unless-stopped restart: unless-stopped
environment: environment:
@@ -9,7 +9,7 @@ services:
SPRING_DATASOURCE_PASSWORD: ${SPRING_DATASOURCE_PASSWORD} SPRING_DATASOURCE_PASSWORD: ${SPRING_DATASOURCE_PASSWORD}
APP_PASSWORD: ${APP_PASSWORD} APP_PASSWORD: ${APP_PASSWORD}
JWT_SECRET: ${JWT_SECRET} JWT_SECRET: ${JWT_SECRET}
JWT_EXPIRATION_MS: ${JWT_EXPIRATION_MS} JWT_EXPIRATION_MS: ${JWT_EXPIRATION_MS:-86400000}
MAIL_HOST: ${MAIL_HOST} MAIL_HOST: ${MAIL_HOST}
MAIL_PORT: ${MAIL_PORT} MAIL_PORT: ${MAIL_PORT}
MAIL_USERNAME: ${MAIL_USERNAME} MAIL_USERNAME: ${MAIL_USERNAME}

View File

@@ -27,6 +27,22 @@ mkdir -p /var/log/supervisor
export SPRING_DATASOURCE_URL=${SPRING_DATASOURCE_URL:-jdbc:postgresql://localhost:5432/${APP_DB_NAME}} export SPRING_DATASOURCE_URL=${SPRING_DATASOURCE_URL:-jdbc:postgresql://localhost:5432/${APP_DB_NAME}}
export SPRING_DATASOURCE_USERNAME=${SPRING_DATASOURCE_USERNAME:-${APP_DB_USER}} export SPRING_DATASOURCE_USERNAME=${SPRING_DATASOURCE_USERNAME:-${APP_DB_USER}}
export SPRING_DATASOURCE_PASSWORD=${SPRING_DATASOURCE_PASSWORD:-${APP_DB_PASSWORD}} export SPRING_DATASOURCE_PASSWORD=${SPRING_DATASOURCE_PASSWORD:-${APP_DB_PASSWORD}}
export JWT_EXPIRATION_MS=${JWT_EXPIRATION_MS:-86400000}
# ── Log all Spring Boot environment variables for debugging ──────────────────
echo "========================================"
echo "Spring Boot Configuration:"
echo "========================================"
echo "SPRING_DATASOURCE_URL=${SPRING_DATASOURCE_URL}"
echo "SPRING_DATASOURCE_USERNAME=${SPRING_DATASOURCE_USERNAME}"
echo "SPRING_DATASOURCE_PASSWORD=${SPRING_DATASOURCE_PASSWORD}"
echo "JWT_EXPIRATION_MS=${JWT_EXPIRATION_MS}"
echo "JAVA_OPTS=${JAVA_OPTS:-not set}"
echo "OPENAI_API_KEY=${OPENAI_API_KEY:-not set}"
echo "========================================"
# ── Start all services via supervisord ─────────────────────────────────────── # ── Start all services via supervisord ───────────────────────────────────────
# Export unbuffered output for both Python and Java
export PYTHONUNBUFFERED=1
export JAVA_OPTS="${JAVA_OPTS} -Dfile.encoding=UTF-8 -Djava.awt.headless=true"
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf

View File

@@ -1,8 +1,10 @@
[supervisord] [supervisord]
nodaemon=true nodaemon=true
silent=false
logfile=/dev/stdout logfile=/dev/stdout
logfile_maxbytes=0 logfile_maxbytes=0
pidfile=/var/run/supervisord.pid pidfile=/var/run/supervisord.pid
loglevel=info
[program:postgres] [program:postgres]
command=/usr/lib/postgresql/16/bin/postgres -D /var/lib/postgresql/data command=/usr/lib/postgresql/16/bin/postgres -D /var/lib/postgresql/data
@@ -15,7 +17,7 @@ stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0 stderr_logfile_maxbytes=0
[program:backend] [program:backend]
command=java -jar /app/app.jar command=java -Dspring.output.ansi.enabled=always -Dlogging.level.root=DEBUG -jar /app/app.jar
autostart=true autostart=true
autorestart=true autorestart=true
startsecs=15 startsecs=15

View File

@@ -15,6 +15,9 @@ http {
gzip_types text/plain text/css application/json application/javascript gzip_types text/plain text/css application/json application/javascript
text/xml application/xml application/xml+rss text/javascript; text/xml application/xml application/xml+rss text/javascript;
access_log /dev/stdout;
error_log /dev/stderr;
server { server {
listen 80; listen 80;
server_name _; server_name _;