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

Add Docker Support #4

Merged
merged 5 commits into from
Aug 8, 2024
Merged
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
68 changes: 68 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@


name: Java CI with Maven

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: self-hosted

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml

- name: Trivy FS scan
run: |
trivy fs --format table -o fs.html .

- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

- name: SonarQube Quality Gate check
id: sonarqube-quality-gate-check
uses: sonarsource/sonarqube-quality-gate-action@master
# Force to fail step after specific time.
timeout-minutes: 5
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Docker Image
run: |
docker build -t adijaiswal/boardgame:latest .

- name: Trivy Image Scan
run: |
trivy image --format table -o trivy-image-report.html asr2003/board:latest

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Push Docker Image
run: |
docker push asr2003/boardgame:latest
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM adoptopenjdk/openjdk11

EXPOSE 3000

ENV APP_HOME /usr/src/app

COPY target/*.jar $APP_HOME/app.jar

WORKDIR $APP_HOME

CMD ["java", "-jar", "app.jar"]
27 changes: 27 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
pipeline {
agent any
tools {
jdk 'jdk17'
maven 'maven3'
}

stages {
stage('Compile') {
steps {
sh 'mvn compile'
}
}

stage('Test') {
steps {
sh 'mvn test'
}
}

stage('Build') {
steps {
sh 'mvn package'
}
}
}
}
28 changes: 28 additions & 0 deletions Jenkinsfile123
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
pipeline {
agent {label 'slave-1'}

tools {
jdk 'jdk17'
maven 'maven3'
}

stages {
stage('Compile') {
steps {
sh 'mvn compile'
}
}

stage('Test') {
steps {
sh 'mvn test'
}
}

stage('Build') {
steps {
sh 'mvn package'
}
}
}
}
34 changes: 34 additions & 0 deletions deployment-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: boardgame-deployment
spec:
selector:
matchLabels:
app: boardgame
replicas: 2
template:
metadata:
labels:
app: boardgame
spec:
containers:
- name: boardgame
image: adijaiswal/boardshack:latest
imagePullPolicy: Always
ports:
- containerPort: 3000
---

apiVersion: v1
kind: Service
metadata:
name: boardgame-ssvc
spec:
selector:
app: boardgame
ports:
- protocol: "TCP"
port: 3000
targetPort: 3000
type: LoadBalancer
Loading
Loading