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

Release/v.0.1.0 #10

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c64fd19
👷 build[package.json]: Update type definitions and add new dependencies
boytur Dec 15, 2024
90ec9b1
🔧 chore[environment]: Add frontend, backend, and service name variabl…
boytur Dec 15, 2024
45824df
♻️ refactor[user.service]: Enhance user retrieval methods to include …
boytur Dec 15, 2024
24b9a04
👷 build[package.json]: Add cookie-parser and its type definitions
boytur Dec 15, 2024
15827ea
🔧 chore[gitignore]: Update .gitignore to include keys and PEM files
boytur Dec 15, 2024
1c282c2
✨ feat[auth.controller]: Add 'me' endpoint to retrieve user info and …
boytur Dec 15, 2024
7802928
✨ feat[app]: Initialize cookie-parser middleware for enhanced request…
boytur Dec 15, 2024
4257b68
🔧 chore[env]: Add COOKIE_DOMAIN variable to .env.example and env.conf…
boytur Dec 15, 2024
eae168c
📝 docs[auth.docs]: Update authentication API documentation to include…
boytur Dec 15, 2024
f31770d
✨ feat[middlewares]: Add authentication and role-based access control…
boytur Dec 15, 2024
c2b3db6
✨ feat[auth.service]: Bind login and profile methods in constructor a…
boytur Dec 15, 2024
92a8b6d
✨ feat[cache.service]: Implement CacheService with Redis client for c…
boytur Dec 15, 2024
118c7fa
✨ feat[crypto.service]: Implement CryptoService for password hashing …
boytur Dec 15, 2024
fb364e0
♻️ refactor[user.service]: Enhance user data retrieval by including c…
boytur Dec 15, 2024
60830ea
✨ feat[auth.route]: Simplify login route and add 'me' endpoint with a…
boytur Dec 15, 2024
ff38d13
✨ feat[utils]: Add utility functions for error handling, logging, and…
boytur Dec 15, 2024
c0b3bea
📝 docs[auth.docs]: Add 'me' endpoint documentation for fetching authe…
boytur Dec 15, 2024
186ae7d
✨ feat: Implement location and sublocation routes with validation
poommieiei Dec 15, 2024
e7ebfcd
Merge pull request #5 from poommieiei/feature/AT-65-Backend-Implement…
boytur Dec 15, 2024
6ec2557
Merge pull request #4 from BSO-Space/feature/AT-93-Backend-Authentica…
boytur Dec 15, 2024
c833c52
Merge pull request #7 from BSO-Space/feature/AT-65-Backend-Implement-…
boytur Dec 15, 2024
6dfe033
👷build[package.json]: update bcrypt type definitions and adjust prism…
boytur Dec 25, 2024
7f8155d
✨ feat: Refactor seed script to improve structure and add role and pe…
boytur Dec 25, 2024
8f9b059
🔧 chore[tsconfig.json]: comment out rootDir in tsconfig.json for clar…
boytur Dec 25, 2024
1e58f4d
♻️ refactor[prisma]: update import paths for prisma client in service…
boytur Dec 25, 2024
eada39e
🔧 chore[Jenkinsfile]: simplify prisma generate command by removing sc…
boytur Dec 25, 2024
17c780d
Merge pull request #8 from BSO-Space/develop
poommieiei Dec 25, 2024
e7f125e
🔧 chore[Dockerfile]: Dockerfile with multi-stage build for optimized …
boytur Dec 25, 2024
b9d7907
Merge pull request #9 from BSO-Space/develop
poommieiei Dec 25, 2024
407eeef
🔧 chore[Jenkinsfile]: deleted credential use and pull code
boytur Dec 26, 2024
4df00b0
🔧 chore[tsconfig]: update target and module settings for compatibility
boytur Dec 26, 2024
cb6a2ef
🔧 chore[package.json]: change module type from 'module' to 'commonjs'
boytur Dec 26, 2024
67ba710
♻️ refacto: update import paths for consistency across controllers, s…
boytur Dec 26, 2024
d04ad82
🔧 chore[package.json]: update start script path to reflect new direct…
boytur Dec 26, 2024
0e6097b
🔧 chore[docker] update Dockerfile and docker-compose files to use Nod…
boytur Dec 26, 2024
07f6e53
🔧 chore[Jenkinsfile]: remove redundant post checkout messages
boytur Dec 26, 2024
caa40c4
🔧 chore[Jenkinsfile]: refactor stages to determine environment and st…
boytur Dec 26, 2024
50ba172
🔧 chore[package.json]: simplify Prisma commands by removing schema pa…
boytur Dec 26, 2024
6587b9a
🔧 chore[Jenkinsfile]: update deployment conditions to exclude 'other'…
boytur Dec 26, 2024
1c5b827
🔧 chore[Jenkinsfile]: add debug output to list loaded environment file
boytur Dec 26, 2024
71d7725
🔧 chore[Jenkinsfile]: add output to display contents of loaded enviro…
boytur Dec 26, 2024
c548f5a
🔧 chore[app]: integrate Prisma connection and graceful shutdown handling
boytur Jan 5, 2025
c8516a0
Merge branch 'main' into release/v.0.1.0
boytur Jan 5, 2025
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: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
NODE_ENV=
APP_PORT=


