Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(root): Add Dockerfile and docker-compose #666

Open
wants to merge 16 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/deploy_checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Deploy Checks

on:
pull_request:
branches: [ dev ]
jobs:
deploy_preview:
name: Deploy Checks
runs-on: ubuntu-latest
permissions:
deployments: write
contents: read
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build Docker Compose services
run: docker-compose build
- name: Start Docker Compose services
run: docker-compose up -d
- name: List running services
run: docker-compose ps
# - name: Ensure services remain healthy
# run:
- name: Shutdown Docker Compose services
run: docker-compose down
49 changes: 49 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# syntax = docker/dockerfile:1.2
usirin marked this conversation as resolved.
Show resolved Hide resolved
FROM node:18 AS base
WORKDIR /app
RUN npm install --global turbo
COPY . .

# kampus-builder stage, use "turbo" to get incremental builds
FROM base AS kampus-builder
# Prune the workspace
RUN turbo prune --scope=@kampus-apps/kampus --docker
RUN npm install
# Build the project
RUN npx turbo build --filter=kampus...

# gql-builder stage, use "turbo" to get incremental builds
FROM base AS gql-builder
# Prune the workspace
RUN turbo prune --scope=@kampus-apps/gql --docker
# First install the dependencies (as they change less often)
RUN npm install
# Build the project
RUN npx turbo build --filter=gql...

# pasaport-builder stage, use "turbo" to get incremental builds
FROM base AS pasaport-builder
# Prune the workspace
RUN turbo prune --scope=@kampus-apps/pasaport --docker
# First install the dependencies (as they change less often)
RUN npm install
# Build the project
RUN npx turbo build --filter=pasaport...

# kampus stage - the dev server
FROM node:18-bullseye-slim as kampus
COPY --from=kampus-builder /app .
EXPOSE 3000
CMD ["npm", "run", "dev", "-w", "@kampus-apps/kampus"]

# gql stage - the dev server
FROM node:18-bullseye-slim as gql
COPY --from=gql-builder /app .
EXPOSE 3002
CMD ["npm", "run", "dev", "-w", "@kampus-apps/gql"]

# pasaport stage - the dev server
FROM node:18-bullseye-slim as pasaport
COPY --from=pasaport-builder /app .
EXPOSE 3001
CMD ["npm", "run", "dev", "-w", "@kampus-apps/pasaport"]
46 changes: 44 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ kamp.us web projects & packages
- sozluk: turkce terimler sozlugu - https://sozluk.dev.kamp.us
- pano: link & bilgi & soru cevap paylasim platformu - https://pano.dev.kamp.us
- gql: https://gql.dev.kamp.us/graphql
- pasaport: kampus icin kullanici bilgileri & [centralized auth](https://sozluk.dev.kamp.us/centralized-auth) servisi - https://pasaport.dev.kamp.us
- pasaport: kampus icin kullanici bilgileri & [centralized auth](https://sozluk.dev.kamp.us/centralized-auth)
servisi - https://pasaport.dev.kamp.us
- storybook: @kampus/ui paketi icin hosted storybook - https://ui.dev.kamp.us

## IMPORTANT NOTE
Expand All @@ -18,7 +19,7 @@ and say hi to us at #kampus-projects channel.
## Getting started

- Fork `kamp-us/monorepo` under your personal account.
- eg: `usirin/monorepo`
- eg: `usirin/monorepo`
- Clone the project to your local computer:

```sh
Expand Down Expand Up @@ -46,3 +47,44 @@ If you haven't already install [Volta](https://volta.sh), you can install instal
```sh
curl https://get.volta.sh | bash
```

## Docker Setup

### Dockerfile

- We use a multi-stage build process to separate the building of applications from the final production image. This
ensures smaller and more optimized production images.
- We build three services: `kampus`, `gql`, and `pasaport`. Each service has its dedicated builder stage followed by its
execution stage.
- The `node:18-bullseye-slim` image is used to keep the final production images lean.

### Docker Compose

- We have four primary services: `mysql`, `kampus`, `gql`, and `pasaport`.
- `mysql` is the database service. We ensure that its authentication is set correctly and ports are mapped to allow for
local development access.
- The other three services are built using the project's Dockerfile. These services are exposed on ports 3000, 3001, and
3002 respectively.
- Health checks are set up for each service to ensure they are running correctly.

## Running a Fully Clean Build with Docker Compose

- To build the images and run the containers, run the following command:

```sh
docker-compose up --build -d
```

- To stop the containers, run the following command:

```sh
docker-compose down
```

## Running a Fully Clean Build with Docker

- Build and start the services, ensuring Docker Compose builds the images from scratch without using any cache.

```sh
docker-compose up --build --force-recreate
```
117 changes: 117 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
version: "3.9"

services:
mysql:
usirin marked this conversation as resolved.
Show resolved Hide resolved
container_name: mysql
image: mysql
command: --default-authentication-plugin=mysql_native_password
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: kampus
MYSQL_DATABASE: kampus
MYSQL_USER: kampus
MYSQL_PASSWORD: kampus
volumes:
- mysqldata:/var/lib/mysql
networks:
- kampus-network
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-p$MYSQL_ROOT_PASSWORD"]
interval: 1m
timeout: 10s
retries: 3

kampus:
container_name: kampus
build:
context: .
dockerfile: Dockerfile
target: kampus
ports:
- "3000:3000"
restart: unless-stopped
depends_on:
- mysql
networks:
- kampus-network
volumes:
- kampusdata:/app
env_file:
- .env
logging:
driver: "json-file"
options:
max-size: "200k"
max-file: "10"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000"]
interval: 30s
timeout: 10s
retries: 3

gql:
container_name: gql
build:
context: .
dockerfile: Dockerfile
target: gql
ports:
- "3001:3001"
restart: unless-stopped
depends_on:
- mysql
networks:
- kampus-network
volumes:
- gqldata:/app
env_file:
- .env
logging:
driver: "json-file"
options:
max-size: "200k"
max-file: "10"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3001"]
interval: 30s
timeout: 10s
retries: 3

pasaport:
container_name: pasaport
build:
context: .
dockerfile: Dockerfile
target: pasaport
ports:
- "3002:3002"
restart: unless-stopped
depends_on:
- mysql
networks:
- kampus-network
volumes:
- pasaportdata:/app
env_file:
- .env
logging:
driver: "json-file"
options:
max-size: "200k"
max-file: "10"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3002"]
interval: 30s
timeout: 10s
retries: 3

volumes:
mysqldata:
kampusdata:
gqldata:
pasaportdata:

networks:
kampus-network:
driver: bridge
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading