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

ED-4000 feat: Github actions instead of Jenkins-18 #9304

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e88a0a5
ED-4000 feat: Github actions instead of Jenkins-18
princegupta1131 Jun 10, 2024
ad5a9b3
ED-4000 feat: Github actions instead of Jenkins-19
princegupta1131 Jun 10, 2024
7e9aaf0
ED-4000 feat: Github actions instead of Jenkins-19
princegupta1131 Jun 10, 2024
983a73f
ED-4000 feat: Github actions instead of Jenkins-20
princegupta1131 Jun 10, 2024
ec53844
ED-4000 feat: Github actions instead of Jenkins-21
princegupta1131 Jun 10, 2024
8c30041
ED-4000 feat: Github actions instead of Jenkins-21
princegupta1131 Jun 10, 2024
2e8edb0
ED-4000 feat: Github actions instead of Jenkins-21
princegupta1131 Jun 10, 2024
8eae711
ED-4000 feat: Github actions instead of Jenkins-21
princegupta1131 Jun 10, 2024
7e5fdb7
ED-4000 feat: Github actions instead of Jenkins-21
princegupta1131 Jun 10, 2024
7d0f87b
ED-4000 feat: Github actions instead of Jenkins-22
princegupta1131 Jun 10, 2024
126922b
ED-4000 feat: Github actions instead of Jenkins-23
princegupta1131 Jun 10, 2024
69e88be
ED-4000 feat: Github actions instead of Jenkins-24
princegupta1131 Jun 11, 2024
9c0e335
ED-4000 feat: Github actions instead of Jenkins-24
princegupta1131 Jun 11, 2024
c45ff9a
ED-4000 feat: Github actions instead of Jenkins-24
princegupta1131 Jun 11, 2024
5e8bd55
ED-4000 feat: Github actions instead of Jenkins-24
princegupta1131 Jun 11, 2024
821f06b
ED-4000 feat: Github actions instead of Jenkins-24
princegupta1131 Jun 11, 2024
4b7f553
ED-4000 feat: Github actions instead of Jenkins-24
princegupta1131 Jun 11, 2024
3477949
ED-4000 feat: Github actions instead of Jenkins-24
princegupta1131 Jun 11, 2024
30b15d1
ED-4000 feat: Github actions instead of Jenkins-25
princegupta1131 Jun 11, 2024
4dae31e
ED-4000 feat: Github actions instead of Jenkins-25
princegupta1131 Jun 11, 2024
eca6462
ED-4000 feat: Github actions instead of Jenkins-25
princegupta1131 Jun 11, 2024
c263c1a
ED-4000 feat: Github actions instead of Jenkins-test
princegupta1131 Jun 11, 2024
91c2d05
ED-4000 feat: Github actions instead of Jenkins-test
princegupta1131 Jun 11, 2024
e53f653
ED-4000 feat: Github actions instead of Jenkins-test
princegupta1131 Jun 11, 2024
1fcfe64
ED-4000 feat: Github actions instead of Jenkins-test
princegupta1131 Jun 11, 2024
aaaa3ef
ED-4000 feat: Github actions instead of Jenkins-test
princegupta1131 Jun 11, 2024
210658a
ED-4000 feat: Github actions instead of Jenkins-test
princegupta1131 Jun 11, 2024
029f9eb
ED-4000 feat: Github actions instead of Jenkins-test
princegupta1131 Jun 11, 2024
ee29fcb
ED-4000 feat: Github actions instead of Jenkins-test
princegupta1131 Jun 11, 2024
8103d07
ED-4000 feat: Github actions instead of Jenkins-test
princegupta1131 Jun 11, 2024
3af61c5
ED-4000 feat: Github actions instead of Jenkins-script
princegupta1131 Jun 11, 2024
d9c882b
ED-4000 feat: Github actions instead of Jenkins-test
princegupta1131 Jun 11, 2024
421533b
ED-4000 feat: Github actions instead of Jenkins-test
princegupta1131 Jun 11, 2024
8fffecf
ED-4000 feat: Github actions instead of Jenkins-test
princegupta1131 Jun 12, 2024
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
56 changes: 56 additions & 0 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Build and Deploy

on:
push:
branches:
- "deploy" # Trigger on push to any branch
pull_request:
branches:
- "deploy" # Trigger on pull request to any branch

