|
| 1 | +pipeline { |
| 2 | + agent none |
| 3 | + |
| 4 | + environment { |
| 5 | + DOCKERHUB_CREDENTIALS_ID = 'dockerhub-credentials' |
| 6 | + DOCKERHUB_USERNAME = 'your-dockerhub-username' // It is recommended to set this from Jenkins credentials |
| 7 | + } |
| 8 | + |
| 9 | + stages { |
| 10 | + stage('Lint Frontend') { |
| 11 | + agent { |
| 12 | + docker { |
| 13 | + image 'node:20-slim' |
| 14 | + } |
| 15 | + } |
| 16 | + steps { |
| 17 | + dir('frontend') { |
| 18 | + sh 'npm install' |
| 19 | + sh 'npm run lint' |
| 20 | + } |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | + stage('Build Images') { |
| 25 | + agent any |
| 26 | + steps { |
| 27 | + script { |
| 28 | + docker.build("${env.DOCKERHUB_USERNAME}/frontend:latest", "-f frontend/Dockerfile.prod frontend") |
| 29 | + docker.build("${env.DOCKERHUB_USERNAME}/backend:latest", "-f backend/Dockerfile.prod backend") |
| 30 | + docker.build("${env.DOCKERHUB_USERNAME}/service:latest", "-f service/Dockerfile.prod service") |
| 31 | + } |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + stage('Push Images to Docker Hub') { |
| 36 | + agent any |
| 37 | + steps { |
| 38 | + echo 'Pushing images to Docker Hub...' |
| 39 | + withCredentials([usernamePassword(credentialsId: env.DOCKERHUB_CREDENTIALS_ID, usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) { |
| 40 | + sh "docker login -u ${DOCKER_USERNAME} -p ${DOCKER_PASSWORD}" |
| 41 | + sh "docker push ${env.DOCKERHUB_USERNAME}/frontend:latest" |
| 42 | + sh "docker push ${env.DOCKERHUB_USERNAME}/backend:latest" |
| 43 | + sh "docker push ${env.DOCKERHUB_USERNAME}/service:latest" |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + stage('Deploy Frontend to Netlify') { |
| 49 | + agent { |
| 50 | + docker { |
| 51 | + image 'node:20-slim' |
| 52 | + } |
| 53 | + } |
| 54 | + steps { |
| 55 | + dir('frontend') { |
| 56 | + sh 'npm install' |
| 57 | + sh 'npm run build' |
| 58 | + // Assumes NETLIFY_AUTH_TOKEN and NETLIFY_SITE_ID are configured in Jenkins |
| 59 | + // sh 'npm install -g netlify-cli' |
| 60 | + // sh 'netlify deploy --prod --dir=dist' |
| 61 | + echo 'Deploying to Netlify...' |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + stage('Deploy Backend to AWS Lambda') { |
| 67 | + agent any // Or an agent with AWS CLI and necessary tools |
| 68 | + steps { |
| 69 | + echo 'Deploying backend to AWS Lambda...' |
| 70 | + // This is a placeholder. A real deployment would be more complex. |
| 71 | + // You might use Serverless Framework, AWS SAM, or a custom script. |
| 72 | + // Example with a custom script: |
| 73 | + // dir('backend') { |
| 74 | + // sh './deploy-to-lambda.sh' |
| 75 | + // } |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + stage('Deploy Service') { |
| 80 | + agent any |
| 81 | + steps { |
| 82 | + echo 'Deploying the service...' |
| 83 | + // The service appears to be a background worker. |
| 84 | + // You could deploy this to a container service like AWS Fargate or a small VM. |
| 85 | + // Example for AWS Fargate: |
| 86 | + // sh 'aws ecs update-service --cluster your-cluster --service your-service --force-new-deployment' |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | +} |
0 commit comments