Skip to content

Commit

Permalink
dockerization
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed May 18, 2024
1 parent 61a0719 commit 82dc232
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/api-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/client-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
32 changes: 32 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
5 changes: 5 additions & 0 deletions api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
33 changes: 33 additions & 0 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 82dc232

Please sign in to comment.