Skip to content

Commit

Permalink
BPWA-109 Initial commit. Separated protocol service from client
Browse files Browse the repository at this point in the history
  • Loading branch information
colps committed Jul 26, 2021
0 parents commit 5d450d8
Show file tree
Hide file tree
Showing 135 changed files with 5,598 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**
!/build/libs/sandbox_bap-*.*.*-SNAPSHOT.jar
427 changes: 427 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: build

on: [ push ]

jobs:
build:
runs-on: [ self-hosted, linux ]

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Build with Gradle
run: ./gradlew clean build
- name: Cleanup Gradle Cache
# Remove some files from the Gradle cache, so they aren't cached by GitHub Actions.
# Restoring these files from a GitHub Actions cache might cause problems for future builds.
run: |
rm -f ~/.gradle/caches/modules-2/modules-2.lock
rm -f ~/.gradle/caches/modules-2/gc.properties
deploy:
name: package and deploy the service
needs: build
if: github.ref == 'refs/heads/main'
runs-on: [ self-hosted, linux ]
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build docker image
uses: docker/build-push-action@v2
with:
load: true
context: .
push: false
tags: 795151977897.dkr.ecr.ap-south-1.amazonaws.com/beckn_one_sandbox_bap_protocol:${{ github.run_number }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Cache growth workaround
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Push image to ECR
env:
GITHUB_RUN_NUMBER: ${{ github.run_number }}
run: |
aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin 795151977897.dkr.ecr.ap-south-1.amazonaws.com
docker push 795151977897.dkr.ecr.ap-south-1.amazonaws.com/beckn_one_sandbox_bap_protocol:${GITHUB_RUN_NUMBER}
docker rmi -f 795151977897.dkr.ecr.ap-south-1.amazonaws.com/beckn_one_sandbox_bap_protocol:${GITHUB_RUN_NUMBER}
- name: Deploying to the BAP servers qa using ansible
run: |
cd ansible
export ANSIBLE_ROLES_PATH=./roles
echo bap_build_no: ${GITHUB_RUN_NUMBER} >> vars/vars.yml
/home/ubuntu/.local/bin/ansible-playbook playbooks/beckn_services.yml -i inventory/qa.ini --extra-vars "@vars/vars.yml"
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/
1 change: 1 addition & 0 deletions .java-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Sandbox BAP

Provides BAP APIs for Sandbox

6 changes: 6 additions & 0 deletions ansible/.ssh/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Host *
StrictHostKeyChecking no

Host 10.0.1.*
User ubuntu
IdentityFile ~/.ssh/id_rsa
5 changes: 5 additions & 0 deletions ansible/inventory/qa.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[bap_protocol_service]
10.0.1.184

[docker:children]
bap_protocol_service
14 changes: 14 additions & 0 deletions ansible/playbooks/beckn_services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- hosts: bap_protocol_service
roles:
- { role: docker, tags: docker }
- { role: awscli, tags: awscli }
- { role: beckn_service, tags: beckn_one_sandbox_bap_protocol }
become: yes
vars:
service_name: beckn_one_sandbox_bap_protocol
service_description: BAP Protocol Service
service_port: 9002
expose_ports: -p {{ service_port }}:{{ service_port }}
mount_points: -v {{ user_dir }}/application.yml:/usr/local/lib/application.yml
tags: deploy_beckn_one_sandbox_bap_protocol
5 changes: 5 additions & 0 deletions ansible/playbooks/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: docker
roles:
- { role: docker, become: yes }

3 changes: 3 additions & 0 deletions ansible/roles/awscli/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
user_dir: /home/ubuntu

29 changes: 29 additions & 0 deletions ansible/roles/awscli/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
- name: Install unzip
apt:
name: unzip

- name: Download AWS CLI V2 Installer
get_url:
url: https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip
dest: "{{ user_dir }}/awscliv2.zip"

- name: Extract AWS CLI V2 Installer
unarchive:
src: "{{ user_dir }}/awscliv2.zip"
dest: "{{ user_dir }}"
remote_src: true

- name: Install AWS CLI V2
command: ./aws/install --update

- name: Create AWS CLI directory
file:
path: "{{ user_dir }}/.aws"
state: directory

- name: Create AWS Config file
template:
src: config.j2
dest: "{{ user_dir }}/.aws/config"

3 changes: 3 additions & 0 deletions ansible/roles/awscli/templates/config.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[default]
region={{ aws_region }}

7 changes: 7 additions & 0 deletions ansible/roles/beckn_service/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
aws_account_id: 795151977897
aws_region: ap-south-1
image_version: "{{ bap_build_no }}"
ecr_url: "{{ aws_account_id }}.dkr.ecr.{{ aws_region }}.amazonaws.com"
image_repository: "{{ service_name }}"
image_name: "{{ ecr_url }}/{{ image_repository }}:{{ image_version }}"
12 changes: 12 additions & 0 deletions ansible/roles/beckn_service/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- name: Systemctl Daemon Reload
shell: systemctl daemon-reload

- name: Systemctl Enable Service
shell: "systemctl enable {{ service_name }}"

- name: Restart Service
service:
name: "{{ service_name }}"
state: restarted

34 changes: 34 additions & 0 deletions ansible/roles/beckn_service/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- name: Get AWS Login password
shell: "aws ecr get-login-password"
register: aws_password
no_log: True

- name: Login to AWS
command: "docker login --username AWS --password {{ aws_password.stdout }} {{ ecr_url }}"

- name: Pull docker image
command: "docker pull {{ image_name }}"
notify:
- Systemctl Daemon Reload
- Systemctl Enable Service
- Restart Service

- name: Create Services
template:
src: "beckn_service.j2"
dest: "/etc/systemd/system/{{ service_name }}.service"
backup: yes
notify:
- Systemctl Daemon Reload
- Systemctl Enable Service
- Restart Service

- name: Substitute application properties
template:
src: "../../../../src/main/resources/application.yml.j2"
dest: "{{ user_dir }}/application.yml"
backup: yes

- name: Cleanup older docker images
ansible.builtin.shell: 'docker image prune --all --force --filter until=$(date "--date=`date` -2 DAY" +%Y-%m-%dT%H:%m)'
12 changes: 12 additions & 0 deletions ansible/roles/beckn_service/templates/beckn_service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description={{ service_description }}

[Service]
TimeoutStartSec=60
Restart=always
ExecStart=/usr/bin/docker run {{ expose_ports }} {{ mount_points }} --rm --name %n {{ image_name }}
ExecStop=/usr/bin/docker stop %n

[Install]
WantedBy=default.target

33 changes: 33 additions & 0 deletions ansible/roles/docker/tasks/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
- name: Update APT cache
apt:
update_cache: yes

- name: Install packages that allow APT to use repository over HTTPS
apt:
name: ["apt-transport-https", "ca-certificates", "curl", "gnupg", "lsb-release"]

- name: Add Docker GPG apt Key
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present

- name: Add Docker Repository
apt_repository:
repo: deb https://download.docker.com/linux/ubuntu bionic stable
state: present

- name: Update APT cache
apt:
update_cache: yes

- name: Install Docker and packages it depends on
apt:
name: ["docker-ce", "docker-ce-cli", "containerd.io"]

- name: Add docker group
command: groupadd -f docker

- name: Add current user to group
command: usermod -aG docker $USER

3 changes: 3 additions & 0 deletions ansible/roles/docker/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- include: install.yml

5 changes: 5 additions & 0 deletions ansible/vars/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
var: this
mongo_host: 10.0.1.10
mongo_port: 27017
bap_mongo_name: sandbox_bap
84 changes: 84 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("jacoco")
id("org.springframework.boot") version "2.5.0"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
id("org.jetbrains.kotlin.plugin.serialization") version "1.5.10"
id("org.jetbrains.kotlin.plugin.allopen") version ("1.5.20")
kotlin("jvm") version "1.4.31"
kotlin("plugin.spring") version "1.4.31"
kotlin("kapt") version "1.4.31"
}

