Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pambrose committed Oct 3, 2024
0 parents commit c964400
Show file tree
Hide file tree
Showing 17 changed files with 770 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.gradle
.kotlin
build/
secrets/

!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

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

### VS Code ###
.vscode/
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM alpine
# LABEL org.opencontainers.image.authors="[email protected]"
RUN apk add openjdk17-jre

# Define the user to use in this instance to prevent using root that even in a container, can be a security risk.
ENV APPLICATION_USER=vapi_user

# Then add the user, create the /app folder and give permissions to our user.
RUN adduser --disabled-password --gecos '' $APPLICATION_USER
RUN mkdir /app
RUN chown -R $APPLICATION_USER /app

# Mark this container to use the specified $APPLICATION_USER
USER $APPLICATION_USER

COPY ./build/libs/vapi4k-template.jar /app/vapi4k-template.jar
COPY src/main/resources /app/src/main/resources

# Make /app the working directory
WORKDIR /app

EXPOSE 8080

CMD []
# Launch java to execute the jar with defaults intended for containers.
ENTRYPOINT ["java", "-server", "-XX:+UseContainerSupport", "-Xmx2048m", "-jar", "/app/vapi4k-template.jar"]
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
VERSION=0.0.1

default: versioncheck

clean:
./gradlew clean

compile: clean
./gradlew build -x test

jar: compile
./gradlew buildFatJar

run-jar: jar
./gradlew runFatJar

versioncheck:
./gradlew dependencyUpdates

# Assign your docker hub username here
IMAGE_NAME := docker_hub_username/vapi4k-template
PLATFORMS := linux/amd64,linux/arm64/v8

build-docker: jar
docker build -t ${IMAGE_NAME}:${VERSION} .

run-docker:
docker run --rm -p 8080:8080 ${IMAGE_NAME}:${VERSION}

push-docker:
# prepare multiarch
docker buildx use buildx 2>/dev/null || docker buildx create --use --name=buildx
docker buildx build --platform ${PLATFORMS} --push -t ${IMAGE_NAME}:latest -t ${IMAGE_NAME}:${VERSION} .

release: build-docker push-docker

upgrade-wrapper:
./gradlew wrapper --gradle-version=8.10.2 --distribution-type=bin
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: java -jar build/libs/vapi4k-template.jar
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Vapi4k Application Template

[![Kotlin](https://img.shields.io/badge/%20language-Kotlin-red.svg)](https://kotlinlang.org/)
[![ktlint](https://img.shields.io/badge/ktlint%20code--style-%E2%9D%A4-FF4081)](https://pinterest.github.io/ktlint/)

This template is a starting point for creating a new [vapi.ai](https://vapi.ai) application using
the vapi4k ktor plugin and Kotlin DSL. It contains some simple applications that can be deployed to
Heroku or any docker-supported environment.

For more information on how to use this template, please refer to the [vapi4k Documentation](https://docs.vapi4k.com/).

68 changes: 68 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask

val kotlin_version: String by project
val logback_version: String by project
val vapi4k_version: String by project

plugins {
val kotlinVersion: String by System.getProperties()
val ktorVersion: String by System.getProperties()
val versionsVersion: String by System.getProperties()

java
kotlin("jvm") version kotlinVersion
id("io.ktor.plugin") version ktorVersion
id("com.github.ben-manes.versions") version versionsVersion
}

group = "com.myapp"
version = "1.0.0"

application {
mainClass.set("com.myapp.ApplicationKt")
}

ktor {
fatJar {
// Change this to whatever name you want
// It also has to be changed in the Dockerfile
archiveFileName.set("vapi4k-template.jar")
}
}

// This must match the version defined in system.properties
kotlin {
jvmToolchain(11)
}

repositories {
google()
mavenCentral()
maven(url = "https://jitpack.io") // Required for the vapi4k jars
}

dependencies {
implementation("com.github.vapi4k.vapi4k:vapi4k-core:$vapi4k_version")
implementation("com.github.vapi4k.vapi4k:vapi4k-dbms:$vapi4k_version")

testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
}

// Required for heroku deployments
tasks.register("stage") {
dependsOn("build", "clean")
doLast {
println("Stage task completed")
}
}

// Required for heroku deployments
tasks.named("build") {
mustRunAfter("clean")
}

tasks.withType<DependencyUpdatesTask> {
rejectVersionIf {
listOf("BETA", "-RC").any { candidate.version.uppercase().contains(it) }
}
}
8 changes: 8 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
kotlin.code.style=official
# Plugins
systemProp.kotlinVersion=2.0.20
systemProp.ktorVersion=2.3.12
systemProp.versionsVersion=0.51.0
# Jars
kotlin_version=2.0.20
vapi4k_version=1.3.16
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit c964400

Please sign in to comment.