Skip to content

File tree

105 files changed

+1492
-514
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+1492
-514
lines changed

apps/logistic-server/.env

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
BCRYPT_SALT=10
22
COMPOSE_PROJECT_NAME=amp_clbozbamx00noj301wjlnxivl
3-
JWT_SECRET_KEY=Change_ME!!!
4-
JWT_EXPIRATION=2d
5-
PORT=3000
6-
DB_USER=root
3+
DB_NAME=my-db
74
DB_PASSWORD=admin
85
DB_PORT=3306
9-
DB_URL=mysql://root:admin@localhost:3306/my-service
6+
DB_URL=mysql://root:admin@localhost:3306/my-db
7+
DB_USER=root
8+
JWT_EXPIRATION=2d
9+
JWT_SECRET_KEY=Change_ME!!!
1010
KAFKA_BROKERS=localhost:9092
11+
KAFKA_CLIENT_ID=logistic
1112
KAFKA_ENABLE_SSL=false
12-
KAFKA_CLIENT_ID=my-service
13-
KAFKA_GROUP_ID=my-service
13+
KAFKA_GROUP_ID=logistic
14+
NATS_SERVERS=localhost:4222
15+
PORT=3000

apps/logistic-server/.gitignore

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2-
3-
2+
43
/node_modules
54
/dist
6-
.DS_Store
5+
.DS_Store

apps/logistic-server/Dockerfile

+42-5
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,48 @@
1-
FROM node:19.1 AS base
1+
# multi-stage: base (build)
2+
FROM node:18.13.0 AS base
23

4+
# create directory where the application will be built
35
WORKDIR /app
46

5-
COPY package.json ./
7+
# copy over the dependency manifests, both the package.json
8+
# and the package-lock.json are copied over
9+
COPY package*.json ./
610

11+
# installs packages and their dependencies
712
RUN npm install
813

14+
# copy over the prisma schema
915
COPY prisma/schema.prisma ./prisma/
1016

17+
# generate the prisma client based on the schema
1118
RUN npm run prisma:generate
1219

20+
# copy over the code base
1321
COPY . .
1422

23+
# create the bundle of the application
1524
RUN npm run build
1625

17-
FROM node:19.1 AS prod
26+
# multi-stage: production (runtime)
27+
FROM node:18.13.0-slim AS production
1828

29+
# create arguments of builds time variables
30+
ARG user=amplication
31+
ARG group=${user}
32+
ARG uid=1001
33+
ARG gid=$uid
34+
35+
# [temporary] work around to be able to run prisma
36+
RUN apt-get update -y && apt-get install -y openssl
37+
38+
# create directory where the application will be executed from
1939
WORKDIR /app
2040

41+
# add the user and group
42+
RUN groupadd --gid ${gid} ${user}
43+
RUN useradd --uid ${uid} --gid ${gid} -m ${user}
44+
45+
# copy over the bundled code from the build stage
2146
COPY --from=base /app/node_modules/ ./node_modules
2247
COPY --from=base /app/package.json ./package.json
2348
COPY --from=base /app/dist ./dist
@@ -26,6 +51,18 @@ COPY --from=base /app/scripts ./scripts
2651
COPY --from=base /app/src ./src
2752
COPY --from=base /app/tsconfig* ./
2853

29-
EXPOSE 3000
54+
# change ownership of the workspace directory
55+
RUN chown -R ${uid}:${gid} /app/
56+
57+
# get rid of the development dependencies
58+
RUN npm install --production
59+
60+
# set user to the created non-privileged user
61+
USER ${user}
62+
63+
# expose a specific port on the docker container
64+
ENV PORT=3000
65+
EXPOSE ${PORT}
3066

31-
CMD [ "node", "./dist/main"]
67+
# start the server using the previously build application
68+
CMD [ "node", "./dist/main.js" ]

