diff --git a/Makefile b/Makefile index b4f16b94..4b6532f2 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,16 @@ build: mvn -DskipTests package - docker compose build + docker build ./services/jobs --tag workup:service_jobs + docker build ./services/payments --tag workup:service_payments + docker build ./services/users --tag workup:service_users + docker build ./services/contracts --tag workup:service_contracts up: - docker compose up --force-recreate + docker stack deploy -c compose.yaml -c compose.override.yaml workup + +portainer: + docker stack deploy -c portainer-agent-stack.yml portainer reload: mvn -DskipTests package diff --git a/compose.override.yaml b/compose.override.yaml new file mode 100644 index 00000000..4bf143fb --- /dev/null +++ b/compose.override.yaml @@ -0,0 +1,11 @@ + +version: '3.7' +services: + service_jobs: + image: workup:service_jobs + + service_payments: + image: workup:service_payments + + service_contracts: + image: workup:service_contracts diff --git a/compose.yaml b/compose.yaml index ca0db906..e6ac13d3 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,5 +1,6 @@ # This docker compose is for testing a real production env locally.. # Simulates a network etc. +version: '3.7' services: # ----- GENERAL SERVICES ------- @@ -11,53 +12,32 @@ services: timeout: 30s retries: 3 networks: - - microservices - ports: - - "5672:5672" - - "15672:15672" - + - default + service_redis: - image: redis:latest + image: redis:7.2.4 healthcheck: test: redis-cli ping interval: 30s timeout: 30s retries: 3 networks: - - microservices - ports: - - "6379:6379" + - default # ----- JOBS MICROSERVICE ------- service_jobs: - build: ./services/jobs + image: ahmad45123/workup:service_jobs depends_on: - jobs_db: - condition: service_healthy - service_mq: - condition: service_healthy + - jobs_db + - service_mq networks: - - microservices + - default - jobs - - # ----- PAYMENTS MICROSERVICE ------- - service_payments: - build: ./services/payments - depends_on: - payments_db: - condition: service_healthy - service_mq: - condition: service_healthy - service_redis: - condition: service_healthy - networks: - - microservices - - payments + env_file: + - ./services/jobs/.env jobs_db: image: cassandra:4.0.7 - networks: - - jobs # only accessible by the jobs service volumes: - ./services/jobs/cassandra-config/cassandra.yaml:/etc/cassandra/cassandra.yaml healthcheck: @@ -65,22 +45,60 @@ services: interval: 20s timeout: 10s retries: 60 - ports: - - "9042:9042" + networks: + - jobs + + # ----- PAYMENTS MICROSERVICE ------- + service_payments: + image: ahmad45123/workup:service_payments + depends_on: + - payments_db + - service_mq + - service_redis + networks: + - default + - payments + env_file: + - ./services/payments/.env payments_db: - image: postgres:latest + image: postgres:12.18 environment: POSTGRES_PASSWORD: payments_password POSTGRES_USER: payments_user POSTGRES_DB: payments_database - ports: - - "5432:5432" + healthcheck: + test: ["CMD", "pg_isready"] + interval: 20s + timeout: 10s + retries: 10 + networks: + - payments + + # ----- CONTRACTS MICROSERVICE ------- + service_contracts: + image: ahmad45123/workup:service_contracts + depends_on: + - contracts_db + - service_mq + networks: + - default + - contracts + env_file: + - ./services/contracts/.env + + contracts_db: + image: cassandra:4.0.7 + healthcheck: + test: [ "CMD", "cqlsh", "-e", "describe keyspaces" ] + interval: 20s + timeout: 10s + retries: 60 + networks: + - contracts networks: - microservices: - driver: bridge + default: jobs: - driver: bridge payments: - driver: bridge \ No newline at end of file + contracts: diff --git a/portainer-agent-stack.yml b/portainer-agent-stack.yml new file mode 100644 index 00000000..f0302ec7 --- /dev/null +++ b/portainer-agent-stack.yml @@ -0,0 +1,39 @@ +version: '3.2' + +services: + agent: + image: portainer/agent:2.19.5 + volumes: + - /var/run/docker.sock:/var/run/docker.sock:z + - /var/lib/docker/volumes:/var/lib/docker/volumes + networks: + - agent_network + deploy: + mode: global + placement: + constraints: [node.platform.os == linux] + + portainer: + image: portainer/portainer-ce:2.19.5 + command: -H tcp://tasks.agent:9001 --tlsskipverify + ports: + - "9443:9443" + - "9000:9000" + - "8000:8000" + volumes: + - portainer_data:/data + networks: + - agent_network + deploy: + mode: replicated + replicas: 1 + placement: + constraints: [node.role == manager] + +networks: + agent_network: + driver: overlay + attachable: true + +volumes: + portainer_data: diff --git a/services/contracts/.env b/services/contracts/.env new file mode 100644 index 00000000..88e9e56f --- /dev/null +++ b/services/contracts/.env @@ -0,0 +1,2 @@ +CONTRACTS_MQ_URL=service_mq +CONTRACTS_DB_URL=contracts_db:9042 diff --git a/services/contracts/src/main/resources/application.properties b/services/contracts/src/main/resources/application.properties index 465575d2..2b246689 100644 --- a/services/contracts/src/main/resources/application.properties +++ b/services/contracts/src/main/resources/application.properties @@ -1,12 +1,12 @@ spring.application.name=contract -spring.rabbitmq.host=localhost +spring.rabbitmq.host=${CONTRACTS_MQ_URL} spring.rabbitmq.port=5672 spring.rabbitmq.username=guest spring.rabbitmq.password=guest spring.cassandra.local-datacenter=datacenter1 spring.cassandra.keyspace-name=contracts_data -spring.cassandra.contact-points=localhost:9042 +spring.cassandra.contact-points=${CONTRACTS_DB_URL} spring.cassandra.schema-action=CREATE_IF_NOT_EXISTS diff --git a/services/jobs/.env b/services/jobs/.env new file mode 100644 index 00000000..59921715 --- /dev/null +++ b/services/jobs/.env @@ -0,0 +1,2 @@ +JOBS_DB_URL=jobs_db:9042 +JOBS_MQ_URL=service_mq diff --git a/services/jobs/cassandra-config/cassandra.yaml b/services/jobs/cassandra-config/cassandra.yaml index 426f6d9a..d4f3aba1 100644 --- a/services/jobs/cassandra-config/cassandra.yaml +++ b/services/jobs/cassandra-config/cassandra.yaml @@ -463,7 +463,7 @@ seed_provider: parameters: # seeds is actually a comma-delimited list of addresses. # Ex: ",," - - seeds: "172.18.0.2" + - seeds: "10.0.11.6" # For workloads with more data than can fit in memory, Cassandra's # bottleneck will be reads that need to fetch data from @@ -663,7 +663,7 @@ ssl_storage_port: 7001 # # Setting listen_address to 0.0.0.0 is always wrong. # -listen_address: 172.18.0.2 +listen_address: 10.0.11.6 # Set listen_address OR listen_interface, not both. Interfaces must correspond # to a single address, IP aliasing is not supported. @@ -677,7 +677,7 @@ listen_address: 172.18.0.2 # Address to broadcast to other Cassandra nodes # Leaving this blank will set it to the same value as listen_address -broadcast_address: 172.18.0.2 +broadcast_address: 10.0.11.6 # When using multiple physical network interfaces, set this # to true to listen on broadcast_address in addition to @@ -763,7 +763,7 @@ rpc_address: 0.0.0.0 # be set to 0.0.0.0. If left blank, this will be set to the value of # rpc_address. If rpc_address is set to 0.0.0.0, broadcast_rpc_address must # be set. -broadcast_rpc_address: 172.18.0.2 +broadcast_rpc_address: 10.0.11.6 # enable or disable keepalive on rpc/native connections rpc_keepalive: true diff --git a/services/jobs/src/main/java/com/workup/jobs/JobsApplication.java b/services/jobs/src/main/java/com/workup/jobs/JobsApplication.java index 2c413c1f..df7dd3bb 100644 --- a/services/jobs/src/main/java/com/workup/jobs/JobsApplication.java +++ b/services/jobs/src/main/java/com/workup/jobs/JobsApplication.java @@ -4,6 +4,7 @@ import org.springframework.amqp.core.Queue; import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; import org.springframework.amqp.support.converter.MessageConverter; +import org.springframework.boot.ApplicationRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; @@ -24,4 +25,11 @@ public Queue myQueue() { public MessageConverter messageConverter() { return new Jackson2JsonMessageConverter(); } + + @Bean + public ApplicationRunner runner() { + return args -> { + System.out.println("WE ARE NEW IN JOBS"); + }; + } } diff --git a/services/jobs/src/main/resources/application.properties b/services/jobs/src/main/resources/application.properties index e22173ae..6ef2e3d9 100644 --- a/services/jobs/src/main/resources/application.properties +++ b/services/jobs/src/main/resources/application.properties @@ -1,4 +1,4 @@ -spring.rabbitmq.host=service_mq +spring.rabbitmq.host=${JOBS_MQ_URL} spring.rabbitmq.port=5672 spring.rabbitmq.username=guest spring.rabbitmq.password=guest @@ -6,5 +6,5 @@ spring.rabbitmq.password=guest spring.cassandra.local-datacenter=datacenter1 spring.cassandra.keyspace-name=jobs_data -spring.cassandra.contact-points=jobs_db:9042 +spring.cassandra.contact-points=${JOBS_DB_URL} spring.cassandra.schema-action=CREATE_IF_NOT_EXISTS \ No newline at end of file diff --git a/services/payments/.env b/services/payments/.env new file mode 100644 index 00000000..0e4f643c --- /dev/null +++ b/services/payments/.env @@ -0,0 +1,2 @@ +PAYMENTS_DB_URL=jdbc:postgresql://payments_db:5432/payments_database +PAYMENTS_MQ_URL=service_mq diff --git a/services/payments/src/main/resources/application.properties b/services/payments/src/main/resources/application.properties index 25f9ac46..b125cb1f 100644 --- a/services/payments/src/main/resources/application.properties +++ b/services/payments/src/main/resources/application.properties @@ -1,5 +1,5 @@ spring.application.name=payments -spring.datasource.url=jdbc:postgresql://localhost:5432/payments_database +spring.datasource.url=${PAYMENTS_DB_URL} spring.datasource.username=payments_user spring.datasource.password=payments_password spring.jpa.hibernate.ddl-auto=create-drop @@ -8,7 +8,7 @@ spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect spring.jpa.properties.hibernate.format_sql=true server.error.include-message=always -spring.rabbitmq.host=service_mq +spring.rabbitmq.host=${PAYMENTS_MQ_URL} spring.rabbitmq.port=5672 spring.rabbitmq.username=guest spring.rabbitmq.password=guest diff --git a/shared/src/main/resources/application.properties b/shared/src/main/resources/application.properties index 58e67797..245d2e51 100644 --- a/shared/src/main/resources/application.properties +++ b/shared/src/main/resources/application.properties @@ -1,4 +1,4 @@ spring.cache.type=redis -spring.cache.host=localhost +spring.cache.host=service_redis spring.cache.port=6379 spring.cache.redis.time-to-live=600000 \ No newline at end of file