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

Jenkins #2

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
52 changes: 52 additions & 0 deletions .github/workflows/dockerimagepush.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Build and Push Docker Image to DockerHub

on:
push:
branches:
- main

env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USER }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
REPO_NAME: "weather-app"

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Install Trivy
run: |
wget https://github.com/aquasecurity/trivy/releases/download/v0.18.3/trivy_0.18.3_Linux-64bit.deb
sudo dpkg -i trivy_0.18.3_Linux-64bit.deb
- name: Build Docker Image
run: docker build -t "${DOCKERHUB_USERNAME}/${REPO_NAME}:$GITHUB_RUN_NUMBER" .
- name: Scan container images
run: |
trivy image "${DOCKERHUB_USERNAME}/${REPO_NAME}:$GITHUB_RUN_NUMBER"
- name: Login to DockerHub
run: echo "${DOCKERHUB_TOKEN}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin
- name: Push Docker Image to DockerHub
run: docker push "${DOCKERHUB_USERNAME}/${REPO_NAME}:$GITHUB_RUN_NUMBER"


update-manifest-stage:
runs-on: ubuntu-latest
needs: ['build-and-push']
steps:
- uses: actions/checkout@v3
with:
repository: RohanRusta21/weather-app-manifests
ref: 'main'
token: ${{ secrets.G_TOKEN }}
- name: setup git config
run: |
git config --global user.email "[email protected]"
git config --global user.name "RohanRusta21"
echo ${{ github.sha }}
sed -i "s#${DOCKERHUB_USERNAME}.*#${DOCKERHUB_USERNAME}/${REPO_NAME}:$GITHUB_RUN_NUMBER#g" deployment.yml
git add -A
git commit -am "Update image for Version - $GITHUB_RUN_NUMBER"
- run: echo ${{ github }}
- run: git push origin main
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Stage 1: Build the application
FROM node:16
LABEL maintainer="Rohan Rustagi"
WORKDIR /app
COPY package-lock.json ./
COPY package.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD [ "npm", "start" ]
41 changes: 41 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
pipeline {
agent any
environment{
registry = "wededo4644/react_weather_app"
}

stages {
stage('Github Checkout') {
steps {
git branch: 'main', url: 'https://github.com/RohanRusta21/Weather-App.git'
}
}
stage('Building image') {
steps{
script {
docker.build("${registry}")
}
}
}
stage('Pushing image') {
steps{
script {
withCredentials([string(credentialsId: 'dockerhubpass', variable: 'dockerhubpwd')]) {
sh 'docker login -u wededo4644 -p ${dockerhubpwd}'
sh 'docker push ${registry}'

}
}
}
}
stage('Deploy To EKS Cluster'){
steps{

withKubeConfig(caCertificate: '', clusterName: '', contextName: '', credentialsId: 'k8s', namespace: '', restrictKubeConfigAccess: false, serverUrl: '') {
sh "kubectl apply -f deployment.yml"
sh "kubectl apply -f service.yml"
}
}
}
}
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app)

## Available Scripts

Expand Down Expand Up @@ -31,7 +31,7 @@ See the section about [deployment](https://facebook.github.io/create-react-app/d

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can't go back!**
**Note: this is a one-way operation. Once you `eject`, you can't go back**

If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Expand Down Expand Up @@ -65,6 +65,6 @@ This section has moved here: [https://facebook.github.io/create-react-app/docs/a

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `npm run build` fails to minify
### `npm run build` fails to minify.

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
21 changes: 21 additions & 0 deletions manifests/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: weather-app
spec:
replicas: 2
selector:
matchLabels:
app: weather-app
template:
metadata:
labels:
app: weather-app
spec:
containers:
- name: weather-app
image: wededo4644/react_weather_app:latest
imagePullPolicy: Always
ports:
- containerPort: 3000

13 changes: 13 additions & 0 deletions manifests/service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: weather-app
spec:
type: LoadBalancer
selector:
app: weather-app
ports:
- port: 80
protocol: TCP
targetPort: 3000
nodePort: 31000
Loading