mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 06:45:50 +00:00
added pipeline and dockerfile
This commit is contained in:
parent
aa2273e955
commit
a86e3a6ca3
3 changed files with 142 additions and 0 deletions
14
Dockerfile
Normal file
14
Dockerfile
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
FROM maven:3.9-eclipse-temurin-17 AS builder
|
||||||
|
COPY . /spc
|
||||||
|
WORKDIR /spc
|
||||||
|
RUN mvn package
|
||||||
|
|
||||||
|
FROM eclipse-temurin:17-alpine
|
||||||
|
LABEL org="spc build" author="venkat"
|
||||||
|
ARG USERNAME=spc
|
||||||
|
RUN apk add --no-cache bash
|
||||||
|
RUN adduser -D -h /apps -s /bin/bash/ ${USERNAME}
|
||||||
|
USER ${USERNAME}
|
||||||
|
COPY --from=builder --chown={USERNAME}:{USERNAME} /spc/target/spring-petclinic-3.4.0-SNAPSHOT.jar /apps/spring-petclinic-3.4.0-SNAPSHOT.jar
|
||||||
|
WORKDIR /apps
|
||||||
|
EXPOSE 8080
|
40
azure-pipelines.yml
Normal file
40
azure-pipelines.yml
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
pool: Default
|
||||||
|
|
||||||
|
pr:
|
||||||
|
- develop
|
||||||
|
|
||||||
|
stages:
|
||||||
|
- stage: CI
|
||||||
|
jobs:
|
||||||
|
- job: Build
|
||||||
|
displayName: 'Building and Testing'
|
||||||
|
steps:
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- task: Maven@4
|
||||||
|
displayName: 'build and publish the maven code'
|
||||||
|
inputs:
|
||||||
|
mavenPomFile: pom.xml
|
||||||
|
goals: 'clean package'
|
||||||
|
testResultsFiles: '**/surefire-reports/TEST-*.xml'
|
||||||
|
publishJUnitResults: true
|
||||||
|
|
||||||
|
- task: CopyFiles@2
|
||||||
|
inputs:
|
||||||
|
contents: '**/*.jar'
|
||||||
|
targetFolder: '$(Build.ArtifactStagingDirectory)'
|
||||||
|
|
||||||
|
- task: PublishBuildArtifacts@1
|
||||||
|
inputs:
|
||||||
|
pathToPublish: '$(Build.ArtifactStagingDirectory)'
|
||||||
|
artifactName: drop
|
||||||
|
|
||||||
|
- task: Docker@2
|
||||||
|
displayName: 'Build docker image'
|
||||||
|
inputs:
|
||||||
|
command: 'buildAndPush'
|
||||||
|
Dockerfile: './Dockerfile'
|
||||||
|
repository: venkeyboda/spring-petclinic
|
||||||
|
tags: '$(Build.BuildId)'
|
||||||
|
|
||||||
|
|
88
setup.md
Normal file
88
setup.md
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
# Steps
|
||||||
|
|
||||||
|
### DEVELOP BRANCH PULL BASED
|
||||||
|
-----------------------------
|
||||||
|
* Java-based Spring Petclinic application
|
||||||
|
* Pull request-based development
|
||||||
|
* Create a multi-stage Dockerfile for the Spring Petclinic application on the `develop` branch
|
||||||
|
* Execute Dockerfile Using Command
|
||||||
|
```bash
|
||||||
|
# Create image command
|
||||||
|
docker image build -t spc:1.0 .
|
||||||
|
docker image build -t <your image:tag> (dockerfile name)
|
||||||
|
# Check if the image was created
|
||||||
|
docker image ls
|
||||||
|
# Check if your image is running in a container (for verification purposes)
|
||||||
|
docker container run -P -d --name mytest spc:1.0
|
||||||
|
docker container run -P -d --name <container name> <your image:tag>
|
||||||
|
# Check if the container is running (to verify container status)
|
||||||
|
docker container ls
|
||||||
|
```
|
||||||
|
* Image Scanning with Trivy
|
||||||
|
* Now, to scan your image with Trivy, follow these steps:
|
||||||
|
* First, install Trivy on your VM or EC2 instance.
|
||||||
|
```bash
|
||||||
|
sudo apt-get install wget apt-transport-https gnupg lsb-release
|
||||||
|
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null
|
||||||
|
echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" | sudo tee -a /etc/apt/sources.list.d/trivy.list
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install trivy -y
|
||||||
|
```
|
||||||
|
### After Trivy is installed, scan your image using the following command:
|
||||||
|
```bash
|
||||||
|
trivy image spc:1.0
|
||||||
|
trivy image <image:tag>
|
||||||
|
```
|
||||||
|
#############################################################################################################################################################################
|
||||||
|
|
||||||
|
### RELEASE BRANCH PUSH BASED
|
||||||
|
-----------------------------
|
||||||
|
* Push Based `Release`
|
||||||
|
* Multiple developers have made changes, so we will scan the Docker image again.
|
||||||
|
* On the release branch, scan the Docker image with Trivy.
|
||||||
|
### After Trivy is installed, use the following command:
|
||||||
|
```bash
|
||||||
|
trivy image spc:1.0
|
||||||
|
trivy image <image:tag>
|
||||||
|
```
|
||||||
|
* The output will show vulnerabilities or reports.
|
||||||
|
* Pushing the Image to a Registry
|
||||||
|
* Once the image scan is completed, we can push the image to a registry such as Docker Hub, ECR, or ACR.
|
||||||
|
### To push to Docker Hub, follow these steps:
|
||||||
|
```bash
|
||||||
|
docker login
|
||||||
|
docker image tag <docke image> <repousename>/<reponame>:<tag>
|
||||||
|
docker image tag spc:1.0 longflew/javaimagecicd:1.0
|
||||||
|
docker image push longflew/javaimagecicd:1.0
|
||||||
|
```
|
||||||
|
##### Note: Ensure k8s Cluster(AKS or EKS) will be created
|
||||||
|
### Installing helm
|
||||||
|
* [Refer Here](https://helm.sh/docs/intro/install/) for installing Helm
|
||||||
|
* Once installation completed run the following commands
|
||||||
|
* To Create a new helm chart repo
|
||||||
|
`helm create <your chat>`
|
||||||
|
`helm create spc-chart`
|
||||||
|
* Deploy the application in k8s using helm , the command will be
|
||||||
|
`helm install <release name> <chart name>`
|
||||||
|
`helm install spc-release spc-chart`
|
||||||
|
* Check the appliocation running or not using the k8s commands
|
||||||
|
```bash
|
||||||
|
kubectl get po
|
||||||
|
kubectl get svc
|
||||||
|
```
|
||||||
|
* Take the IP or DNS of the service and open new Browser and paste the IP or DNS.
|
||||||
|
|
||||||
|
### Upgrade docker image in helm
|
||||||
|
* Whenever we upgrade the Docker image in Helm, the deployment manifest file is also automatically updated with the new image
|
||||||
|
* After making further changes, we updated the values.yaml file to modify the image tag.
|
||||||
|
* use the following command:
|
||||||
|
```bash
|
||||||
|
# docker image upgrade
|
||||||
|
helm upgrade spc-release spc-chart -f values.yaml --set image.tag=new-image-tag
|
||||||
|
|
||||||
|
# Verify the Upgrade
|
||||||
|
helm get all <release name>
|
||||||
|
helm get all spc-release
|
||||||
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue