Skip to content

Commit 04d9cc2

Browse files
committed
chore: test infra
1 parent dabedca commit 04d9cc2

10 files changed

Lines changed: 40 additions & 25 deletions

File tree

.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ DB_SCHEMA=base
1818
DATABASE_URL=postgres://${DB_USERNAME}:${DB_PASSWORD}@localhost:${DB_PORT}/${DB_DATABASE}
1919

2020
# --- REDIS ---
21-
# in the docker network will be
21+
# in the docker network will be, not show port redis, at prod env
2222
# REDIS_HOST=redis
2323
# at development mode
24-
REDIS_HOST=redis
24+
REDIS_HOST=127.0.0.1
2525
REDIS_PORT=7000
2626

2727
JWT_ACCESS_SECRET=same-same-same-same-same

.github/workflows/build.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Build and Push
22

33
on:
44
push:
5-
branches: [dev, main]
5+
branches: [dev, main, feat/**]
66

77
env:
88
REGISTRY: ghcr.io
@@ -13,20 +13,20 @@ jobs:
1313
runs-on: ubuntu-latest
1414
permissions:
1515
contents: read
16-
# packages: write
16+
packages: write
1717

1818
steps:
1919
- uses: actions/checkout@v4
2020

2121
- name: Set up Docker Buildx
2222
uses: docker/setup-buildx-action@v3
2323

24-
# - name: Log in to the Container registry
25-
# uses: docker/login-action@v3
26-
# with:
27-
# registry: ${{ env.REGISTRY }}
28-
# username: ${{ github.actor }}
29-
# password: ${{ secrets.GITHUB_TOKEN }}
24+
- name: Log in to the Container registry
25+
uses: docker/login-action@v3
26+
with:
27+
registry: ${{ env.REGISTRY }}
28+
username: ${{ github.actor }}
29+
password: ${{ secrets.GITHUB_TOKEN }}
3030

3131
- name: Extract metadata (tags, labels)
3232
id: meta
@@ -36,13 +36,14 @@ jobs:
3636
tags: |
3737
type=ref,event=branch
3838
type=sha,format=short
39+
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
3940
4041
- name: Build and push Docker image
4142
uses: docker/build-push-action@v5
4243
with:
4344
context: .
4445
file: ./Dockerfile.prod
45-
push: false # add true, if your setup variables
46+
push: true
4647
tags: ${{ steps.meta.outputs.tags }}
4748
labels: ${{ steps.meta.outputs.labels }}
4849
cache-from: type=gha

Dockerfile.prod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ENV PORT=3000
2828

2929
COPY --from=build /app/dist ./dist
3030
COPY --from=build /app/node_modules ./node_modules
31+
COPY --from=build /app/migrations ./migrations
3132
COPY --from=build /app/package.json ./
3233

3334
EXPOSE 3000

infra/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
Run it by pwd at root! Not include at this dir
44

55
```sh
6-
docker compose -f .\infra\compose.dev.yaml --env-file .env --profile infra up --build -d -V
6+
docker compose -f ./infra/dev/compose.dev.yaml --env-file .env --profile infra up --build -d -V
77
```

infra/dev/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Файл для фронт разрабов
2+
3+
Цель файла - дать инстанс бэка, чтоб фронты могли локально запускать с минимальными развертываниями
Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
11
version: "3.9"
22

3-
name: task-tracker
3+
name: task-tracker-api
44

55
services:
66
api:
77
hostname: api
88
container_name: api
9-
build:
10-
context: ../
11-
dockerfile: Dockerfile.dev
12-
restart: always
9+
image: ghcr.io/task-tracker-lab/task-tracker-backend:feat-user
1310
env_file:
14-
- ../.env
11+
- .env
1512
ports:
1613
- "3000:3000"
1714
depends_on:
1815
database:
1916
condition: service_healthy
2017
networks:
2118
- backend
19+
deploy:
20+
resources:
21+
limits:
22+
cpus: "2.0"
23+
memory: 1024M
24+
reservations:
25+
cpus: "0.5"
26+
memory: 256M
2227

2328
database:
2429
hostname: database
2530
container_name: database
2631
image: postgres:16-alpine
2732
restart: always
2833
env_file:
29-
- ../.env
34+
- .env
3035
environment:
3136
POSTGRES_USER: ${DB_USERNAME}
3237
POSTGRES_PASSWORD: ${DB_PASSWORD}
@@ -38,7 +43,11 @@ services:
3843
networks:
3944
- backend
4045
healthcheck:
41-
test: ["CMD-SHELL", "pg_isready -U \"$$POSTGRES_USER\" -d \"$$POSTGRES_DB\" -q || exit 1"]
46+
test:
47+
[
48+
"CMD-SHELL",
49+
'pg_isready -U "$$POSTGRES_USER" -d "$$POSTGRES_DB" -q || exit 1',
50+
]
4251
interval: 5s
4352
timeout: 5s
4453
retries: 5

libs/config/src/config.schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const ConfigSchema = z.object({
1414
DB_SCHEMA: z.string({ error: 'DB_SCHEMA is missing' }),
1515
DATABASE_URL: z.string().url('DATABASE_URL must be a valid connection string'),
1616
REDIS_HOST: z.string().default('redis'),
17-
REDIS_PORT: z.coerce.number().default(6379),
17+
REDIS_PORT: z.coerce.number().optional().default(6379),
1818
DOMAIN: z
1919
.string()
2020
.toLowerCase()

src/modules/app/app.controller.ts

Whitespace-only changes.

src/modules/app/app.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import { S3Module } from '@libs/s3';
6060
useFactory: (cfg: ConfigService) => ({
6161
connection: {
6262
host: cfg.getOrThrow('REDIS_HOST'),
63-
port: cfg.getOrThrow('REDIS_PORT'),
63+
port: cfg.get('REDIS_PORT'),
6464
},
6565
}),
6666
}),

src/modules/auth/auth.module.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ import { BullMQAdapter } from '@bull-board/api/bullMQAdapter';
3737
RedisModule.forRootAsync({
3838
inject: [ConfigService],
3939
useFactory: async (cfg: ConfigService) => {
40-
const host = cfg.get('REDIS_HOST', { infer: true });
41-
const port = cfg.get('REDIS_PORT', { infer: true });
40+
const host = cfg.getOrThrow('REDIS_HOST', { infer: true });
41+
const port = cfg.get('REDIS_PORT');
42+
const url = `redis://${host}${port ? '' : ':' + port}`;
4243

4344
return {
4445
type: 'single',
45-
url: `redis://${host}:${port}`,
46+
url,
4647
options: {
4748
retryStrategy(times) {
4849
return Math.min(times * 50, 2000);

0 commit comments

Comments
 (0)