diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml deleted file mode 100644 index 0c458d82..00000000 --- a/.github/workflows/maven.yml +++ /dev/null @@ -1,72 +0,0 @@ - - -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 adijaiswal/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 adijaiswal/boardgame:latest - - - - diff --git a/Dockerfile b/Dockerfile index f7143762..1ff51337 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM adoptopenjdk/openjdk11 EXPOSE 8080 -ENV APP_HOME /usr/src/app +ENV APP_HOME /usr/src/app COPY target/*.jar $APP_HOME/app.jar diff --git a/appspec.yml b/appspec.yml new file mode 100644 index 00000000..2bb47536 --- /dev/null +++ b/appspec.yml @@ -0,0 +1,21 @@ +version: 0.0 +os: linux +files: + - source: target/database_service_project-0.0.4.jar + destination: /opt/database_service_project + overwrite: true + +hooks: + BeforeInstall: + - location: scripts/install_depen.sh + timeout: 300 + runas: root + + ApplicationStop: + - location: scripts/stop_server.sh + timeout: 300 + runas: root + ApplicationStart: + - location: scripts/start_server.sh + timeout: 300 + runas: root diff --git a/buildspec.yml b/buildspec.yml new file mode 100644 index 00000000..a9fb47a5 --- /dev/null +++ b/buildspec.yml @@ -0,0 +1,21 @@ +version: 0.2 + +phases: + install: + runtime-versions: + java: corretto17 + nodejs: 18 + build: + commands: + - echo "Hello World" + - mvn clean install + post_build: + commands: + - mvn test + - mvn package +artifacts: + files: + - target/database_service_project-0.0.4.jar + - appspec.yml + - scripts/* + discard-paths: no diff --git a/deployment-service.yaml b/deployment-service.yaml index c735026a..f021ebb7 100644 --- a/deployment-service.yaml +++ b/deployment-service.yaml @@ -1,12 +1,12 @@ apiVersion: apps/v1 -kind: Deployment # Kubernetes resource kind we are creating +kind: Deployment metadata: name: boardgame-deployment spec: selector: matchLabels: app: boardgame - replicas: 2 # Number of replicas that will be created for this deployment + replicas: 2 template: metadata: labels: @@ -14,17 +14,15 @@ spec: spec: containers: - name: boardgame - image: adijaiswal/boardshack:latest # Image that will be used to containers in the cluster + image: adijaiswal/boardshack:latest imagePullPolicy: Always ports: - - containerPort: 8080 # The port that the container is running on in the cluster - + - containerPort: 8080 --- - -apiVersion: v1 # Kubernetes API version -kind: Service # Kubernetes resource kind we are creating -metadata: # Metadata of the resource kind we are creating +apiVersion: v1 +kind: Service +metadata: name: boardgame-ssvc spec: selector: @@ -32,5 +30,5 @@ spec: ports: - protocol: "TCP" port: 80 - targetPort: 8080 - type: LoadBalancer # type of the service. + targetPort: 8080 + type: LoadBalancer diff --git a/scripts/deploy_server.sh b/scripts/deploy_server.sh new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/scripts/deploy_server.sh @@ -0,0 +1 @@ + diff --git a/scripts/install_depen.sh b/scripts/install_depen.sh new file mode 100644 index 00000000..0afe8808 --- /dev/null +++ b/scripts/install_depen.sh @@ -0,0 +1,2 @@ +#!/bin/bash +sudo apt update -y diff --git a/scripts/start_server.sh b/scripts/start_server.sh new file mode 100644 index 00000000..cd306d82 --- /dev/null +++ b/scripts/start_server.sh @@ -0,0 +1,5 @@ +#!/bin/bash +echo "Starting Java application..." +chmod +x /opt/database_service_project/database_service_project-0.0.4.jar +nohup java -jar /opt/database_service_project/database_service_project-0.0.4.jar >/opt/database_service_project/app.log 2>&1 & +echo "Application started!" diff --git a/scripts/stop_server.sh b/scripts/stop_server.sh new file mode 100644 index 00000000..12acaf87 --- /dev/null +++ b/scripts/stop_server.sh @@ -0,0 +1,4 @@ +#!/bin/bash +echo "Stopping Java application..." +pkill -f 'java -jar' || echo "No running Java application found" +echo "Java application stopped."