Skip to content

Commit d56b859

Browse files
authored
Merge pull request #105 from bsospace/develop
Develop
2 parents 211ec70 + 7d07a62 commit d56b859

7 files changed

Lines changed: 86 additions & 92 deletions

File tree

Dockerfile.dev

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Use the official Node.js image as the base image
2-
FROM node:18-alpine
2+
FROM node:18-bullseye
33

44
# Set the working directory inside the container
55
WORKDIR /bsoblog-dev
@@ -19,7 +19,5 @@ RUN npx prisma generate
1919
# Build the Next.js application
2020
RUN npm run build
2121

22-
EXPOSE 3000
23-
2422
# Start the Next.js application
2523
CMD ["npm", "start"]

Dockerfile.pre

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Use the official Node.js image as the base image
2-
FROM node:18-alpine
2+
FROM node:18-bullseye
33

44
# Set the working directory inside the container
55
WORKDIR /bsoblog-pre

Dockerfile.prod

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Use the official Node.js image as the base image
2-
FROM node:18-alpine
2+
FROM node:18-bullseye
33

44
# Install OpenSSL and other dependencies
5-
# RUN apk add --no-cache libssl3
65

76
# Set the working directory inside the container
87
WORKDIR /bsoblog-prod
@@ -22,7 +21,5 @@ RUN npx prisma generate
2221
# Build the Next.js application
2322
RUN npm run build
2423

25-
EXPOSE 9009
26-
2724
# Start the Next.js application
2825
CMD ["npm", "start"]

Jenkinsfile

