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

devops #24

Merged
merged 3 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 0 additions & 6 deletions .env.example

This file was deleted.

89 changes: 18 additions & 71 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ concurrency:
cancel-in-progress: true

jobs:
lint-web:
lint:
runs-on: ubuntu-latest
name: Run eslint/format on frontend
name: Run eslint/format
steps:
- uses: actions/checkout@v3
- name: Set up node
Expand All @@ -24,33 +24,15 @@ jobs:
- name: Install yarn
run: npm install -g yarn
- name: Install dependencies
run: yarn --cwd apps/web
- name: Lint web
run: yarn lint-web
run: yarn install
- name: Lint
run: yarn lint
- name: Prettier
run: yarn --cwd apps/web prettier --check .
lint-server:
run: yarn format
tsc:
runs-on: ubuntu-latest
name: Run eslint/format on server
steps:
- uses: actions/checkout@v3
- name: Set up node
uses: actions/setup-node@v3
with:
node-version: '19.x'
# cache: yarn
# cache-dependency-path: './apps/server/package-lock.json'
- name: Install yarn
run: npm install -g yarn
- name: Install dependencies
run: yarn --cwd apps/server
- name: Lint server
run: yarn lint-server
- name: Prettier
run: yarn --cwd apps/server prettier --check .
tsc-web:
runs-on: ubuntu-latest
name: Check tsc on frontend
name: Check tsc
needs: [lint]
steps:
- uses: actions/checkout@v3
- name: Set up node
Expand All @@ -62,48 +44,13 @@ jobs:
- name: Install yarn
run: npm install -g yarn
- name: Install dependencies
run: yarn --cwd apps/web
- name: tsc web
run: yarn tsc-web
tsc-server:
runs-on: ubuntu-latest
name: Check tsc on server
steps:
- uses: actions/checkout@v3
- name: Set up node
uses: actions/setup-node@v3
with:
node-version: '19.x'
# cache: yarn
# cache-dependency-path: './apps/server/package-lock.json'
- name: Install yarn
run: npm install -g yarn
- name: Install dependencies
run: yarn --cwd apps/server
- name: tsc server
run: yarn tsc-server
# jest-web:
# runs-on: ubuntu-latest
# name: Run tests on frontend
# needs: [lint-web, tsc-web] # ensure tests are run only after eslint and tsc pass
# steps:
# - uses: actions/checkout@v3
# - name: Set up node
# uses: actions/setup-node@v3
# with:
# node-version: '19.x'
# # cache: yarn
# # cache-dependency-path: './apps/web/package-lock.json'
# - name: Install yarn
# run: npm install -g yarn
# - name: Install dependencies
# run: yarn --cwd apps/web
# - name: Test web
# run: yarn test-web
jest-server:
run: yarn install
- name: tsc
run: yarn tsc
jest:
runs-on: ubuntu-latest
name: Run tests on server
needs: [lint-server, tsc-server] # ensure tests are run only after eslint and tsc pass
name: Run tests
needs: [lint, tsc] # ensure tests are run only after eslint and tsc pass
steps:
- uses: actions/checkout@v3
- name: Set up node
Expand All @@ -115,6 +62,6 @@ jobs:
- name: Install yarn
run: npm install -g yarn
- name: Install dependencies
run: yarn --cwd apps/server
- name: Test server
run: yarn test-server
run: yarn install
- name: Test
run: yarn test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

# postgres
/apps/server/pgdata
6 changes: 6 additions & 0 deletions apps/server/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Dockerfile
.dockerignore
node_modules
npm-debug.log
dist
coverage
6 changes: 6 additions & 0 deletions apps/server/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DOMAIN=http://localhost
PORT=8080
SALT_ROUNDS=10

# Prisma
DATABASE_URL="postgresql://user:pass@localhost:5432/db?schema=public"
80 changes: 80 additions & 0 deletions apps/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# https://dawchihliou.github.io/articles/the-last-dockerfile-you-need-for-nestjs

#
# 🧑‍💻 Development
#
FROM node:18-alpine as dev
# add the missing shared libraries from alpine base image
# RUN apk add --no-cache libc6-compat
# Create app folder
WORKDIR /app

# Set to dev environment
ENV NODE_ENV dev

# Create non-root user for Docker
# RUN addgroup --system --gid 1001 node
# RUN adduser --system --uid 1001 node

# Copy source code into app folder
COPY --chown=node:node . .

# Install dependencies
RUN yarn --frozen-lockfile

# Set Docker as a non-root user
USER node

#
# 🏡 Production Build
#
FROM node:18-alpine as build

WORKDIR /app
RUN apk add --no-cache libc6-compat

# Set to production environment
ENV NODE_ENV production

# Re-create non-root user for Docker
# RUN addgroup --system --gid 1001 node
# RUN adduser --system --uid 1001 node

