Skip to content

Commit 7a5dcda

Browse files
committed
chore: test infra
1 parent dabedca commit 7a5dcda

12 files changed

Lines changed: 82 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ 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 ./
33+
COPY --from=build /app/drizzle.config.ts ./drizzle.config.ts
3234

3335
EXPOSE 3000
3436

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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Файл для фронт разрабов
2+
3+
Цель файла - дать инстанс бэка, чтоб фронты могли локально запускать с минимальными развертываниями
4+
5+
```sh
6+
docker compose -f ./infra/dev/compose.dev.yaml --profile infra up --pull always --build -d -V
7+
```
Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,39 @@
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
17+
redis:
18+
condition: service_healthy
2019
networks:
2120
- backend
21+
deploy:
22+
resources:
23+
limits:
24+
cpus: "2.0"
25+
memory: 1024M
26+
reservations:
27+
cpus: "0.5"
28+
memory: 256M
2229

2330
database:
2431
hostname: database
2532
container_name: database
2633
image: postgres:16-alpine
2734
restart: always
2835
env_file:
29-
- ../.env
36+
- .env
3037
environment:
3138
POSTGRES_USER: ${DB_USERNAME}
3239
POSTGRES_PASSWORD: ${DB_PASSWORD}
@@ -38,7 +45,11 @@ services:
3845
networks:
3946
- backend
4047
healthcheck:
41-
test: ["CMD-SHELL", "pg_isready -U \"$$POSTGRES_USER\" -d \"$$POSTGRES_DB\" -q || exit 1"]
48+
test:
49+
[
50+
"CMD-SHELL",
51+
'pg_isready -U "$$POSTGRES_USER" -d "$$POSTGRES_DB" -q || exit 1',
52+
]
4253
interval: 5s
4354
timeout: 5s
4455
retries: 5
@@ -56,6 +67,11 @@ services:
5667
- redis_data:/data
5768
networks:
5869
- backend
70+
healthcheck:
71+
test: ["CMD", "redis-cli", "ping"]
72+
interval: 5s
73+
timeout: 3s
74+
retries: 5
5975
profiles: ["infra"]
6076

6177
volumes:

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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { MailProcessor } from 'src/shared/workers';
1616
import { BullModule } from '@nestjs/bullmq';
1717
import { MailAdapter } from 'src/shared/adapters/mail';
1818
import { S3Module } from '@libs/s3';
19+
import { MigrationService } from 'src/shared/migration';
1920

2021
@Module({
2122
imports: [
@@ -60,7 +61,7 @@ import { S3Module } from '@libs/s3';
6061
useFactory: (cfg: ConfigService) => ({
6162
connection: {
6263
host: cfg.getOrThrow('REDIS_HOST'),
63-
port: cfg.getOrThrow('REDIS_PORT'),
64+
port: cfg.get('REDIS_PORT'),
6465
},
6566
}),
6667
}),
@@ -73,6 +74,7 @@ import { S3Module } from '@libs/s3';
7374
HealthModule.register('gateway'),
7475
],
7576
providers: [
77+
MigrationService,
7678
{
7779
provide: 'IMailPort',
7880
useClass: MailAdapter,

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)