Skip to content

Commit 8ba6540

Browse files
committed
update microservice pattern
1 parent dee0419 commit 8ba6540

File tree

11 files changed

+81
-66
lines changed

11 files changed

+81
-66
lines changed

auth

Submodule auth updated 46 files

build.sh

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
#!/bin/bash
22

3+
# Function to build a Docker image for a given folder
34
build_docker_image() {
45
local folder="$1"
56
local service_name=$(basename "$folder")
67
if [[ -e "$folder/Dockerfile" ]]; then
78
echo ">>> Building service ${service_name}..."
8-
docker build -t "${service_name}:latest" -f "$folder/Dockerfile" "$folder" && echo ">>> Build completed for ${service_name}"
9-
echo ">>> Built ${service_name}..."
9+
if docker build -t "${service_name}:latest" -f "$folder/Dockerfile" "$folder"; then
10+
echo ">>> Build completed for ${service_name}"
11+
else
12+
echo ">>> Build failed for ${service_name}" >&2
13+
fi
1014
fi
1115
}
1216

13-
find . -maxdepth 1 -type d | while read -r dir; do
14-
if [[ "$dir" != "." ]]; then
15-
build_docker_image "$dir"
16-
fi
17-
done
17+
# Export the function to be used by parallel
18+
export -f build_docker_image
19+
20+
# Find all directories with a Dockerfile and build images in parallel
21+
find . -maxdepth 1 -type d -not -path '.' -print0 | xargs -0 -n 1 -P $(nproc) bash -c 'build_docker_image "$0"'
1822

1923
echo ">>> All builds completed"

deploy.sh

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
11
#!/bin/bash
22

3+
# Function to log into AWS ECR
4+
aws_ecr_login() {
5+
echo ">>> Logging into AWS ECR"
6+
aws ecr get-login-password --region "$AWS_REGION" | docker login --username AWS --password-stdin "$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com"
7+
}
8+
9+
# Function to build and push Docker image
10+
build_and_push_image() {
11+
local service_name="$1"
12+
local image_name="nestjs_$service_name:latest"
13+
local ecr_image_uri="$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$service_name:latest"
14+
15+
echo ">>> Building $image_name"
16+
docker build -t "$image_name" -f "$service_name/Dockerfile" "$service_name"
17+
18+
if [ $? -eq 0 ]; then
19+
echo ">>> Tagging $image_name"
20+
docker tag "$image_name" "$ecr_image_uri"
21+
22+
echo ">>> Pushing $image_name"
23+
docker push "$ecr_image_uri"
24+
25+
if [ $? -eq 0 ]; then
26+
echo ">>> Deployment completed for $service_name"
27+
else
28+
echo ">>> Failed to push image $image_name" >&2
29+
fi
30+
else
31+
echo ">>> Failed to build image $image_name" >&2
32+
fi
33+
}
34+
35+
# Main script execution
336
printf "Please select service:\n"
437
select d in */; do
538
test -n "$d" && break
@@ -9,35 +42,14 @@ done
942
service_name="${d%/}"
1043

1144
if [ "$service_name" == 'fluent-bit' ]; then
45+
echo ">>> Service fluent-bit is not allowed for deployment"
1246
exit 1
1347
fi
1448

15-
service_dir="./$service_name"
16-
17-
if [ ! -e "$service_dir/Dockerfile" ]; then
49+
if [ ! -e "$service_name/Dockerfile" ]; then
1850
echo ">>> Dockerfile not found for service $service_name"
1951
exit 1
2052
fi
2153

2254
echo ">>> Deploying service $service_name..."
23-
cd "$service_dir" || exit
24-
25-
aws_ecr_login() {
26-
echo ">>> Logging into AWS ECR"
27-
aws ecr get-login-password --region "$AWS_REGION" | docker login --username AWS --password-stdin "$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/nestjs-microservices-$service_name"
28-
}
29-
30-
build_and_push_image() {
31-
local image_name="nestjs_$service_name:latest"
32-
echo ">>> Building $image_name"
33-
docker build -t "$image_name" -f Dockerfile .
34-
echo ">>> Tagging $image_name"
35-
docker tag "$image_name" "$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$service_name:latest"
36-
echo ">>> Pushing $image_name"
37-
docker push "$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$service_name:latest"
38-
}
39-
40-
aws_ecr_login && build_and_push_image
41-
42-
echo ">>> Deployment completed for $service_name"
43-
cd ..
55+
aws_ecr_login && build_and_push_image "$service_name"