apps/logistic-server/README.md

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<p align="right">
2+
<a href="https://amplication.com" target="_blank">
3+
<img alt="amplication-logo" height="70" alt="Amplication Logo" src="https://amplication.com/images/logo.svg"/>
4+
</a>
5+
</p>
6+
7+
# Introduction
8+
9+
This service was generated with Amplication. The server-side of the generated project. This component provides the different backend services - i.e., REST API, GraphQL API, authentication, authorization, logging, data validation and the connection to the database. Additional information about the server component and the architecture around it, can be found on the [documentation](https://docs.amplication.com/guides/getting-started) site.
10+
11+
# Getting started
12+
13+
## Step 1: Configuration
14+
15+
Configuration for the server component can be provided through the use of environment variables. These can be passed to the application via the use of the `.env` file in the base directory of the generated service. Below a table can be found which show the different variables that can be passed - these are the variables which exist by default, through the use of plugins additional integrations could require additional values. These values are provided default values after generation, change them to the desired values.
16+
17+
| Variable | Description | Value |
18+
| -------------------- | -------------------------------------------- | ------------------------------------------------------------------- |
19+
| BCRYPT_SALT | the string used for hashing | [random-string] |
20+
| COMPOSE_PROJECT_NAME | the identifier of the service plus prefix | amp_[service-identifier] |
21+
| PORT | the port on which to run the server | 3000 |
22+
| DB_URL | the connection url for the database | [db-provider]://[username]:[password]@localhost:[db-port]/[db-name] |
23+
| DB_PORT | the port used by the database instance | [db-provider-port] |
24+
| DB_USER | the username used to connect to the database | [username] |
25+
| DB_PASSWORD | the password used to connect to the database | [password] |
26+
| DB_NAME | the name of the database | [service-name] / [project-name] |
27+
| JWT_SECRET_KEY | the secret used to sign the json-web token | [secret] |
28+
| JWT_EXPIRATION | the expiration time for the json-web token | 2d |
29+
30+
> **Note**
31+
> Amplication generates default values and stores them under the .env file. It is advised to use some form of secrets manager/vault solution when using in production.
32+
33+
## Step 2.1: Scripts - pre-requisites
34+
35+
After configuration of the server the next step would be to run the application. Before running the server side of the component, make sure that the different pre-requisites are met - i.e., node.js [^16.x], npm, docker. After the setup of the pre-requisites the server component can be started.
36+
37+
```sh
38+
# installation of the dependencies
39+
$ npm install
40+
41+
# generate the prisma client
42+
$ npm run prisma:generate
43+
```
44+
45+
## Step 2.2: Scripts - local development
46+
47+
```sh
48+
# start the database where the server component will connect to
49+
$ npm run docker:dev
50+
51+
# initialize the database
52+
$ npm run db:init
53+
54+
# start the server component
55+
$ npm run start
56+
```
57+
By default, your app comes with one user with the username "admin" and password "admin".
58+
59+
## Step 2.2: Scripts - container based development
60+
61+
```shell
62+
# start the server component as a docker container
63+
$ npm run compose:up
64+
```

apps/logistic-server/docker-compose.db.yml

-17
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
version: "3"
2+
services:
3+
db:
4+
image: mysql:8.3
5+
command: --default-authentication-plugin=mysql_native_password
6+
restart: always
7+
ports:
8+
- ${DB_PORT}:3306
9+
environment:
10+
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
11+
healthcheck:
12+
test:
13+
- CMD
14+
- mysqladmin
15+
- ping
16+
- -h
17+
- localhost
18+
- -u
19+
- ${DB_USER}
20+
timeout: 45s
21+
interval: 10s
22+
retries: 10
23+
adminer:
24+
image: adminer
25+
restart: always
26+
ports:
27+
- 1234:8080
28+
zookeeper:
29+
image: confluentinc/cp-zookeeper:5.2.4
30+
environment:
31+
ZOOKEEPER_CLIENT_PORT: 2181
32+
ZOOKEEPER_TICK_TIME: 2000
33+
ports:
34+
- 2181:2181
35+
kafka:
36+
image: confluentinc/cp-kafka:7.3.1
37+
depends_on:
38+
- zookeeper
39+
ports:
40+
- 9092:9092
41+
- 9997:9997
42+
environment:
43+
KAFKA_BROKER_ID: 1
44+
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
45+
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092
46+
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
47+
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
48+
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
49+
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
50+
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
51+
kafka-ui:
52+
container_name: kafka-ui
53+
image: provectuslabs/kafka-ui:latest
54+
ports:
55+
- 8080:8080
56+
depends_on:
57+
- zookeeper
58+
- kafka
59+
environment:
60+
KAFKA_CLUSTERS_0_NAME: local
61+
KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:29092
62+
KAFKA_CLUSTERS_0_ZOOKEEPER: zookeeper:2181
63+
KAFKA_CLUSTERS_0_JMXPORT: 9997
64+
nats:
65+
image: nats:2.9.15
66+
networks:
67+
- internal
68+
ports:
69+
- 4222:4222
70+
- 8222:8222
71+
volumes:
72+
mysql: ~
73+
networks:
74+
internal:
75+
name: internal
76+
driver: bridge

apps/logistic-server/docker-compose.yml

+31-12
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ services:
99
- ${PORT}:3000
1010
environment:
1111
BCRYPT_SALT: ${BCRYPT_SALT}
12-
JWT_SECRET_KEY: ${JWT_SECRET_KEY}
13-
JWT_EXPIRATION: ${JWT_EXPIRATION}
14-
DB_URL: mysql://${DB_USER}:${DB_PASSWORD}@db:3306
12+
DB_URL: mysql://${DB_USER}:${DB_PASSWORD}@db:3306/${DB_NAME}
13+
KAFKA_BROKERS: kafka:9092
14+
KAFKA_ENABLE_SSL: ${KAFKA_ENABLE_SSL}
15+
KAFKA_CLIENT_ID: ${KAFKA_CLIENT_ID}
16+
KAFKA_GROUP_ID: ${KAFKA_GROUP_ID}
1517
depends_on:
1618
- migrate
19+
restart: on-failure
1720
migrate:
1821
build:
1922
context: .
@@ -23,7 +26,7 @@ services:
2326
working_dir: /app/server
2427
environment:
2528
BCRYPT_SALT: ${BCRYPT_SALT}
26-
DB_URL: mysql://${DB_USER}:${DB_PASSWORD}@db:3306
29+
DB_URL: mysql://${DB_USER}:${DB_PASSWORD}@db:3306/${DB_NAME}
2730
depends_on:
2831
db:
2932
condition: service_healthy
@@ -33,13 +36,13 @@ services:
3336
ports:
3437
- 1234:8080
3538
db:
36-
image: mysql
39+
image: mysql:8.3
3740
command: --default-authentication-plugin=mysql_native_password
3841
restart: always
3942
ports:
4043
- ${DB_PORT}:3306
4144
environment:
42-
DB_ROOT_PASSWORD: ${DB_PASSWORD}
45+
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
4346
healthcheck:
4447
test:
4548
- CMD
@@ -54,17 +57,13 @@ services:
5457
retries: 10
5558
zookeeper:
5659
image: confluentinc/cp-zookeeper:5.2.4
57-
networks:
58-
- internal
5960
environment:
6061
ZOOKEEPER_CLIENT_PORT: 2181
6162
ZOOKEEPER_TICK_TIME: 2000
6263
ports:
6364
- 2181:2181
6465
kafka:
65-
image: confluentinc/cp-kafka:5.3.1
66-
networks:
67-
- internal
66+
image: confluentinc/cp-kafka:7.3.1
6867
depends_on:
6968
- zookeeper
7069
ports:
@@ -73,12 +72,32 @@ services:
7372
environment:
7473
KAFKA_BROKER_ID: 1
7574
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
76-
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092
75+
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://kafka:9092
7776
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
7877
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
7978
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
8079
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
8180
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
81+
kafka-ui:
82+
container_name: kafka-ui
83+
image: provectuslabs/kafka-ui:latest
84+
ports:
85+
- 8080:8080
86+
depends_on:
87+
- zookeeper
88+
- kafka
89+
environment:
90+
KAFKA_CLUSTERS_0_NAME: local
91+
KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:29092
92+
KAFKA_CLUSTERS_0_ZOOKEEPER: zookeeper:2181
93+
KAFKA_CLUSTERS_0_JMXPORT: 9997
94+
nats:
95+
image: nats:2.9.15
96+
networks:
97+
- internal
98+
ports:
99+
- 4222:4222
100+
- 8222:8222
82101
volumes:
83102
mysql: ~
84103
networks:

apps/logistic-server/nest-cli.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{
22
"sourceRoot": "src",
33
"compilerOptions": {
4-
"assets": ["swagger"]
4+
"assets": [
5+
{
6+
"include": "swagger/**/*"
7+
}
8+
]
59
}
610
}

0 commit comments

Comments
 (0)