diff --git a/deploy-swarm.sh b/deploy-swarm.sh new file mode 100755 index 0000000..484b38d --- /dev/null +++ b/deploy-swarm.sh @@ -0,0 +1,17 @@ +#!/bin/bash +if [ "$1" == "" ] ; then + printf "\nNisi zadao verziju Docker image-a koji treba deployati" + printf "\n\nSintaksa:\n\n deploy.sh 1.0.0\n\n" + exit 1 +fi + +printf "\nBUILD START ...\n\n" + +IMAGE_VERSION=$1 + +echo "Deploying $STACK_NAME with image version: $IMAGE_VERSION" + +# Pass IMAGE_VERSION env var for compose variable substitution +IMAGE_VERSION="$IMAGE_VERSION" docker stack deploy \ + -c docker-compose-deploy.yml \ + utility-bills-tracker \ No newline at end of file diff --git a/deploy.sh b/deploy.sh index 484b38d..b13b3a4 100755 --- a/deploy.sh +++ b/deploy.sh @@ -12,6 +12,4 @@ IMAGE_VERSION=$1 echo "Deploying $STACK_NAME with image version: $IMAGE_VERSION" # Pass IMAGE_VERSION env var for compose variable substitution -IMAGE_VERSION="$IMAGE_VERSION" docker stack deploy \ - -c docker-compose-deploy.yml \ - utility-bills-tracker \ No newline at end of file +IMAGE_VERSION="$IMAGE_VERSION" docker compose up -d \ No newline at end of file diff --git a/docker-compose-swarm.yml b/docker-compose-swarm.yml new file mode 100644 index 0000000..290ba21 --- /dev/null +++ b/docker-compose-swarm.yml @@ -0,0 +1,73 @@ +# this compose file runs Postgres db and exposes it's port to the host machine +version: "3.7" + +networks: + traefik-network: + name: "traefik-network" + external: true + mongo-network: + name: "mongo-network" + attachable: false + external: false + internal: true + +services: + web-app: + image: utility-bills-tracker:${IMAGE_VERSION} + networks: + - traefik-network + - mongo-network + volumes: + - ./etc/hosts/:/etc/hosts + 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= + LINKEDIN_ID: 776qlcsykl1rag + LINKEDIN_SECRET: ugf61aJ2iyErLK40 + HOSTNAME: rezije.app # IP address at which the server will be listening (0.0.0.0 = listen on all addresses) + NEXTAUTH_URL: https://rezije.app # URL next-auth will use while redirecting user during authentication (if not set - will use HOSTNAME) + PORT: ${PORT:-80} + 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=80 + - traefik.http.routers.web-app.entrypoints=http + - traefik.http.routers.web-app.rule=Host(`${FQDN:-rezije.app}`) + mongo: + image: mongo:4.4.27 + environment: + MONGO_INITDB_ROOT_USERNAME: root + MONGO_INITDB_ROOT_PASSWORD: example + volumes: + - ./mongo-volume:/data/db + networks: + - mongo-network + mongo-express: + image: mongo-express + environment: + ME_CONFIG_MONGODB_ADMINUSERNAME: root + ME_CONFIG_MONGODB_ADMINPASSWORD: example + ME_CONFIG_MONGODB_URL: mongodb://root:example@mongo:27017/ + networks: + - traefik-network + - mongo-network + 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=8081 + - traefik.http.routers.mongo-express.entrypoints=http + - traefik.http.routers.mongo-express.rule=Host(`mongo.rezije.app`) diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..0e37f30 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,72 @@ +# docker-compose.yml +version: "3.9" + +networks: + traefik-network: + name: traefik-network + external: true + mongo-network: + name: mongo-network + internal: true # bridge network, isolated from host and other networks + +services: + web-app: + image: utility-bills-tracker:${IMAGE_VERSION} + container_name: evidencija-rezija__web-app + restart: unless-stopped # u slučaju rušenja containera pokušavaj ga pokrenuti dok ne uspije = BESKONAČNO + networks: + - traefik-network + - mongo-network + depends_on: + - mongo + volumes: + - ./etc/hosts/:/etc/hosts + 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= + LINKEDIN_ID: 776qlcsykl1rag + LINKEDIN_SECRET: ugf61aJ2iyErLK40 + HOSTNAME: rezije.app # IP address at which the server will be listening (0.0.0.0 = listen on all addresses) + NEXTAUTH_URL: https://rezije.app # URL next-auth will use while redirecting user during authentication (if not set - will use HOSTNAME) + PORT: ${PORT:-80} + 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=80 + - traefik.http.routers.web-app.entrypoints=http + - traefik.http.routers.web-app.rule=Host(`${FQDN:-rezije.app}`) + + mongo: + image: mongo:4.4.27 + container_name: evidencija-rezija__mongo + restart: unless-stopped # u slučaju rušenja containera pokušavaj ga pokrenuti dok ne uspije = BESKONAČNO + environment: + MONGO_INITDB_ROOT_USERNAME: root + MONGO_INITDB_ROOT_PASSWORD: example + volumes: + - ./mongo-volume:/data/db + networks: + - mongo-network + + mongo-express: + image: mongo-express + container_name: evidencija-rezija__mongo-express + restart: unless-stopped + networks: + - traefik-network + - mongo-network + depends_on: + - mongo + environment: + ME_CONFIG_MONGODB_ADMINUSERNAME: root + ME_CONFIG_MONGODB_ADMINPASSWORD: example + ME_CONFIG_MONGODB_URL: mongodb://root:example@mongo:27017/ + 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=8081 + - traefik.http.routers.mongo-express.entrypoints=http + - traefik.http.routers.mongo-express.rule=Host(`mongo.rezije.app`) +