jobs:
build_and_deploy:
name: Build and Deploy Job # Define the name of the job
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2 # Checkout the repository code

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: "18.20.2" # Set up Node.js version 18

- name: Customize dependencies
if: ${{ env.WL_Customization != null }} # Conditional step execution
run: |
git clone --recurse-submodules ${WL_Customization} sunbirded-portal # Clone repository with submodules
cp -r sunbirded-portal/images/ src/app/client/src/assets # Copy images to client assets
cp -r sunbirded-portal/resourceBundles/data/ src/app/resourcebundles/ # Copy resource bundle data
env:
WL_Customization: ${{ github.event.inputs.WL_Customization }} # Set environment variable WL_Customization

- name: Build and Create Docker Image
run: |
commit_hash=$(git rev-parse --short HEAD) # Get commit hash
build_tag=$(echo "${{ github.ref }}" | rev | cut -d/ -f1 | rev)_${commit_hash}_${GITHUB_RUN_NUMBER} # Generate build tag
echo "build_tag: $build_tag" # Print build tag
bash ./build.sh "${build_tag}" "${{ env.NODE_NAME }}" "test" true false "" # Run build script with parameters
env:
NODE_NAME: "18.20.2" # Set environment variable NODE_NAME

- name: Archive Artifacts
uses: actions/upload-artifact@v2
with:
name: metadata
path: metadata.json

