Skip to content
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
50 changes: 50 additions & 0 deletions .github/workflows/ads-java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Ads

on:
push:
branches: [ main ]
paths:
- services/ads/java/**
workflow_dispatch:
branches: [ main ]

defaults:
run:
working-directory: ads

jobs:

build:

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

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

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Login to ECR
id: login-ecr
uses: docker/login-action@v1
with:
registry: public.ecr.aws
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

- name: Build and push
uses: docker/build-push-action@v2
with:
context: ./services/ads/java
platforms: linux/amd64
push: true
tags: ${{ secrets.PUBLIC_ECR_REGISTRY }}/storedog/ads-java:latest

4 changes: 2 additions & 2 deletions .github/workflows/ads.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [ main ]
paths:
- services/ads/**
- services/ads/python/**
workflow_dispatch:
branches: [ main ]

Expand Down Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Build and push
uses: docker/build-push-action@v2
with:
context: ./services/ads
context: ./services/ads/python
platforms: linux/amd64
push: true
tags: ${{ secrets.PUBLIC_ECR_REGISTRY }}/storedog/ads:latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
${{ secrets.PUBLIC_ECR_REGISTRY }}/storedog/backend
${{ secrets.PUBLIC_ECR_REGISTRY }}/storedog/discounts
${{ secrets.PUBLIC_ECR_REGISTRY }}/storedog/ads
${{ secrets.PUBLIC_ECR_REGISTRY }}/storedog/ads-java
${{ secrets.PUBLIC_ECR_REGISTRY }}/storedog/attackbox
${{ secrets.PUBLIC_ECR_REGISTRY }}/storedog/auth
)
Expand Down
19 changes: 16 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ services:
- DD_PROFILING_ENABLED=true
- DD_APPSEC_ENABLED=true
build:
context: ./services/ads
context: ./services/ads/python
command: flask run --port=${ADS_PORT} --host=0.0.0.0 # If using any other port besides the default 9292, overriding the CMD is required
volumes:
- "./services/ads:/app"
- ./services/ads/python:/app
ports:
- "${ADS_PORT}:${ADS_PORT}"
networks:
Expand All @@ -104,7 +104,7 @@ services:
build:
context: ./services/discounts
volumes:
- "./services/discounts:/app"
- ./services/discounts:/app
ports:
- "${DISCOUNTS_PORT}:${DISCOUNTS_PORT}"
- "22:22"
Expand Down Expand Up @@ -153,6 +153,19 @@ services:
- /sys/fs/cgroup/:/host/sys/fs/cgroup:ro
networks:
- storedog-net
ads-java:
build:
context: ./services/ads/java
environment:
- DD_SERVICE=ads-java
- DD_AGENT_HOST=dd-agent
- DD_LOGS_INJECTION=true
- DD_TRACE_ANALYTICS_ENABLED=true
- DD_PROFILING_ENABLED=true
ports:
- "3030:8080"
networks:
- storedog-net
attackbox:
build:
context: ./services/attackbox
Expand Down
26 changes: 26 additions & 0 deletions services/ads/java/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# compile via gradle
FROM gradle:jdk11 AS TEMP_BUILD_IMAGE
ENV APP_HOME=/usr/app/
WORKDIR $APP_HOME
COPY build.gradle settings.gradle $APP_HOME

COPY gradle $APP_HOME/gradle
COPY --chown=gradle:gradle . /home/gradle/src
USER root
RUN chown -R gradle /home/gradle/src

COPY . .
RUN gradle clean build

# app container
FROM alpine:latest
RUN apk --update add openjdk11-jre
ENV ARTIFACT_NAME=ads-java-0.0.1-SNAPSHOT.jar
ENV APP_HOME=/usr/app/

WORKDIR $APP_HOME
COPY --from=TEMP_BUILD_IMAGE $APP_HOME/build/libs/$ARTIFACT_NAME .

RUN wget -O dd-java-agent.jar 'https://dtdg.co/latest-java-tracer'

ENTRYPOINT exec java -javaagent:/usr/app/dd-java-agent.jar -Ddd.logs.injection=true -Ddd.service=ads-java -Ddd.env=dev -jar ${ARTIFACT_NAME}
25 changes: 25 additions & 0 deletions services/ads/java/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
plugins {
id 'org.springframework.boot' version '2.7.5'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
mavenCentral()
}

dependencies {
implementation (
'commons-io:commons-io:2.4',
'org.springframework.boot:spring-boot-starter-web'
)
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
useJUnitPlatform()
}
Binary file not shown.
5 changes: 5 additions & 0 deletions services/ads/java/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
1 change: 1 addition & 0 deletions services/ads/java/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'ads-java'
65 changes: 65 additions & 0 deletions services/ads/java/src/main/java/adsjava/AdsJavaApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package adsjava;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.http.MediaType;
import org.springframework.util.StreamUtils;
import java.io.*;
import org.springframework.web.bind.annotation.ResponseBody;
import org.apache.commons.io.IOUtils;
import java.util.concurrent.ThreadLocalRandom;
import java.util.HashMap;
import org.springframework.web.bind.annotation.RequestParam;

@SpringBootApplication
@RestController
public class AdsJavaApplication {

@CrossOrigin(origins = "http://localhost:3000")
@RequestMapping(
value = "/banners/{id}",
produces = MediaType.IMAGE_JPEG_VALUE
)
public @ResponseBody byte[] getImageWithMediaType() throws IOException {
int randomNum = ThreadLocalRandom.current().nextInt(1, 3 + 1);
String imagePath = "/static/ads/ad" + randomNum + ".jpg";
InputStream in = getClass()
.getResourceAsStream(imagePath);
return IOUtils.toByteArray(in);
}

@RequestMapping("/")
public String home() {
return "Hello from Advertisements (Java)";
}

@CrossOrigin(origins = "http://localhost:3000")
@RequestMapping(
value = "/ads",
produces = MediaType.APPLICATION_JSON_VALUE
)
public HashMap[] ads() {
HashMap<String, String> map1 = new HashMap<>();
map1.put("id", "1");
map1.put("path", "ad1.jpg");

HashMap<String, String> map2 = new HashMap<>();
map2.put("id", "2");
map2.put("path", "ad2.jpg");

HashMap<String, String> map3 = new HashMap<>();
map3.put("id", "3");
map3.put("path", "ad3.jpg");

HashMap[] myArr = { map1, map2, map3 };
return myArr;
}

public static void main(String[] args) {
SpringApplication.run(AdsJavaApplication.class, args);
}

}
23 changes: 23 additions & 0 deletions services/ads/java/src/main/resources/static/banner-list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[
{
"id": 1,
"name": "Discount Clothing",
"path": "ad1.jpg",
"url": "/t/clothing",
"weight": 15.1
},
{
"id": 2,
"name": "Cool Hats",
"path": "ad2.jpg",
"url": "/products/datadog-ringer-t-shirt",
"weight": 300.1
},
{
"id": 3,
"name": "Nice Bags",
"path": "ad3.jpg",
"url": "/t/bags",
"weight": 5242.1
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package adsjava;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class AdsJavaApplicationTests {

@Test
void contextLoads() {
}

}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added services/ads/python/ads/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added services/ads/python/ads/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added services/ads/python/ads/3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.