# In order to run `yarn build` we need access to the Nest CLI.
# Nest CLI is a dev dependency.
COPY --chown=node:node --from=dev /app/node_modules ./node_modules
# Copy source code
COPY --chown=node:node . .

# Generate the production build. The build script runs "nest build" to compile the application.
RUN yarn build

# Install only the production dependencies and clean cache to optimize image size.
RUN yarn --frozen-lockfile --production && yarn cache clean

# Set Docker as a non-root user
USER node

#
# 🚀 Production Server
#
FROM node:18-alpine as prod

WORKDIR /app
RUN apk add --no-cache libc6-compat

# Set to production environment
ENV NODE_ENV production

# Re-create non-root user for Docker
# RUN addgroup --system --gid 1001 node
# RUN adduser --system --uid 1001 node

# Copy only the necessary files
COPY --chown=node:node --from=build /app/dist dist
COPY --chown=node:node --from=build /app/node_modules node_modules

# Set Docker as non-root user
USER node

CMD ["node", "dist/main.js"]
25 changes: 25 additions & 0 deletions apps/server/docker-compose.db.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: "3"
services:
db:
image: postgres:13
restart: always
ports:
- "5432:5432"
volumes:
- ./pgdata:/var/lib/postgresql/data
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: db

pgadmin:
image: dpage/pgadmin4
restart: always
container_name: nest-pgadmin4
environment:
- PGADMIN_DEFAULT_EMAIL=admin@admin.com
- PGADMIN_DEFAULT_PASSWORD=pgadmin4
ports:
- '5050:80'
depends_on:
- db
45 changes: 45 additions & 0 deletions apps/server/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
version: "3"
services:
app:
restart: on-failure
build:
context: .
dockerfile: Dockerfile
container_name: mfa-backend
depends_on:
- db
environment:
DATABASE_URL: postgres://user:pass@postgres:5432/db
NODE_ENV: development
PORT: 8080
ports:
- "8080:8080"
command: node dist/main.js
volumes:
- ./src:/apps
- .:/apps/
- /node_modules

db:
image: postgres:13
restart: always
ports:
- "5432:5432"
volumes:
- ./pgdata:/var/lib/postgresql/data
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: db

pgadmin:
image: dpage/pgadmin4
restart: always
container_name: nest-pgadmin4
environment:
- PGADMIN_DEFAULT_EMAIL=admin@admin.com
- PGADMIN_DEFAULT_PASSWORD=pgadmin4
ports:
- '5050:80'
depends_on:
- db
6 changes: 4 additions & 2 deletions apps/server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
"declaration": true,
"removeComments": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"target": "ESNext",
"sourceMap": true,
"outDir": "./dist"
"outDir": "./dist",
"emitDecoratorMetadata": true,
"experimentalDecorators": true
}
}
3 changes: 2 additions & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "mfa-frontend",
"name": "web",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"test": "jest",
"gen-client": "openapi --input http://localhost:4000/api-json --output ./src/client --client axios"
},
"dependencies": {
Expand Down
44 changes: 27 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
{
"name": "mfa-form-automator",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "yarn --cwd apps/web dev & yarn --cwd apps/server start:dev",
"format": "yarn --cwd apps/web prettier . --write & yarn --cwd apps/server prettier . --write",
"lint-web": "yarn --cwd apps/web lint",
"lint-server": "yarn --cwd apps/server lint",
"test-web": "yarn --cwd apps/web jest",
"test-server": "yarn --cwd apps/server test",
"tsc-web": "yarn --cwd apps/web tsc -p tsconfig.json",
"tsc-server": "yarn --cwd apps/server tsc -p tsconfig.json"
},
"keywords": [],
"author": "",
"license": "ISC"
"name": "mfa-form-automator",
"version": "1.0.0",
"description": "",
"main": "index.js",
"private": "true",
"workspaces": [
"apps/server",
"apps/web"
],
"scripts": {
"dev": "yarn --cwd apps/web dev & yarn --cwd apps/server start:dev",
"format": "yarn workspaces run prettier . --write",
"lint": "yarn workspaces run lint",
"test": "yarn workspaces run test --passWithNoTests",
"tsc": "yarn workspaces run tsc -p tsconfig.json",
"dev:db:up": "docker compose -f apps/server/docker-compose.db.yml up -d",
"dev:db:down": "docker compose -f apps/server/docker-compose.db.yml down",
"backend:docker:build": "docker compose -f apps/server/docker-compose.yml build",
"backend:docker:run": "docker compose -f apps/server/docker-compose.yml up -d",
"backend:docker:down": "docker compose -f apps/server/docker-compose.yml down"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@yarnpkg/plugin-workspace-tools": "^4.0.0-rc.51"
}
}
Loading