From df30650e62b0b6c827a75ab3c0f7e7ade4c8add1 Mon Sep 17 00:00:00 2001 From: rohitdevops05112024 Date: Thu, 14 Nov 2024 13:05:41 +0530 Subject: [PATCH 1/5] Create Jenkinsfile --- Jenkinsfile | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..2a6d00e --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,93 @@ +pipeline { + agent any + + environment { + GO_VERSION = '1.18' // Set the Go version if needed + GOPATH = '/go' // Define Go workspace path + } + + stages { + stage('Checkout') { + steps { + // Checkout the code from GitHub + git branch: 'rohit_test', url: 'https://github.com/rohitdevops05112024/OT-Microservices.git' + } + } + + stage('Install Dependencies') { + steps { + script { + // Install Go dependencies using `go mod` + sh 'go mod tidy' + } + } + } + + stage('Build') { + steps { + script { + // Build the Go application + sh 'go build -o employee-app ./employee' + } + } + } + + stage('Run Tests') { + steps { + script { + // Run Go tests + sh 'go test -v ./employee' + } + } + } + + stage('Build Docker Image') { + when { + branch 'rohit_test' // Only build Docker image on this branch + } + steps { + script { + // Build the Docker image + sh 'docker build -t rohit/employee-app ./employee' + } + } + } + + stage('Publish Docker Image') { + when { + branch 'rohit_test' // Only push Docker image to the registry on this branch + } + steps { + script { + // Publish the Docker image to Docker Hub or your private registry + sh 'docker push rohit/employee-app' + } + } + } + + stage('Clean Up') { + steps { + script { + // Remove the built binaries and Docker images to keep the workspace clean + sh 'rm -rf employee-app' + sh 'docker rmi rohit/employee-app' + } + } + } + } + + post { + always { + // Actions to be taken after the pipeline execution + cleanWs() // Clean up the workspace + } + success { + // Actions to take on success + echo 'Pipeline completed successfully.' + } + failure { + // Actions to take on failure + echo 'Pipeline failed.' + } + } +} From f08b8a2d79e1aa748180da2148878d0951e9590f Mon Sep 17 00:00:00 2001 From: rohitdevops05112024 Date: Thu, 14 Nov 2024 13:11:54 +0530 Subject: [PATCH 2/5] Update Jenkinsfile --- Jenkinsfile | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2a6d00e..cee4048 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,16 +1,20 @@ pipeline { - agent any - + agent { + docker { image 'golang:1.18' } // Use the official Golang Docker image + } environment { GO_VERSION = '1.18' // Set the Go version if needed GOPATH = '/go' // Define Go workspace path + DOCKER_IMAGE = 'rohit/employee-app' // Docker image name (you can update this) + DOCKER_REGISTRY = 'docker.io' // Docker registry, e.g., Docker Hub (can be a private registry too) + GITHUB_REPO = 'https://github.com/rohitdevops05112024/OT-Microservices.git' // GitHub repo URL + BRANCH = 'rohit_test' // Branch to checkout } - stages { stage('Checkout') { steps { - // Checkout the code from GitHub - git branch: 'rohit_test', url: 'https://github.com/rohitdevops05112024/OT-Microservices.git' + // Checkout the code from GitHub repository + git branch: "${BRANCH}", url: "${GITHUB_REPO}" } } @@ -42,25 +46,19 @@ pipeline { } stage('Build Docker Image') { - when { - branch 'rohit_test' // Only build Docker image on this branch - } steps { script { - // Build the Docker image - sh 'docker build -t rohit/employee-app ./employee' + // Build the Docker image using the Dockerfile located in the employee directory + sh 'docker build -t ${DOCKER_IMAGE} ./employee' } } } stage('Publish Docker Image') { - when { - branch 'rohit_test' // Only push Docker image to the registry on this branch - } steps { script { - // Publish the Docker image to Docker Hub or your private registry - sh 'docker push rohit/employee-app' + // Push the Docker image to the specified Docker registry (e.g., Docker Hub) + sh 'docker push ${DOCKER_IMAGE}' } } } @@ -68,17 +66,16 @@ pipeline { stage('Clean Up') { steps { script { - // Remove the built binaries and Docker images to keep the workspace clean + // Clean up generated binaries and Docker images sh 'rm -rf employee-app' - sh 'docker rmi rohit/employee-app' + sh 'docker rmi ${DOCKER_IMAGE}' } } } } - post { always { - // Actions to be taken after the pipeline execution + // Actions to be taken after the pipeline execution, such as cleaning the workspace cleanWs() // Clean up the workspace } success { From 62b0e19d1933f5e6f462b5705d5a4f9d3744973f Mon Sep 17 00:00:00 2001 From: root Date: Wed, 20 Nov 2024 20:58:53 +0530 Subject: [PATCH 3/5] Add GitHub Actions workflow for Python CI --- attendance/.github/workflows/python-ci.yml | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 attendance/.github/workflows/python-ci.yml diff --git a/attendance/.github/workflows/python-ci.yml b/attendance/.github/workflows/python-ci.yml new file mode 100644 index 0000000..8dd9c10 --- /dev/null +++ b/attendance/.github/workflows/python-ci.yml @@ -0,0 +1,36 @@ +name: Python CI Workflow + +on: + push: + branches: + - rohit_test + pull_request: + branches: + - rohit_test + +jobs: + build-and-test: + runs-on: ubuntu-latest + + steps: + # Step 1: Check out the code + - name: Checkout code + uses: actions/checkout@v3 + + # Step 2: Set up Python + - name: Set up Python 3.10 + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + # Step 3: Install dependencies + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + # Step 4: Run tests + - name: Run tests with pytest + run: | + pytest + From 24b623c3b39315348b42682e530ebe1ede76a5f0 Mon Sep 17 00:00:00 2001 From: rohitdevops05112024 Date: Wed, 20 Nov 2024 21:01:09 +0530 Subject: [PATCH 4/5] Update Dockerfile From 9b57a0cfac2f0cbedcb65e640f75a0d1dfd1d952 Mon Sep 17 00:00:00 2001 From: rohitdevops05112024 Date: Wed, 20 Nov 2024 21:04:38 +0530 Subject: [PATCH 5/5] Update python-ci.yml