group = "org.beckn.one.sandbox"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11

allOpen {
annotation("org.beckn.one.sandbox.bap.Open")
}

repositories {
mavenCentral()
/*maven {
url = uri("s3://beckn-maven-artifacts/releases")
authentication {
val awsIm by registering(AwsImAuthentication::class)
}
}*/
mavenLocal()
}

dependencies {
val retrofitVersion = "2.9.+"

kapt("io.arrow-kt:arrow-meta:0.13.2")
kapt("org.mapstruct:mapstruct-processor:1.4.2.Final")
kapt("org.mapstruct:mapstruct-jdk8:1.4.2.Final")

implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.+")
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.12.+")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.12.+")
implementation("io.arrow-kt:arrow-optics:0.13.2")
implementation("org.litote.kmongo:kmongo:4.2.8")
implementation("org.mapstruct:mapstruct:1.4.2.Final")
implementation("org.beckn.jvm:beckn-protocol-dtos:0.9.1.9")

testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("io.kotest:kotest-runner-junit5:4.4.3")
testImplementation("io.kotest:kotest-extensions-spring:4.4.3")
testImplementation("com.github.tomakehurst:wiremock-jre8:2.28.0")
testImplementation("org.testcontainers:mongodb:1.15.3")
testImplementation("org.mockito.kotlin:mockito-kotlin:3.2.0")
testImplementation("io.kotest.extensions:kotest-assertions-arrow:1.0.2")
}

tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "11"
}
}

tasks.withType<Test> {
useJUnitPlatform()
}

jacoco {
toolVersion = "0.8.7"
}

tasks.jacocoTestReport {
dependsOn("build")
reports {
xml.required.set(false)
csv.required.set(false)
html.outputLocation.set(layout.buildDirectory.dir("jacocoHtml"))
}
}
6 changes: 6 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM openjdk:11-jre-slim
# try out alpine/debian

COPY build/libs/sandbox_bap-*.*.*-SNAPSHOT.jar /usr/local/lib/sandbox_bap.jar

ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar /usr/local/lib/sandbox_bap.jar --spring.config.location=file:///usr/local/lib/application.yml"]
Loading

0 comments on commit 5d450d8

Please sign in to comment.