FRONTEND_URL=
BACKEND_URL=
SERVICE_NAME=
COOKIE_DOMAIN=

# Database variables
DATABASE_URL=

Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,6 @@ dist
node_modules
.env*
build
dist
dist
keys
*pem
38 changes: 27 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
# Use an official Node.js runtime as the base image
FROM node:22
# Stage 1: Build Stage
FROM node:20-alpine3.17 AS build

# Set the working directory inside the container
# Set the working directory
WORKDIR /app

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./
# Copy only package files for dependency installation
COPY package*.json tsconfig.json ./

# Install dependencies
RUN npm install
# Install all dependencies (including devDependencies)
RUN npm ci

# Copy the rest of the application code to the working directory
# Copy the rest of the application code
COPY . .

# Prisma Client generates a Node.js client for the Prisma API. It is used to access the database in the application code.
RUN npm run prisma:generate

# Build the TypeScript code
RUN npm run build

# Stage 2: Production Runtime Stage
FROM node:20-alpine3.17

# Set the working directory
WORKDIR /app

# Copy only production dependencies from the build stage
COPY package*.json ./
RUN npm ci --only=production

# Copy the built application from the build stage
COPY --from=build /app/dist ./dist

# Copy Prisma schema and other necessary files (if needed)
COPY --from=build /app/prisma ./prisma

# Generate Prisma client (if Prisma is used)
RUN npx prisma generate

# Start the application
CMD ["npm", "start"]
2 changes: 1 addition & 1 deletion Dockerfile.release
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use an official Node.js runtime as the base image
FROM node:22
FROM node:20-alpine3.17 AS build

