diff --git a/.dockerignore b/.dockerignore index 199c8c2..67b26eb 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,4 +3,5 @@ .vscode .gitignore node_modules -mongo \ No newline at end of file +mongo +mongo-volume \ No newline at end of file diff --git a/.gitignore b/.gitignore index dbc1565..e160b25 100644 --- a/.gitignore +++ b/.gitignore @@ -36,4 +36,5 @@ next-env.d.ts postgres -mongo \ No newline at end of file +mongo +mongo-volume \ No newline at end of file diff --git a/app/lib/auth.ts b/app/lib/auth.ts index a32437f..182fa3f 100644 --- a/app/lib/auth.ts +++ b/app/lib/auth.ts @@ -38,6 +38,7 @@ const authConfig: NextAuthConfig = { }), ], secret: process.env.AUTH_SECRET, + trustHost: true, // needs to be set to false for the NextJS to work behing Traefik session: { // Use JSON Web Tokens for session instead of database sessions. // This option can be used with or without a database for users/accounts. diff --git a/docker-compose-deploy.yml b/docker-compose-deploy.yml index c64385e..927a654 100644 --- a/docker-compose-deploy.yml +++ b/docker-compose-deploy.yml @@ -1,19 +1,35 @@ # this compose file runs Postgres db and exposes it's port to the host machine version: "3.7" +networks: + traefik-network: + name: "traefik-network" + services: web-app: image: utility-bills-tracker:1.0.0 - ports: - - 3000:3000 + networks: + - traefik-network # komunikacija sa Traefikom environment: MONGODB_URI: mongodb://root:example@mongo:27017/ GOOGLE_ID: 355397364527-adjrokm6hromcaaar0qfhk050mfr35ou.apps.googleusercontent.com GOOGLE_SECRET: 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 AUTH_SECRET: Gh0jQ35oq6DR8HkLR3heA8EaEDtxYN/xkP6blvukZ0w= - HOSTNAME: ${HOSTNAME:-0.0.0.0} # IP address at which the server will be listening (0.0.0.0 = listen on all addresses) - NEXTAUTH_URL: ${NEXTAUTH_URL:-http://localhost:3000} # URL next-auth will use while redirecting user during authentication (if not set - will use HOSTNAME) + # HOSTNAME: rezije.localhost # IP address at which the server will be listening (0.0.0.0 = listen on all addresses) + EXTAUTH_URL: ${HOSTNAME:-http://rezije.localhost:3000) # URL next-auth will use while redirecting user during authentication (if not set - will use HOSTNAME) PORT: ${PORT:-3000} + deploy: + # u slucaju rušenja kontejnera čekamo 5s i dižemo novi kontejner => ako se i on sruši opet ceka 5s i pokusava ponovno (tako 5 puta) + restart_policy: + condition: any + delay: 5s + max_attempts: 0 # u slučaju rušenja containera pokušavaj ga pokrenuti dok ne uspije = BESKONAČNO + labels: + - traefik.enable=true + - traefik.docker.network=traefik-network # mreže preko koje ide komunikacija sa Traefikom + - traefik.http.services.web-app.loadbalancer.server.port=3000 + - traefik.http.routers.web-app.entrypoints=http + - traefik.http.routers.web-app.rule=Host(`${FQDN:-rezije.localhost)`) mongo: image: mongo:6.0.12 environment: @@ -23,10 +39,48 @@ services: - ./mongo-volume:/data/db mongo-express: image: mongo-express - ports: - - 8081:8081 environment: ME_CONFIG_MONGODB_ADMINUSERNAME: root ME_CONFIG_MONGODB_ADMINPASSWORD: example ME_CONFIG_MONGODB_URL: mongodb://root:example@mongo:27017/ + networks: + - traefik-network # komunikacija sa Traefikom + deploy: + # u slucaju rušenja kontejnera čekamo 5s i dižemo novi kontejner => ako se i on sruši opet ceka 5s i pokusava ponovno (tako 5 puta) + restart_policy: + condition: any + delay: 5s + max_attempts: 0 # u slučaju rušenja containera pokušavaj ga pokrenuti dok ne uspije = BESKONAČNO + labels: + - traefik.enable=true + - traefik.docker.network=traefik-network # mreže preko koje ide komunikacija sa Traefikom + - traefik.http.services.mongo-express.loadbalancer.server.port=8001 + - traefik.http.routers.mongo-express.entrypoints=http + - traefik.http.routers.mongo-express.rule=Host(`mongo.localhost`) + + reverse-proxy: + image: traefik:v2.3 + command: + # Traefik web konzoli se pristupa preko HTTP, a ne HTTPS + - --api.insecure=true + - --providers.docker + # activates the Swarm Mode (instead of standalone Docker). + # - kada je `false` neće detektirati containere kada se pokrene sa `docker-compose up` + - --providers.docker.swarmMode=true + # prikazuj samo containere koji su nakačeni na Traefik + - --providers.docker.exposedByDefault=false + # "ping" omogućujemo za potrebe healthcheck-a + - --ping=true + - --ping.entryPoint=traefik + #- --accesslog=true + #- --log.level=DEBUG + - --entryPoints.http.address=:3000 + ports: + - "3001:3000" + - "8080:8080" + volumes: + # So that Traefik can listen to the Docker events + - /var/run/docker.sock:/var/run/docker.sock + networks: + - traefik-network