Skip to content
Open
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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.iml
*.ipr
*.iws
.gradle/**
.idea/**
build/**


49 changes: 49 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM eclipse-temurin:19@sha256:f3fbf1ad599d4b5dbdd7ceb55708d10cb9fafb08e094ef91e92aa63b520a232e as builder

WORKDIR /app

COPY ["build.gradle", "gradlew", "./"]
COPY gradle gradle
RUN chmod +x gradlew
RUN ./gradlew downloadRepos

COPY . .
RUN chmod +x gradlew
RUN ./gradlew installDist

FROM eclipse-temurin:19.0.1_10-jre-alpine@sha256:a75ea64f676041562cd7d3a54a9764bbfb357b2bf1bebf46e2af73e62d32e36c as without-grpc-health-probe-bin

RUN apk add --no-cache ca-certificates

# Download Stackdriver Profiler Java agent
RUN mkdir -p /opt/cprof && \
wget -q -O- https://storage.googleapis.com/cloud-profiler/java/latest/profiler_java_agent_alpine.tar.gz \
| tar xzv -C /opt/cprof && \
rm -rf profiler_java_agent.tar.gz

WORKDIR /app
COPY --from=builder /app .

EXPOSE 9555
ENTRYPOINT ["/app/build/install/hipstershop/bin/AdService"]

FROM without-grpc-health-probe-bin

# renovate: datasource=github-releases depName=grpc-ecosystem/grpc-health-probe
ENV GRPC_HEALTH_PROBE_VERSION=v0.4.18
RUN wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \
chmod +x /bin/grpc_health_probe
19 changes: 12 additions & 7 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
pipeline {

agent any

stages {
stage('Deploy To Kubernetes') {
stage('Build & Tag Docker Image') {
steps {
withKubeCredentials(kubectlCredentials: [[caCertificate: '', clusterName: 'EKS-1', contextName: '', credentialsId: 'k8-token', namespace: 'webapps', serverUrl: 'https://9F39F577334FF23706994135261985F2.gr7.ap-south-1.eks.amazonaws.com']]) {
sh "kubectl apply -f deployment-service.yml"

script {
withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') {
sh "docker build -t adelekegbolahan/adservice:latest ."
}
}
}
}

stage('verify Deployment') {
stage('Push Docker Image') {
steps {
withKubeCredentials(kubectlCredentials: [[caCertificate: '', clusterName: 'EKS-1', contextName: '', credentialsId: 'k8-token', namespace: 'webapps', serverUrl: 'https://9F39F577334FF23706994135261985F2.gr7.ap-south-1.eks.amazonaws.com']]) {
sh "kubectl get svc -n webapps"
script {
withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') {
sh "docker push adelekegbolahan/adservice:latest "
}
}
}
}
}
}
#
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Ad Service

The Ad service provides advertisement based on context keys. If no context keys are provided then it returns random ads.

## Building locally

The Ad service uses gradlew to compile/install/distribute. Gradle wrapper is already part of the source code. To build Ad Service, run:

```
./gradlew installDist
```
It will create executable script src/adservice/build/install/hipstershop/bin/AdService

### Upgrading gradle version
If you need to upgrade the version of gradle then run

```
./gradlew wrapper --gradle-version <new-version>
```

## Building docker image

From `src/adservice/`, run:

```
docker build ./
```

117 changes: 117 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
plugins {
id 'com.google.protobuf' version '0.9.3'
id 'com.github.sherter.google-java-format' version '0.9'
id 'idea'
id 'application'
}

repositories {
mavenCentral()
mavenLocal()
}

description = 'Ad Service'
group = "adservice"
version = "0.1.0-SNAPSHOT"

def grpcVersion = "1.54.1"
def jacksonCoreVersion = "2.15.0"
def jacksonDatabindVersion = "2.15.0"
def protocVersion = "3.22.3"

tasks.withType(JavaCompile) {
sourceCompatibility = JavaVersion.VERSION_19
targetCompatibility = JavaVersion.VERSION_19
}

ext {
speed = project.hasProperty('speed') ? project.getProperty('speed') : false
offlineCompile = new File("$buildDir/output/lib")
}

dependencies {
if (speed) {
implementation fileTree(dir: offlineCompile, include: '*.jar')
} else {
implementation "com.google.api.grpc:proto-google-common-protos:2.18.0",
"javax.annotation:javax.annotation-api:1.3.2",
"io.grpc:grpc-protobuf:${grpcVersion}",
"io.grpc:grpc-stub:${grpcVersion}",
"io.grpc:grpc-netty:${grpcVersion}",
"io.grpc:grpc-services:${grpcVersion}",
"io.grpc:grpc-census:${grpcVersion}",
"org.apache.logging.log4j:log4j-core:2.20.0",
"com.google.protobuf:protobuf-java:${protocVersion}"

runtimeOnly "com.fasterxml.jackson.core:jackson-core:${jacksonCoreVersion}",
"com.fasterxml.jackson.core:jackson-databind:${jacksonDatabindVersion}",
"io.netty:netty-tcnative-boringssl-static:2.0.61.Final"
}
}

protobuf {
protoc {
artifact = "com.google.protobuf:protoc:${protocVersion}"
}
plugins {
grpc {
artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
}
}
generateProtoTasks {
all()*.plugins {
grpc {}
}
ofSourceSet('main')
}
}

googleJavaFormat {
toolVersion '1.17.0'
}

// Inform IDEs like IntelliJ IDEA, Eclipse or NetBeans about the generated code.
sourceSets {
main {
java {
srcDirs 'hipstershop'
srcDirs 'build/generated/source/proto/main/java/hipstershop'
srcDirs 'build/generated/source/proto/main/grpc/hipstershop'
}
}
}

startScripts.enabled = false

// This to cache dependencies during Docker image building. First build will take time.
// Subsequent build will be incremental.
task downloadRepos(type: Copy) {
from configurations.compileClasspath
into offlineCompile
from configurations.compileClasspath
into offlineCompile
}

task adService(type: CreateStartScripts) {
mainClass.set('hipstershop.AdService')
applicationName = 'AdService'
outputDir = new File(project.buildDir, 'tmp')
classpath = startScripts.classpath
defaultJvmOpts =
["-agentpath:/opt/cprof/profiler_java_agent.so=-cprof_service=adservice,-cprof_service_version=1.0.0"]
}

task adServiceClient(type: CreateStartScripts) {
mainClass.set('hipstershop.AdServiceClient')
applicationName = 'AdServiceClient'
outputDir = new File(project.buildDir, 'tmp')
classpath = startScripts.classpath
defaultJvmOpts =
["-agentpath:/opt/cprof/profiler_java_agent.so=-cprof_service=adserviceclient,-cprof_service_version=1.0.0"]
}

applicationDistribution.into('bin') {
from(adService)
from(adServiceClient)
fileMode = 0755
}
Loading