Skip to content

Commit

Permalink
- enhance githubAction
Browse files Browse the repository at this point in the history
  • Loading branch information
ubaid4j committed May 29, 2024
1 parent da3ca0f commit 9b093c3
Show file tree
Hide file tree
Showing 14 changed files with 404 additions and 147 deletions.
102 changes: 102 additions & 0 deletions .github/workflows/build-and-pubilsh-post-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Test and Build post service

env:
REGISTRY: ghcr.io
IMAGE_NAME: ubaid4j/cloud-native-app-spring-boot/post-service
VERSION: latest

on:
push:
paths:
- 'post-service/**'
branches:
- social-app-project

defaults:
run:
working-directory: ./post-service

jobs:
build:
name: Build and Test
runs-on: ubuntu-24.04
permissions:
contents: read
security-events: write
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: set up JDK
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 22
cache: maven
- name: Code vulnerability scanning
uses: anchore/scan-action@v3
id: scan
with:
path: "${{ github.workspace }}/post-service"
only-fixed: true
fail-build: true
severity-cutoff: critical
- name: Upload vulnerability report
uses: github/codeql-action/upload-sarif@v3
if: success()
with:
sarif_file: ${{ steps.scan.outputs.sarif }}
- name: Build and Test
run: |
mvn -Pprod verify
- name: Setup k8s validator
uses: alexellis/arkade-get@master
with:
kubectl: latest
kubeval: latest
kustomize: latest
- name: Validate k8s files
run: |
kustomize build k8s -o k8s/k8s.yml
kubeval --schema-location https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/ --strict -d k8s/k8s.yml
rm -f k8s/k8s.yml
package:
name: Package and Publish
needs: [build]
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
security-events: write
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Setup JDK
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 22
cache: maven
- name: Build Container Image
run: |
mvn -Pprod spring-boot:build-image
- name: OCI Image vulnerability scanning
uses: anchore/scan-action@v3
id: scan
with:
image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}
fail-build: true
only-fixed: true
severity-cutoff: critical
- name: Upload vulnerability report
uses: github/codeql-action/upload-sarif@v3
if: success()
with:
sarif_file: ${{ steps.scan.outputs.sarif }}
- name: Login to container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Publish container image
run: docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}
8 changes: 4 additions & 4 deletions .github/workflows/build-and-pubish-api-gateway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defaults:
jobs:
build:
name: Build and Test
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
permissions:
contents: read
security-events: write
Expand All @@ -30,7 +30,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 21
java-version: 22
cache: maven
- name: Code vulnerability scanning
uses: anchore/scan-action@v3
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
package:
name: Package and Publish
needs: [build]
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
Expand All @@ -74,7 +74,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 21
java-version: 22
cache: maven
- name: Build Container Image
run: |
Expand Down
4 changes: 4 additions & 0 deletions api-gateway/.sdkmanrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Enable auto-env through the sdkman_auto_env config
# Add key=value pairs of SDKs to use below
java=22.0.1-tem
maven=4.0.0-beta-3
25 changes: 14 additions & 11 deletions api-gateway/src/main/webapp/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {AppComponent} from './app.component';
import {PostService} from "./posts/post.service";

describe('AppComponent', () => {
let component: AppComponent;
let fixture: ComponentFixture<AppComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
AppComponent
]
}).compileComponents();
await TestBed.configureTestingModule({
imports: [
AppComponent
],
})
.overrideTemplate(AppComponent, '')
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(AppComponent);
component = fixture.componentInstance;
fixture.detectChanges();
})

it('should create the app', () => {
expect(component).toBeTruthy();
expect(component).toBeTruthy();
});

it('should have a title "The Social Platform"', () => {
expect(component.title).toEqual('The Social Platform');
expect(component.title).toEqual('The Social Platform');
});
});
23 changes: 13 additions & 10 deletions api-gateway/src/main/webapp/app/posts/post.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { TestBed } from '@angular/core/testing';
import {TestBed} from '@angular/core/testing';

import { PostService } from './post.service';
import {PostService} from './post.service';
import {HttpClientTestingModule} from "@angular/common/http/testing";

describe('PostService', () => {
let service: PostService;
let service: PostService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(PostService);
});
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule]
});
service = TestBed.inject(PostService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
33 changes: 17 additions & 16 deletions api-gateway/src/main/webapp/app/posts/post/post.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import {ComponentFixture, TestBed} from '@angular/core/testing';

import { PostComponent } from './post.component';
import {PostComponent} from './post.component';
import {HttpClientTestingModule} from "@angular/common/http/testing";

describe('PostComponent', () => {
let component: PostComponent;
let fixture: ComponentFixture<PostComponent>;
let component: PostComponent;
let fixture: ComponentFixture<PostComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [PostComponent]
})
.compileComponents();
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [PostComponent, HttpClientTestingModule]
})
.compileComponents();

fixture = TestBed.createComponent(PostComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(PostComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
37 changes: 20 additions & 17 deletions api-gateway/src/main/webapp/app/posts/posts.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import {ComponentFixture, TestBed} from '@angular/core/testing';

import { PostsComponent } from './posts.component';
import {PostsComponent} from './posts.component';
import {PostService} from "./post.service";
import {HttpClientTestingModule} from "@angular/common/http/testing";

describe('PostsComponent', () => {
let component: PostsComponent;
let fixture: ComponentFixture<PostsComponent>;
let component: PostsComponent;
let fixture: ComponentFixture<PostsComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [PostsComponent]
})
.compileComponents();

fixture = TestBed.createComponent(PostsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [PostsComponent, HttpClientTestingModule],
})
.overrideTemplate(PostsComponent, '')
.compileComponents();

it('should create', () => {
expect(component).toBeTruthy();
});
fixture = TestBed.createComponent(PostsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
4 changes: 4 additions & 0 deletions post-service/.sdkmanrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Enable auto-env through the sdkman_auto_env config
# Add key=value pairs of SDKs to use below
java=22.0.1-tem
maven=4.0.0-beta-3
2 changes: 2 additions & 0 deletions post-service/k8s/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
server:
port: 80
40 changes: 40 additions & 0 deletions post-service/k8s/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: post-service
labels:
app: post-service
spec:
replicas: 1
selector:
matchLabels:
app: post-service
template:
metadata:
labels:
app: post-service
spec:
containers:
- name: post-service
image: ghcr.io/ubaid4j/cloud-native-app-spring-boot/post-service:latest
imagePullPolicy: IfNotPresent
env:
- name: SPRING_PROFILES_ACTIVE
value: prod
ports:
- containerPort: 80
livenessProbe:
httpGet:
path: /management/health/liveness
port: 80
readinessProbe:
httpGet:
path: /management/health/readiness
port: 80
volumeMounts:
- mountPath: /workspace/config
name: post-service-config-volume
volumes:
- name: post-service-config-volume
configMap:
name: post-service-config
15 changes: 15 additions & 0 deletions post-service/k8s/kustomization.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- deployment.yml
- ingress.yml
- service.yml

configMapGenerator:
- name: post-service-config
files:
- application.yml
options:
labels:
config: post-service
14 changes: 14 additions & 0 deletions post-service/k8s/service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: post-service
labels:
service: post-service
spec:
type: ClusterIP
selector:
app: post-service
ports:
- port: 80
protocol: TCP
targetPort: 80
Loading

0 comments on commit 9b093c3

Please sign in to comment.