# Set the working directory inside the container
WORKDIR /app
Expand Down
137 changes: 63 additions & 74 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,151 +1,140 @@
pipeline {
agent any

environment {
REPO_URL = 'https://github.com/BSO-Space/attendify-back.git'
WORKSPACE_DIR = "${env.WORKSPACE}"
}

stages {
stage("Pull") {
stage('Determine Environment') {
steps {
script {
checkout([
$class: 'GitSCM',
branches: [[name: "*/${env.BRANCH_NAME}"]],
userRemoteConfigs: [[
url: 'https://github.com/BSO-Space/attendify-back.git',
credentialsId: '3c91d658-54b4-4606-b119-5fd58aa85b28'
]]
])
if (env.BRANCH_NAME ==~ /release\/.*/) {
env.ENVIRONMENT = 'staging'
env.ENV_FILE_CREDENTIAL = 'attendify-staging-env-file'
} else if (env.BRANCH_NAME == 'main') {
env.ENVIRONMENT = 'production'
env.ENV_FILE_CREDENTIAL = 'attendify-prod-env-file'
} else {
env.ENVIRONMENT = 'other'
env.ENV_FILE_CREDENTIAL = 'attendify-feature-env-file'
}
}
}
}

stage('Checkout Code') {
steps {
checkout scm
}
post {
always {
echo "Pulling from ${env.BRANCH_NAME}"
echo "Code checkout completed."
}
success {
echo "Pulled Successfully"
echo "Code checkout successful."
}
failure {
echo "Pulled Failed"
echo "Code checkout failed."
}
}
}

stage('Load Environment') {
when {
anyOf {
branch 'main'
branch pattern: 'release/.*'
}
}
stage('Setup .env') {
steps {
script {
// กำหนดตัวแปร sourceFile และ destinationFile ให้อยู่ในพื้นที่เดียวกัน
def sourceFile
def destinationFile

if (env.BRANCH_NAME == 'main') {
sourceFile = '/var/jenkins_home/credential/attendify-back/.env'
destinationFile = "${WORKSPACE}/.env"
} else {
sourceFile = '/var/jenkins_home/credential/attendify-back/.env.release'
destinationFile = "${WORKSPACE}/.env.release"
}

// ตรวจสอบว่าต้นทางมีอยู่ก่อนคัดลอก
if (fileExists(sourceFile)) {
sh "cp ${sourceFile} ${destinationFile}"
echo "Environment file copied successfully to ${destinationFile}"
} else {
error "Source file does not exist: ${sourceFile}"
// Load the Secret File and save it as .env
withCredentials([file(credentialsId: "${ENV_FILE_CREDENTIAL}", variable: 'SECRET_ENV_FILE')]) {
def envFile = env.BRANCH_NAME ==~ /release\/.*/ ? '.env.release' : '.env'
sh "cp $SECRET_ENV_FILE ${envFile}"
sh "ls -la ${envFile}"
sh "cat ${envFile}"
echo "Loaded environment file for ${env.ENVIRONMENT} using ${envFile}."
}
}
}
post {
always {
echo "Loading Environment"
}
success {
echo "Loaded Successfully"
}
failure {
echo "Loaded Failed"
}
}
}

stage("Install Dependencies") {
stage('Install Dependencies') {
steps {
script {
sh "npm install && npx prisma generate --schema=./src/prisma/schema.prisma"
sh 'npm ci && npx prisma generate'
}
}
post {
always {
echo "Installing Dependencies"
echo "Dependencies installation completed."
}
success {
echo "Installed Successfully"
echo "Dependencies installed successfully."
}
failure {
echo "Installed Failed"
echo "Dependencies installation failed."
}
}
}

stage("Build") {
stage('Build Application') {
steps {
script {
sh "npm run build"
sh 'npm run build'
}
}
post {
always {
echo "Building"
echo "Build process completed."
}
success {
echo "Built Successfully"
echo "Build successful."
}
failure {
echo "Build Failed"
echo "Build failed."
}
}
}

stage("Deploy") {
stage('Deploy Application') {
when {
anyOf {
branch 'main'
branch pattern: 'release/.*'
not {
expression {
env.ENVIRONMENT == 'other'
}
}
}
steps {
script {
if (env.BRANCH_NAME == 'main') {
echo "Deploying using docker-compose.yml"
sh "docker compose up -d"
} else {
echo "Deploying using docker-compose.release.yml"
sh "docker compose -f docker-compose.release.yml up -d"
}
def composeFile = env.BRANCH_NAME == 'main'
? 'docker-compose.yml'
: 'docker-compose.release.yml'

echo "Deploying using ${composeFile}"
sh "docker compose -f ${composeFile} up -d --build"
}
}
post {
always {
echo "Deploying"
echo "Deployment process completed."
}
success {
echo "Deployment Successful"
echo "Application deployed successfully."
}
failure {
echo "Deployment Failed"
echo "Deployment failed."
}
}
}
}

post {
always {
echo "Pipeline execution completed."
}
success {
echo "Pipeline execution successful"
echo "Pipeline executed successfully."
}
failure {
echo "Pipeline execution failed"
echo "Pipeline execution failed."
}
}
}
4 changes: 0 additions & 4 deletions docker-compose.release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ services:
- "${APP_PORT}:3000"
env_file:
- .env.release
volumes:
- .:/app
- /app/node_modules
- /app/dist
depends_on:
- db
- redis
Expand Down
4 changes: 0 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ services:
- "${APP_PORT}:3000"
env_file:
- .env
volumes:
- .:/app
- /app/node_modules
- /app/dist
depends_on:
- db
- redis
Expand Down
Loading