diff --git a/.github/workflows/api-tests.yml b/.github/workflows/api-tests.yml index ded53944..1b0b23e7 100644 --- a/.github/workflows/api-tests.yml +++ b/.github/workflows/api-tests.yml @@ -5,11 +5,15 @@ on: paths: - 'api/**' - '.github/workflows/api-tests.yml' + - '/*' # include changes in root + - '!client/**' # exclude client folder + - '!infrastructure/**' # exclude infra folder workflow_dispatch: jobs: + api-tests-e2e: name: API E2E Tests runs-on: ubuntu-22.04 diff --git a/.github/workflows/client-tests.yml b/.github/workflows/client-tests.yml index 7c1b8756..46e34c1b 100644 --- a/.github/workflows/client-tests.yml +++ b/.github/workflows/client-tests.yml @@ -3,8 +3,11 @@ name: Client Tests on: push: paths: - - 'api/**' - - '.github/workflows/client-tests.yml' + - 'client/**' + - '.github/workflows/api-tests.yml' + - '/*' # include changes in root + - '!api/**' # exclude client folder + - '!infrastructure/**' # exclude infra folder workflow_dispatch: diff --git a/api/Dockerfile b/api/Dockerfile new file mode 100644 index 00000000..be1f5b1b --- /dev/null +++ b/api/Dockerfile @@ -0,0 +1,32 @@ +# TODO: Consider using 2 steps, one for building, then copy the build artifacts to a new image for running. Talk with FE team about this. + +FROM node:22.2.0-alpine + + +WORKDIR /app + + +COPY package.json pnpm-workspace.yaml pnpm-lock.yaml tsconfig.json ./ +COPY api/package.json api/tsconfig.json ./api/ +COPY shared/package.json shared/tsconfig.json ./shared/ + +# Install jq to extract the version of pnpm from the package.json +RUN apk add --no-cache jq + +# Extract the version of pnpm from the package.json and install it +RUN export PNPM_VERSION=$(jq -r '.packageManager' /app/package.json | cut -d '@' -f 2) && \ + npm install -g pnpm@$PNPM_VERSION + +COPY api ./api +COPY shared ./shared + +RUN pnpm run api:deps + + +RUN pnpm api:build + + +EXPOSE 4000 + + +CMD ["pnpm", "api:prod"] diff --git a/api/src/app.module.ts b/api/src/app.module.ts index 5ab18be6..b92dd00b 100644 --- a/api/src/app.module.ts +++ b/api/src/app.module.ts @@ -2,6 +2,11 @@ import { Module } from '@nestjs/common'; import { AppController } from './app.controller'; import { AppService } from '@api/app.service'; import { UsersModule } from '@api/modules/users/users.module'; +import { User } from '@shared/dto/users/user.entity'; + +// TODO: The dist folder structure changes if some shared lib is imported in the api. Check this + +const user: User = new User(); @Module({ imports: [UsersModule], diff --git a/client/Dockerfile b/client/Dockerfile new file mode 100644 index 00000000..c6575d92 --- /dev/null +++ b/client/Dockerfile @@ -0,0 +1,33 @@ +# TODO: Consider using 2 steps, one for building, then copy the build artifacts to a new image for running. Talk with FE team about this. + +FROM node:22.2.0-alpine + +WORKDIR /app + + +COPY package.json pnpm-workspace.yaml pnpm-lock.yaml tsconfig.json ./ +COPY client/package.json client/tsconfig.json ./client/ +COPY shared/package.json shared/tsconfig.json ./shared/ + +# Install jq to extract the version of pnpm from the package.json +RUN apk add --no-cache jq + +# Extract the version of pnpm from the package.json and install it +RUN export PNPM_VERSION=$(jq -r '.packageManager' /app/package.json | cut -d '@' -f 2) && \ + npm install -g pnpm@$PNPM_VERSION + + +COPY client ./client +COPY shared ./shared + +RUN pnpm client:deps + + + + +RUN pnpm client:build + +EXPOSE 3000 + + +CMD ["pnpm", "client:prod"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..a8cf2035 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,29 @@ +version: '3.8' + +services: + api: + build: + context: . + dockerfile: api/Dockerfile + ports: + - "4000:4000" + environment: + - NODE_ENV=production + networks: + - 4-growth-docker-network + + client: + build: + context: . + dockerfile: client/Dockerfile + ports: + - "3000:3000" + environment: + - NODE_ENV=production + networks: + - 4-growth-docker-network + + +networks: + 4-growth-docker-network: + driver: bridge \ No newline at end of file