- name: Archive CDN assets if required
if: ${{ github.event.inputs.buildCdnAssests == 'true' }} # Conditional step execution
run: |
rm -rf cdn_assets # Remove existing CDN assets directory
mkdir cdn_assets # Create CDN assets directory
cp -r src/app/dist-cdn/* cdn_assets/ # Copy CDN assets
zip -Jr cdn_assets.zip cdn_assets # Create zip file of CDN assets
echo "##vso[task.uploadfile]cdn_assets.zip" # Upload CDN assets zip file
175 changes: 110 additions & 65 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,70 +23,65 @@ jobs:
with:
node-version: 18

# Install client dependencies
- name: Install client dependencies
working-directory: src/app/client
run: yarn install --no-progress --production=true

# Build the client
- name: Build client
working-directory: src/app/client
run: npm run build

# List all files after the build
- name: List all files after build
working-directory: src/app/client
run: find . -type f

# Check if the dist directory exists and list its contents
- name: Check if dist directory exists and list contents
working-directory: src/app/client
run: |
if [ -d dist ]; then
echo "dist directory exists. Listing contents:"
ls -l dist
else
echo "dist directory does not exist"
fi

# Move index.html to index.ejs if it exists
- name: Move index.html to index.ejs if it exists
working-directory: src/app/client
run: |
if [ -f dist/index.html ]; then
mv dist/index.html dist/index.ejs
else
echo "File dist/index.html does not exist"
fi

# Set up server directories
- name: Set up server directories
run: mkdir -p $GITHUB_WORKSPACE/app_dist

# Copy server files to the destination directory
- name: Copy server files
run: |
cp -r src/app/libs src/app/helpers src/app/proxy src/app/resourcebundles src/app/package.json src/app/framework.config.js src/app/sunbird-plugins src/app/routes src/app/constants src/app/controllers src/app/server.js $GITHUB_WORKSPACE/app_dist/
shell: /usr/bin/bash -e {0}

# Install server dependencies
- name: Install server dependencies
working-directory: ${{ github.workspace }}/app_dist
run: yarn install --ignore-engines --no-progress --production=true

# Run server build script
- name: Run server build script
working-directory: ${{ github.workspace }}/app_dist
run: node helpers/resourceBundles/build.js -task="phraseAppPull"
# # Install client dependencies
# - name: Install client dependencies
# working-directory: src/app/client
# run: yarn install --no-progress --production=true
# # Build the client
# - name: Build client
# working-directory: src/app/client
# run: npm run build
# # List all files after the build
# - name: List all files after build
# working-directory: src/app/client
# run: find . -type f
# # Check if the dist directory exists and list its contents
# - name: Check if dist directory exists and list contents
# working-directory: src/app/client
# run: |
# if [ -d dist ]; then
# echo "dist directory exists. Listing contents:"
# ls -l dist
# else
# echo "dist directory does not exist"
# fi
# # Move index.html to index.ejs if it exists
# - name: Move index.html to index.ejs if it exists
# working-directory: src/app/client
# run: |
# if [ -f dist/index.html ]; then
# mv dist/index.html dist/index.ejs
# else
# echo "File dist/index.html does not exist"
# fi
# # Set up server directories
# - name: Set up server directories
# run: mkdir -p $GITHUB_WORKSPACE/app_dist
# # Copy server files to the destination directory
# - name: Copy server files
# run: |
# cp -r src/app/libs src/app/helpers src/app/proxy src/app/resourcebundles src/app/package.json src/app/framework.config.js src/app/sunbird-plugins src/app/routes src/app/constants src/app/controllers src/app/server.js $GITHUB_WORKSPACE/app_dist/
# shell: /usr/bin/bash -e {0}
# # Install server dependencies
# - name: Install server dependencies
# working-directory: ${{ github.workspace }}/app_dist
# run: yarn install --ignore-engines --no-progress --production=true
# # Run server build script
# - name: Run server build script
# working-directory: ${{ github.workspace }}/app_dist
# run: node helpers/resourceBundles/build.js -task="phraseAppPull"
# Execute test cases using JEST
- name: Execute test cases using JEST
working-directory: src/app/client
run: |
yarn config set ignore-engines true
yarn install
npm run test:ci
# - name: Execute test cases using JEST
# working-directory: src/app/client
# run: |
# yarn config set ignore-engines true
# yarn install
# npm run test:ci
# Debug: Print the masked SONAR_TOKEN
- name: Print SONAR_TOKEN
run: echo "SONAR_TOKEN=${{ secrets.SONAR_TOKEN }}PWR****123"

# Install Sonar Scanner
#Install Sonar Scanner
- name: Install Sonar Scanner
run: |
cd /tmp
Expand All @@ -95,12 +90,62 @@ jobs:
unzip sonar-scanner-cli-5.0.1.3006-linux.zip
cd -

- name: Run Sonar Scanner
# Run SonarScanner for frontend (Angular)
- name: Run SonarScanner for frontend
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
/tmp/sonar-scanner-5.0.1.3006-linux/bin/sonar-scanner \
-Dsonar.projectKey=Sunbird-Ed_SunbirdEd-portal \
-Dsonar.organization=sunbird-ed \
-Dsonar.sources=src/app/client/src \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.login=$SONAR_TOKEN

# - name: Run Sonar Scanner
# env:
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# run: |
# /tmp/sonar-scanner-5.0.1.3006-linux/bin/sonar-scanner \
# -Dsonar.projectKey=Sunbird-Ed_SunbirdEd-portal \
# -Dsonar.sources=src/app/client/src \
# -Dsonar.organization=sunbird-ed \
# -Dsonar.host.url=https://sonarcloud.io \
# -Dsonar.login=$SONAR_TOKEN

# Install SonarScanner globally using npm
# - name: Install SonarScanner
# run:
# npm install -g sonarqube-scanner

# # Check if SONAR_TOKEN is set
# - name: Check SONAR_TOKEN
# run: |
# if [ -z "${{ secrets.SONAR_TOKEN }}" ]; then
# echo "Error: SONAR_TOKEN is not set."

# else
# echo "SONAR_TOKEN is set."
# fi

# Debug: Print the masked SONAR_TOKEN
# - name: Print SONAR_TOKEN
# run: echo "SONAR_TOKEN=${{ secrets.SONAR_TOKEN }}PWR****123"
# # Ensure sonar-project.properties exists and print its content for debugging
# - name: Check sonar-project.properties
# run: |
# if [ -f sonar-project.properties ]; then
# echo "Found sonar-project.properties"
# cat sonar-project.properties
# else
# echo "sonar-project.properties not found"
# fi
# # Run SonarScanner in the specified directory
# - name: Run SonarScanner
# env:
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# run: |
# sonar-scanner \
# -Dsonar.projectKey=Sunbird-Ed_SunbirdEd-portal \
# -Dsonar.organization=sunbird-ed \
# -Dsonar.sources=src/app/client/src \
# -Dsonar.host.url=https://sonarcloud.io \
# -Dsonar.login=$SONAR_TOKEN
112 changes: 108 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,113 @@
# Dockerfile for the player setup
# Use a base image suitable for building the client and server
FROM node:18.20.2-slim AS builder

# Arguments for CDN URL and buildCdnAssets
ARG cdnUrl=""
ENV cdnUrl=${cdnUrl}
ARG buildCdnAssets=""
ENV buildCdnAssets=${buildCdnAssets}

# Set the working directory for the client build
WORKDIR /usr/src/app/client
# Install npm
RUN apt-get update && apt-get install -y npm

# Install Yarn
RUN npm install -g yarn --force

# Copy the client code into the Docker container
COPY src/app/client ./
RUN rm -rf node_modules yarn.lock
RUN yarn cache clean


# Install client dependencies
RUN yarn install --no-progress --frozen-lockfile --production=true


# Build the client
RUN npm run build

# Build the client for CDN and inject CDN fallback
# Conditional build logic for CDN assets
RUN if [ "$buildCdnAssets" = "true" ]; then \
echo "Building client CDN assets..."; \
npm run build-cdn --deploy-url $cdnUrl && \
export sunbird_portal_cdn_url=$cdnUrl && \
npm run inject-cdn-fallback && \
echo "Completed client CDN prod build."; \
else \
echo "Skipping client CDN assets build."; \
fi

# Validate and copy CDN assets if they exist
RUN if [ "$buildCdnAssets" = "true" ]; then \
echo "Validating and copying CDN assets..."; \
if [ -d "src/app/dist-cdn" ] && [ "$(ls -A src/app/dist-cdn)" ]; then \
mkdir -p /usr/src/app/cdn_assets && \
cp -r src/app/dist-cdn/* /usr/src/app/cdn_assets/ && \
echo "CDN assets copied successfully."; \
else \
echo "Directory src/app/dist-cdn does not exist or is empty. Skipping copy."; \
fi; \
else \
echo "Skipping validation and copying of CDN assets."; \
fi
# Set the working directory for server build
WORKDIR /usr/src/app

# Copy package.json and yarn.lock for server
COPY src/app/package.json src/app/yarn.lock ./app_dist/

# Copy server-related files into the app_dist directory before installing dependencies
COPY src/app/libs ./app_dist/libs
COPY src/app/helpers ./app_dist/helpers
COPY src/app/proxy ./app_dist/proxy
COPY src/app/resourcebundles ./app_dist/resourcebundles
COPY src/app/framework.config.js ./app_dist/
COPY src/app/sunbird-plugins ./app_dist/sunbird-plugins
COPY src/app/routes ./app_dist/routes
COPY src/app/constants ./app_dist/constants
COPY src/app/controllers ./app_dist/controllers
COPY src/app/server.js ./app_dist/

# Install server dependencies in the app_dist directory
WORKDIR /usr/src/app/app_dist
RUN yarn install --no-progress --frozen-lockfile --ignore-engines --production=true

# Start a new stage for the final image
FROM node:18.20.2-slim
RUN useradd -u 1001 -md /home/sunbird sunbird

# Set the commit hash as a build argument and environment variable
ARG commit_hash=""
ENV commit_hash=${commit_hash}

# Create a non-root user and group with specific UID and GID
RUN groupadd -g 1001 sunbird && \
useradd -u 1001 -g sunbird -m -d /home/sunbird sunbird

# Set the working directory and copy the built files
WORKDIR /home/sunbird
COPY --chown=sunbird . /home/sunbird/app_dist/
COPY --chown=sunbird:sunbird --from=builder /usr/src/app /home/sunbird

# Switch to the non-root user
USER sunbird

# Rename the index.html file to index.ejs
WORKDIR /home/sunbird/app_dist
RUN mv dist/index.html dist/index.ejs

# Print the commit hash
RUN echo "Commit Hash: ${commit_hash}"

# Add the build hash to package.json
RUN sed -i "/version/a\ \"buildHash\": \"${commit_hash}\"," package.json

# Run the build script to perform additional tasks (e.g., phraseAppPull)
RUN node helpers/resourceBundles/build.js -task="phraseAppPull"

# Expose the port used by the server
EXPOSE 3000
CMD ["node", "server.js", "&"]

# Start the server
CMD ["node", "server.js"]
Loading
Loading