docker-compose.dep.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: "3.8"
2-
31
services:
42
postgres:
53
image: postgres:latest

docker-compose.grafana.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: "3.8"
2-
31
services:
42
fluent-bit:
53
environment:
@@ -26,6 +24,8 @@ services:
2624
ports:
2725
- "3000:3000"
2826
environment:
27+
GF_SECURITY_ADMIN_USER: admin
28+
GF_SECURITY_ADMIN_PASSWORD: master123
2929
GF_RENDERING_SERVER_URL: http://renderer:8081/render
3030
GF_RENDERING_CALLBACK_URL: http://grafana:3000/
3131
GF_LOG_FILTERS: rendering:debug

docker-compose.yml

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: "3.8"
2-
31
services:
42
auth-service:
53
build:
@@ -15,12 +13,12 @@ services:
1513
volumes:
1614
- ./auth:/app/auth
1715
- /app/auth/node_modules
18-
# logging:
19-
# driver: fluentd
20-
# options:
21-
# fluentd-async: "true"
22-
# fluentd-address: localhost:24224
23-
# tag: auth-service
16+
logging:
17+
driver: fluentd
18+
options:
19+
fluentd-async: "true"
20+
fluentd-address: localhost:24224
21+
tag: auth-service
2422

2523
post-service:
2624
build:
@@ -36,12 +34,12 @@ services:
3634
volumes:
3735
- ./post:/app/post
3836
- /app/post/node_modules
39-
# logging:
40-
# driver: fluentd
41-
# options:
42-
# fluentd-async: "true"
43-
# fluentd-address: localhost:24224
44-
# tag: post-service
37+
logging:
38+
driver: fluentd
39+
options:
40+
fluentd-async: "true"
41+
fluentd-address: localhost:24224
42+
tag: post-service
4543

4644
files-service:
4745
build:
@@ -57,12 +55,12 @@ services:
5755
volumes:
5856
- ./files:/app/files
5957
- /app/files/node_modules
60-
# logging:
61-
# driver: fluentd
62-
# options:
63-
# fluentd-async: "true"
64-
# fluentd-address: localhost:24224
65-
# tag: files-service
58+
logging:
59+
driver: fluentd
60+
options:
61+
fluentd-async: "true"
62+
fluentd-address: localhost:24224
63+
tag: files-service
6664

6765
notification-service:
6866
build:
@@ -78,12 +76,12 @@ services:
7876
volumes:
7977
- ./notification:/app/notification
8078
- /app/notification/node_modules
81-
# logging:
82-
# driver: fluentd
83-
# options:
84-
# fluentd-async: "true"
85-
# fluentd-address: localhost:24224
86-
# tag: notification-service
79+
logging:
80+
driver: fluentd
81+
options:
82+
fluentd-async: "true"
83+
fluentd-address: localhost:24224
84+
tag: notification-service
8785

8886
kong:
8987
build:

files

Submodule files updated from 5a1ed86 to cfd4884

kong/conf/kong.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ services:
3131
strip_path: true
3232
- name: notification_service
3333
host: notification
34-
port: 9003
34+
port: 9004
3535
protocol: http
3636
routes:
3737
- name: notification_route
3838
paths:
3939
- /notification
4040
strip_path: true
41+
4142
plugins:
4243
- name: rate-limiting
4344
config:

notification

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
"deploy": "sh deploy.sh",
77
"build": "sh build.sh",
88
"dep:up": "docker compose -f docker-compose.dep.yml up",
9+
"dep:build": "docker compose -f docker-compose.dep.yml build",
910
"dep:down": "docker compose -f docker-compose.dep.yml down",
1011
"grafana:up": "docker compose -f docker-compose.grafana.yml up",
12+
"grafana:build": "docker compose -f docker-compose.grafana.yml build",
1113
"grafana:down": "docker compose -f docker-compose.grafana.yml down"
1214
},
1315
"keywords": [

0 commit comments

Comments
 (0)