Skip to content

Added jenkins file #17046

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

Closed
wants to merge 12 commits into from
Closed
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
44 changes: 44 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Stage 1: Build React App
FROM node:18-alpine AS build

# Set working directory
WORKDIR /app

# Copy only package files for layer caching
COPY package*.json ./

# Optional: clean npm cache
RUN npm cache clean --force

# Install specific versions to avoid breaking changes
RUN npm install ajv@6 ajv-keywords@3 --legacy-peer-deps

# Skip postinstall scripts (which cause workspace errors)
ENV NPM_CONFIG_IGNORE_SCRIPTS=true

# Install dependencies with legacy peer deps
RUN npm install --legacy-peer-deps || true

# Copy rest of the app
COPY . .

# Build the React app
RUN npm run build

# Stage 2: Serve with Nginx
FROM nginx:alpine

# Remove default nginx files
RUN rm -rf /usr/share/nginx/html/*

# Copy build output from previous stage
COPY --from=build /app/build /usr/share/nginx/html

# Optional: copy custom nginx config
# COPY nginx.conf /etc/nginx/nginx.conf

# Expose port 80
EXPOSE 80

# Start Nginx
CMD ["nginx", "-g", "daemon off;"]
34 changes: 34 additions & 0 deletions jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
pipeline {
agent any

stages {
stage('Clone Repository') {
steps {
git branch: 'main', url: 'https://github.com/Rachana-js/create-react-app.git'
}
}

stage('Build Docker Image') {
steps {
sh 'docker build -t rachanajs/react-app .'
}
}

stage('Push to Docker Hub') {
steps {
withDockerRegistry([credentialsId: 'docker-hub-credentials', url: '']) {
sh 'docker push rachanajs/react-app'
}
}
}

stage('Deploy with Docker') {
steps {
sh '''
docker ps -q --filter "ancestor=rachanajs/react-app" | xargs -r docker stop
docker run -d -p 3000:3000 rachanajs/react-app
'''
}
}
}
}
Loading