Lines changed: 76 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,40 @@ pipeline {
22
agent any
33

44
environment {
5-
GIT_URL = 'https://github.com/bsospace/BSOSpace-Blog-Frontend'
6-
SLACK_CHANNEL = '#jenkins-notifications'
7-
APP_PORT = ''
8-
DOCKER_IMAGE_TAG = ''
9-
DOCKER_COMPOSE_FILE = ''
10-
STACK_NAME = ''
5+
DISCORD_WEBHOOK = credentials('discord-webhook')
116
}
127

138
stages {
14-
159
stage('Determine Environment') {
1610
steps {
1711
script {
18-
switch (env.BRANCH_NAME) {
12+
def branchName = env.BRANCH_NAME ?: 'unknown'
13+
branchName = branchName.replaceFirst('origin/', '')
14+
15+
switch (branchName) {
1916
case 'develop':
2017
env.ENVIRONMENT = 'development'
2118
env.ENV_FILE_CREDENTIAL = 'blog-dev-env-file'
19+
env.DOCKER_COMPOSE_FILE = 'docker-compose.develop.yml'
2220
break
23-
case ~(/release\/.*/):
21+
case ~/^release\/.*/:
2422
env.ENVIRONMENT = 'staging'
2523
env.ENV_FILE_CREDENTIAL = 'blog-staging-env-file'
24+
env.DOCKER_COMPOSE_FILE = 'docker-compose.pre.yml'
2625
break
2726
case 'main':
2827
env.ENVIRONMENT = 'production'
2928
env.ENV_FILE_CREDENTIAL = 'blog-prod-env-file'
29+
env.DOCKER_COMPOSE_FILE = 'docker-compose.prod.yml'
3030
break
3131
default:
3232
env.ENVIRONMENT = 'other'
33-
echo "Branch ${env.BRANCH_NAME} is not for deployment. Running Build and Test stages only."
33+
env.DOCKER_COMPOSE_FILE = ''
34+
echo "Branch ${branchName} is not supported. Skipping deployment."
3435
}
36+
37+
echo "Environment: ${env.ENVIRONMENT}"
38+
echo "DOCKER_COMPOSE_FILE: ${env.DOCKER_COMPOSE_FILE}"
3539
}
3640
}
3741
}
@@ -50,51 +54,15 @@ pipeline {
5054
}
5155
}
5256

53-
stage('Setup Environment Variables') {
54-
steps {
55-
script {
56-
def branchName = env.BRANCH_NAME?.replaceFirst('origin/', '')
57-
58-
switch (branchName) {
59-
case ~/^pre-.*/:
60-
APP_PORT = '3002'
61-
DOCKER_IMAGE_TAG = "pre-production-${branchName}-${BUILD_NUMBER}"
62-
DOCKER_COMPOSE_FILE = 'docker-compose.pre.yml'
63-
STACK_NAME = "bso-blog-pre"
64-
break
65-
case 'develop':
66-
APP_PORT = '3000'
67-
DOCKER_IMAGE_TAG = "develop-${BUILD_NUMBER}"
68-
DOCKER_COMPOSE_FILE = 'docker-compose.develop.yml'
69-
STACK_NAME = "bso-blog-develop"
70-
break
71-
case 'main':
72-
APP_PORT = '9009'
73-
DOCKER_IMAGE_TAG = "production-${BUILD_NUMBER}"
74-
DOCKER_COMPOSE_FILE = 'docker-compose.prod.yml'
75-
STACK_NAME = "bso-blog-production"
76-
break
77-
default:
78-
error("Unsupported branch: ${branchName}")
79-
}
80-
81-
echo "APP_PORT=${APP_PORT}, DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG}, STACK_NAME=${STACK_NAME}, DOCKER_COMPOSE_FILE=${DOCKER_COMPOSE_FILE}"
82-
}
83-
}
84-
}
85-
8657
stage('Checkout & Pull') {
8758
steps {
8859
script {
89-
checkout scm: [$class: 'GitSCM',
90-
branches: [[name: env.BRANCH_NAME]],
91-
userRemoteConfigs: [[url: GIT_URL]]]
92-
93-
def branch = env.BRANCH_NAME.replaceFirst('origin/', '')
94-
sh "git checkout ${branch} && git pull origin ${branch}"
95-
60+
checkout scm
9661
env.LAST_COMMIT_AUTHOR = sh(script: "git log -1 --pretty=format:'%an'", returnStdout: true).trim()
9762
env.LAST_COMMIT_MESSAGE = sh(script: "git log -1 --pretty=format:'%s'", returnStdout: true).trim()
63+
64+
echo "Last Commit Author: ${env.LAST_COMMIT_AUTHOR}"
65+
echo "Last Commit Message: ${env.LAST_COMMIT_MESSAGE}"
9866
}
9967
}
10068
}
@@ -117,13 +85,14 @@ pipeline {
11785

11886
stage('Build & Deploy Docker') {
11987
when {
120-
expression { env.ENVIRONMENT != 'other' }
88+
expression { env.ENVIRONMENT != 'other' && env.DOCKER_COMPOSE_FILE?.trim() }
12189
}
12290
steps {
12391
script {
92+
echo "Using DOCKER_COMPOSE_FILE: ${env.DOCKER_COMPOSE_FILE}"
12493
sh """
125-
docker-compose -p ${STACK_NAME} -f ${DOCKER_COMPOSE_FILE} build --no-cache --build-arg DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG}
126-
docker-compose -p ${STACK_NAME} -f ${DOCKER_COMPOSE_FILE} up -d
94+
docker compose -f ${env.DOCKER_COMPOSE_FILE} build
95+
docker compose -f ${env.DOCKER_COMPOSE_FILE} up -d
12796
"""
12897
}
12998
}
@@ -133,15 +102,60 @@ pipeline {
133102
post {
134103
always {
135104
script {
136-
def color = (currentBuild.result == 'SUCCESS') ? '#36A64F' : '#FF0000'
137-
slackSend(channel: SLACK_CHANNEL, color: color, message: """
138-
*Pipeline Report*
139-
*Job*: ${env.JOB_NAME} [#${env.BUILD_NUMBER}]
140-
*Status*: ${currentBuild.result}
141-
*Branch*: ${env.BRANCH_NAME}
142-
*Author*: ${env.LAST_COMMIT_AUTHOR}
143-
*Commit Message*: ${env.LAST_COMMIT_MESSAGE}
144-
""")
105+
def color = (currentBuild.result == 'SUCCESS') ? 3066993 : 15158332
106+
def status = (currentBuild.result == 'SUCCESS') ? '✅ Success' : '❌ Failure'
107+
def timestamp = new Date().format("yyyy-MM-dd'T'HH:mm:ss'Z'", TimeZone.getTimeZone('UTC'))
108+
109+
def payload = [
110+
content: null,
111+
embeds: [[
112+
title: "🚀 Pipeline Execution Report For BSO Blog Front-end",
113+
description: "Pipeline execution details below:",
114+
color: color,
115+
thumbnail: [
116+
url: "https://raw.githubusercontent.com/bsospace/assets/refs/heads/main/LOGO/LOGO%20WITH%20CIRCLE.ico"
117+
],
118+
fields: [
119+
[
120+
name: "Job",
121+
value: "${env.JOB_NAME} [#${env.BUILD_NUMBER}]",
122+
inline: true
123+
],
124+
[
125+
name: "Status",
126+
value: status,
127+
inline: true
128+
],
129+
[
130+
name: "Branch",
131+
value: "${env.BRANCH_NAME ?: 'unknown'}",
132+
inline: true
133+
],
134+
[
135+
name: "Author",
136+
value: "${env.LAST_COMMIT_AUTHOR ?: 'unknown'}",
137+
inline: true
138+
],
139+
[
140+
name: "Commit Message",
141+
value: "${env.LAST_COMMIT_MESSAGE ?: 'unknown'}",
142+
inline: false
143+
]
144+
],
145+
footer: [
146+
text: "Pipeline executed at",
147+
icon_url: "https://raw.githubusercontent.com/bsospace/assets/refs/heads/main/LOGO/LOGO%20WITH%20CIRCLE.ico"
148+
],
149+
timestamp: timestamp
150+
]]
151+
]
152+
153+
httpRequest(
154+
url: env.DISCORD_WEBHOOK,
155+
httpMode: 'POST',
156+
contentType: 'APPLICATION_JSON',
157+
requestBody: groovy.json.JsonOutput.toJson(payload)
158+
)
145159
}
146160
}
147161
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# BSO Space Blog Frontend
22

3-
[![Bugs](https://sonarqube.bsospace.com/api/project_badges/measure?project=bso-space-app&metric=bugs&token=sqb_f0e574fbcaedfab483d303668cf0a3ba4ba18f8d)](https://sonarqube.bsospace.com/dashboard?id=bso-space-app) [![Maintainability Rating](https://sonarqube.bsospace.com/api/project_badges/measure?project=bso-space-app&metric=sqale_rating&token=sqb_f0e574fbcaedfab483d303668cf0a3ba4ba18f8d)](https://sonarqube.bsospace.com/dashboard?id=bso-space-app) [![Quality Gate Status](https://sonarqube.bsospace.com/api/project_badges/measure?project=bso-space-app&metric=alert_status&token=sqb_f0e574fbcaedfab483d303668cf0a3ba4ba18f8d)](https://sonarqube.bsospace.com/dashboard?id=bso-space-app) [![Reliability Rating](https://sonarqube.bsospace.com/api/project_badges/measure?project=bso-space-app&metric=reliability_rating&token=sqb_f0e574fbcaedfab483d303668cf0a3ba4ba18f8d)](https://sonarqube.bsospace.com/dashboard?id=bso-space-app) [![Security Rating](https://sonarqube.bsospace.com/api/project_badges/measure?project=bso-space-app&metric=security_rating&token=sqb_f0e574fbcaedfab483d303668cf0a3ba4ba18f8d)](https://sonarqube.bsospace.com/dashboard?id=bso-space-app)
3+
[![Code Smells](https://sonarqube.bsospace.com/api/project_badges/measure?project=bso-blog&metric=code_smells&token=sqb_510dbd5acec52221843e4c7db5b534331c6ef6b6)](https://sonarqube.bsospace.com/dashboard?id=bso-blog) [![Lines of Code](https://sonarqube.bsospace.com/api/project_badges/measure?project=bso-blog&metric=ncloc&token=sqb_510dbd5acec52221843e4c7db5b534331c6ef6b6)](https://sonarqube.bsospace.com/dashboard?id=bso-blog) [![Quality Gate Status](https://sonarqube.bsospace.com/api/project_badges/measure?project=bso-blog&metric=alert_status&token=sqb_510dbd5acec52221843e4c7db5b534331c6ef6b6)](https://sonarqube.bsospace.com/dashboard?id=bso-blog) [![Security Rating](https://sonarqube.bsospace.com/api/project_badges/measure?project=bso-blog&metric=security_rating&token=sqb_510dbd5acec52221843e4c7db5b534331c6ef6b6)](https://sonarqube.bsospace.com/dashboard?id=bso-blog)
44

55
Welcome to the **BSO Space Blog** repository! This open-source project is part of the **BSO Space** platform, a collaborative blog designed specifically for Software Engineering students to share insights, learnings, and projects with a wider audience. This repository contains the frontend code for the BSO Space Blog.
66

docker-compose.develop.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ services:
77
dockerfile: Dockerfile.dev
88
image: bso-dev-image
99
container_name: bso-blog-develop
10-
environment:
11-
NODE_ENV: development
10+
env_file:
11+
- .env
1212
ports:
1313
- "3000:3000"
14-
env_file:
15-
- .env.develop
1614
volumes:
1715
- ./app-develop:/app
1816
- /develop_app/node_modules

docker-compose.yml

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,13 @@ version: "3"
33
services:
44
web:
55
build: .
6-
container_name: ${DOCKER_NAME:-bso-blog}
6+
container_name: production-bso-blog
77
ports:
88
- "9009:3000"
9-
environment:
10-
APP_PORT: ${APP_PORT:-3000}
11-
DATABASE_URL: ${DATABASE_URL}
12-
NODE_ENV: ${NODE_ENV}
13-
PG_USER: ${PG_USER}
14-
PG_PASSWORD: ${PG_PASSWORD}
15-
PGADMIN_EMAIL: ${PGADMIN_EMAIL}
16-
PGADMIN_PASSWORD: ${PGADMIN_PASSWORD}
17-
GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID}
18-
GOOGLE_CLIENT_SECRET: ${GOOGLE_CLIENT_SECRET}
19-
NEXTAUTH_URL: ${NEXTAUTH_URL}
20-
GITHUB_CLIENT_ID: ${GITHUB_CLIENT_ID}
21-
GITHUB_CLIENT_SECRET: ${GITHUB_CLIENT_SECRET}
22-
PRODUCTION_URL: ${PRODUCTION_URL}
23-
NEXT_PUBLIC_TINYMCE_API_KEY: ${NEXT_PUBLIC_TINYMCE_API_KEY}
9+
env_file:
10+
- .env
2411
volumes:
2512
- ./app:/app
2613
- /app/node_modules
2714
command: npm start
28-
restart: unless-stopped
15+
restart: unless-stopped

0 commit comments

Comments
 (0)