ci(test): local testing
This commit is contained in:
parent
c25f72a185
commit
98b7451157
81
Dockerfile
81
Dockerfile
@ -1,37 +1,64 @@
|
||||
FROM node:19.1-alpine AS dev
|
||||
FROM node:20.5.1-alpine3.17 as build
|
||||
|
||||
# Update packages and clear cache
|
||||
RUN apk update && rm -rf /var/cache/apk/*
|
||||
|
||||
WORKDIR /usr/app
|
||||
|
||||
# Install node dependencies - done in a separate step so Docker can cache it.
|
||||
COPY yarn.lock .
|
||||
COPY package.json .
|
||||
COPY tsconfig.json .
|
||||
|
||||
RUN yarn install --ignore-scripts --non-interactive --frozen-lockfile && yarn cache clean
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN ls
|
||||
|
||||
# Set the working directory inside the container
|
||||
WORKDIR /app
|
||||
# Add package metadata files
|
||||
ADD yarn.lock package.json tsconfig.json ./
|
||||
# Add src folder
|
||||
ADD src ./src/
|
||||
# Add tools
|
||||
ADD tools ./tools/
|
||||
# Add migrations
|
||||
ADD migrations ./migrations
|
||||
# Install packages
|
||||
RUN yarn install --ignore-scripts --non-interactive && yarn cache clean
|
||||
# Build app
|
||||
RUN yarn build
|
||||
|
||||
FROM node:19.1-alpine AS production
|
||||
|
||||
|
||||
FROM node:20.5.1-alpine3.17 as test
|
||||
|
||||
# Update packages and clear cache
|
||||
RUN apk update && rm -rf /var/cache/apk/*
|
||||
|
||||
# Set production env
|
||||
ENV NODE_ENV=production
|
||||
# Set the working directory inside the container
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=dev /usr/app/dist /app
|
||||
COPY --from=dev /usr/app/package.json /app/
|
||||
COPY --from=dev /usr/app/yarn.lock /app/
|
||||
COPY --from=dev /usr/app/tsconfig.json .
|
||||
|
||||
# Copy built files from build stage
|
||||
COPY --from=build /app/dist /app/package.json /app/yarn.lock ./
|
||||
# Copy migrate tool from build stage
|
||||
COPY --from=build /app/tools/migrate /usr/local/bin/migrate
|
||||
# Copy test migrations from build stage
|
||||
COPY --from=build /app/migrations/test ./migrations
|
||||
# Change ownership of files in the /app directory to the 'node' user
|
||||
RUN chown -R node: .
|
||||
|
||||
USER node
|
||||
|
||||
# Install packages
|
||||
RUN yarn install --non-interactive --frozen-lockfile --production && yarn cache clean
|
||||
# Set 'node' user as the active user within the container
|
||||
USER node
|
||||
# Run the Node.js application
|
||||
CMD ["node", "./index.js"]
|
||||
|
||||
CMD ["yarn", "start:prod"]
|
||||
|
||||
|
||||
FROM node:20.5.1-alpine3.17 as production
|
||||
|
||||
# Update packages and clear cache
|
||||
RUN apk update && rm -rf /var/cache/apk/*
|
||||
# Set production env
|
||||
ENV NODE_ENV=production
|
||||
# Set the working directory inside the container
|
||||
WORKDIR /app
|
||||
# Copy built files from build stage
|
||||
COPY --from=build /app/dist /app/package.json /app/yarn.lock ./
|
||||
# Change ownership of files in the /app directory to the 'node' user
|
||||
RUN chown -R node: .
|
||||
# Install packages
|
||||
RUN yarn install --non-interactive --frozen-lockfile --production && yarn cache clean
|
||||
# Set 'node' user as the active user within the container
|
||||
USER node
|
||||
# Run the Node.js application
|
||||
CMD ["node", "./index.js"]
|
8
deployments/test/.env.test
Normal file
8
deployments/test/.env.test
Normal file
@ -0,0 +1,8 @@
|
||||
PUBLIC_ACCESS_SECRET_KEY="-----BEGIN PUBLIC KEY-----
|
||||
MIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgHgnvr7O2tiApjJfid1orFnIGm69
|
||||
80fZp+Lpbjo+NC/0whMFga2Biw5b1G2Q/B2u0tpO1Fs/E8z7Lv1nYfr5jx2S8x6B
|
||||
dA4TS2kB9Kf0wn0+7wSlyikHoKhbtzwXHZl17GsyEi6wHnsqNBSauyIWhpha8i+Y
|
||||
+3GyaOY536H47qyXAgMBAAE=
|
||||
-----END PUBLIC KEY-----"
|
||||
|
||||
SALT=10
|
61
deployments/test/docker-compose.yaml
Normal file
61
deployments/test/docker-compose.yaml
Normal file
@ -0,0 +1,61 @@
|
||||
version: "3.3"
|
||||
|
||||
services:
|
||||
hub-admin-backend-service:
|
||||
container_name: hub-admin-backend-service
|
||||
tty: true
|
||||
build:
|
||||
context: ../../.
|
||||
dockerfile: Dockerfile
|
||||
target: test
|
||||
env_file:
|
||||
- .env.test
|
||||
environment:
|
||||
- HTTP_HOST=0.0.0.0
|
||||
- HTTP_PORT=8000
|
||||
- DB_HOST=hub-admin-backend-db
|
||||
- DB_PORT=27017
|
||||
- DB_USERNAME=test
|
||||
- DB_PASSWORD=test
|
||||
- DB_NAME=admin
|
||||
- ENVIRONMENT=staging
|
||||
- AUTH_SERVICE_HOST=http://pena-auth-service
|
||||
- AUTH_SERVICE_PORT=8000
|
||||
depends_on:
|
||||
- hub-admin-backend-migration
|
||||
- hub-admin-backend-db
|
||||
ports:
|
||||
- 8001:8000
|
||||
networks:
|
||||
- test
|
||||
|
||||
hub-admin-backend-migration:
|
||||
container_name: hub-admin-backend-migration
|
||||
build:
|
||||
context: ../../.
|
||||
dockerfile: Dockerfile
|
||||
target: test
|
||||
command:
|
||||
[
|
||||
"sh",
|
||||
"-c",
|
||||
'migrate -source file://migrations -database "mongodb://test:test@hub-admin-backend-db:27017/admin?authSource=admin" up',
|
||||
]
|
||||
depends_on:
|
||||
- hub-admin-backend-db
|
||||
networks:
|
||||
- test
|
||||
|
||||
hub-admin-backend-db:
|
||||
container_name: hub-admin-backend-db
|
||||
image: "mongo:6.0.3"
|
||||
environment:
|
||||
MONGO_INITDB_ROOT_USERNAME: test
|
||||
MONGO_INITDB_ROOT_PASSWORD: test
|
||||
ports:
|
||||
- "27021:27017"
|
||||
networks:
|
||||
- test
|
||||
|
||||
networks:
|
||||
test:
|
1
migrations/test/001_tariffs_insert.down.json
Normal file
1
migrations/test/001_tariffs_insert.down.json
Normal file
@ -0,0 +1 @@
|
||||
[{ "delete": "tariffs", "deletes": [{ "q": {} }] }]
|
43
migrations/test/001_tariffs_insert.up.json
Normal file
43
migrations/test/001_tariffs_insert.up.json
Normal file
@ -0,0 +1,43 @@
|
||||
[
|
||||
{
|
||||
"insert": "tariffs",
|
||||
"ordered": true,
|
||||
"documents": [
|
||||
{
|
||||
"_id": {
|
||||
"$oid": "64e6105384368b75221a5c3e"
|
||||
},
|
||||
"name": "100 генераций",
|
||||
"price": 5000,
|
||||
"userId": "64e6106eab16496587435cbf",
|
||||
"isCustom": false,
|
||||
"privileges": [
|
||||
{
|
||||
"name": "100 генераций",
|
||||
"privilegeId": "64e60d28eac51324f2296753",
|
||||
"serviceKey": "templategen-key",
|
||||
"description": "",
|
||||
"amount": 1,
|
||||
"type": "count",
|
||||
"value": "100",
|
||||
"price": 5000
|
||||
},
|
||||
{
|
||||
"name": "100 генераций",
|
||||
"privilegeId": "64e60e9094732821e3142eb8",
|
||||
"serviceKey": "shortlink-key",
|
||||
"description": "",
|
||||
"amount": 1,
|
||||
"type": "count",
|
||||
"value": "100",
|
||||
"price": 1000
|
||||
}
|
||||
],
|
||||
"isDeleted": false,
|
||||
"createdAt": "2023-06-16T08:15:30.336Z",
|
||||
"updatedAt": "2023-06-16T08:15:30.336Z",
|
||||
"deletedAt": "2023-06-16T08:15:30.336Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
1
migrations/test/002_privileges_insert.down.json
Normal file
1
migrations/test/002_privileges_insert.down.json
Normal file
@ -0,0 +1 @@
|
||||
[{ "delete": "privileges", "deletes": [{ "q": {} }] }]
|
42
migrations/test/002_privileges_insert.up.json
Normal file
42
migrations/test/002_privileges_insert.up.json
Normal file
@ -0,0 +1,42 @@
|
||||
[
|
||||
{
|
||||
"insert": "privileges",
|
||||
"ordered": true,
|
||||
"documents": [
|
||||
{
|
||||
"_id": {
|
||||
"$oid": "64e60d28eac51324f2296753"
|
||||
},
|
||||
"name": "100 генераций",
|
||||
"privilegeId": "64e60d28eac51324f2296753",
|
||||
"serviceKey": "templategen-key",
|
||||
"description": "",
|
||||
"amount": 1,
|
||||
"type": "count",
|
||||
"value": "100",
|
||||
"price": 5000,
|
||||
"isDeleted": false,
|
||||
"createdAt": "2023-06-16T08:15:30.336Z",
|
||||
"updatedAt": "2023-06-16T08:15:30.336Z",
|
||||
"deletedAt": "2023-06-16T08:15:30.336Z"
|
||||
},
|
||||
{
|
||||
"_id": {
|
||||
"$oid": "64e60e9094732821e3142eb8"
|
||||
},
|
||||
"name": "100 генераций",
|
||||
"privilegeId": "64e60e9094732821e3142eb8",
|
||||
"serviceKey": "shortlink-key",
|
||||
"description": "",
|
||||
"amount": 1,
|
||||
"type": "count",
|
||||
"value": "100",
|
||||
"price": 1000,
|
||||
"isDeleted": false,
|
||||
"createdAt": "2023-06-16T08:15:30.336Z",
|
||||
"updatedAt": "2023-06-16T08:15:30.336Z",
|
||||
"deletedAt": "2023-06-16T08:15:30.336Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
72
package.json
72
package.json
@ -15,6 +15,8 @@
|
||||
"build": "tsc -p tsconfig.json && tsc-alias -p tsconfig.json",
|
||||
"compose:dev:start": "docker-compose -f deployments/dev/docker-compose.yaml up -d",
|
||||
"compose:dev:stop": "docker-compose -f deployments/dev/docker-compose.yaml down --volumes --rmi local",
|
||||
"compose:test:start": "docker-compose -f deployments/test/docker-compose.yaml up -d",
|
||||
"compose:test:stop": "docker-compose -f deployments/test/docker-compose.yaml down --volumes --rmi local",
|
||||
"code:check": "prettier --check \"src/**/*.{ts,tsx,js,css,scss,html}\"",
|
||||
"code:format": "prettier --write \"src/**/*.{ts,tsx,js,css,scss,html}\"",
|
||||
"code:format:specific-file": "prettier --write",
|
||||
@ -22,46 +24,46 @@
|
||||
"lint:fix": "eslint --fix ."
|
||||
},
|
||||
"dependencies": {
|
||||
"@fastify/cookie": "^8.3.0",
|
||||
"@fastify/jwt": "^6.3.3",
|
||||
"@fastify/swagger": "^8.2.1",
|
||||
"@fastify/swagger-ui": "^1.3.0",
|
||||
"axios": "^1.2.1",
|
||||
"@fastify/cookie": "^9.0.4",
|
||||
"@fastify/jwt": "^7.2.0",
|
||||
"@fastify/swagger": "^8.9.0",
|
||||
"@fastify/swagger-ui": "^1.9.3",
|
||||
"axios": "^1.4.0",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"dotenv": "^16.0.3",
|
||||
"fastify": "^4.9.2",
|
||||
"fastify-plugin": "^4.3.0",
|
||||
"fastify-print-routes": "^2.0.6",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"mongoose": "^6.7.2",
|
||||
"nodemon": "^2.0.20",
|
||||
"dotenv": "^16.3.1",
|
||||
"fastify": "^4.21.0",
|
||||
"fastify-plugin": "^4.5.1",
|
||||
"fastify-print-routes": "^2.1.0",
|
||||
"jsonwebtoken": "^9.0.1",
|
||||
"mongoose": "^7.4.4",
|
||||
"nodemon": "^3.0.1",
|
||||
"ts-node": "^10.9.1",
|
||||
"tsconfig-paths": "^4.1.0",
|
||||
"typescript-transform-paths": "^3.4.4"
|
||||
"tsconfig-paths": "^4.2.0",
|
||||
"typescript-transform-paths": "^3.4.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^17.1.2",
|
||||
"@commitlint/config-conventional": "^17.1.0",
|
||||
"@commitlint/cli": "^17.7.1",
|
||||
"@commitlint/config-conventional": "^17.7.0",
|
||||
"@types/bcryptjs": "^2.4.2",
|
||||
"@types/jest": "^29.2.3",
|
||||
"@types/jsonwebtoken": "^8.5.9",
|
||||
"@types/node": "^18.11.9",
|
||||
"@typescript-eslint/eslint-plugin": "^5.18.0",
|
||||
"@typescript-eslint/parser": "^5.18.0",
|
||||
"eslint": "^8.23.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-import-resolver-node": "^0.3.6",
|
||||
"eslint-import-resolver-typescript": "^3.5.0",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"husky": "^7.0.4",
|
||||
"jest": "^29.3.1",
|
||||
"jest-mock-extended": "^3.0.4",
|
||||
"nodemon": "^2.0.20",
|
||||
"prettier": "^2.7.1",
|
||||
"ts-jest": "^29.0.3",
|
||||
"tsc-alias": "^1.8.3",
|
||||
"typescript": "^4.9.3"
|
||||
"@types/jest": "^29.5.4",
|
||||
"@types/jsonwebtoken": "^9.0.2",
|
||||
"@types/node": "^20.5.3",
|
||||
"@typescript-eslint/eslint-plugin": "^6.4.1",
|
||||
"@typescript-eslint/parser": "^6.4.1",
|
||||
"eslint": "^8.47.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-import-resolver-node": "^0.3.9",
|
||||
"eslint-import-resolver-typescript": "^3.6.0",
|
||||
"eslint-plugin-import": "^2.28.1",
|
||||
"eslint-plugin-prettier": "^5.0.0",
|
||||
"husky": "^8.0.3",
|
||||
"jest": "^29.6.3",
|
||||
"jest-mock-extended": "^3.0.5",
|
||||
"nodemon": "^3.0.1",
|
||||
"prettier": "^3.0.2",
|
||||
"ts-jest": "^29.1.1",
|
||||
"tsc-alias": "^1.8.7",
|
||||
"typescript": "^5.1.6"
|
||||
},
|
||||
"lint-staged": {
|
||||
"./src/**/*.{ts,js,jsx,tsx}": [
|
||||
|
BIN
tools/migrate
Normal file
BIN
tools/migrate
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user