rm old kafka-pipe experiments
This commit is contained in:
parent
4c14cc2353
commit
995ea750be
8 changed files with 15 additions and 246 deletions
1
modules/factorio-events-kafka-pipe/.env
Normal file
1
modules/factorio-events-kafka-pipe/.env
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
COMPOSE_PROJECT_NAME=factorio-events-kafka-pipe
|
||||||
|
|
@ -1,11 +1,7 @@
|
||||||
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs
|
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("dev.adamko.factoriowebmap.archetype.kotlin-jvm")
|
id("dev.adamko.factoriowebmap.archetype.base")
|
||||||
|
|
||||||
application
|
|
||||||
|
|
||||||
// id("com.github.johnrengelman.shadow") version "7.1.0"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
description =
|
description =
|
||||||
|
|
@ -14,142 +10,3 @@ description =
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
|
|
||||||
val projectId: String by project.extra
|
val projectId: String by project.extra
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation(libs.bundles.logging)
|
|
||||||
implementation("eu.jrie.jetbrains:kotlin-shell-core:0.2.1")
|
|
||||||
}
|
|
||||||
|
|
||||||
application {
|
|
||||||
mainClass.set("factorioEventsKafkaPipeKt")
|
|
||||||
}
|
|
||||||
|
|
||||||
java {
|
|
||||||
withSourcesJar()
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.jar {
|
|
||||||
manifest {
|
|
||||||
attributes(
|
|
||||||
"Implementation-Title" to project.name,
|
|
||||||
"Implementation-Version" to project.version,
|
|
||||||
"Main-Class" to application.mainClass,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
archiveBaseName.set(project.name)
|
|
||||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
|
||||||
|
|
||||||
from(
|
|
||||||
configurations.runtimeClasspath.map { config ->
|
|
||||||
config.map {
|
|
||||||
logger.trace("Adding runtimeClasspath file to jar - $it")
|
|
||||||
when (it.isDirectory) {
|
|
||||||
true -> it
|
|
||||||
false -> zipTree(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.create<Exec>("dockerBuildPdl2k") {
|
|
||||||
group = projectId
|
|
||||||
|
|
||||||
dependsOn(tasks.jar)
|
|
||||||
|
|
||||||
val jar = tasks.jar.get().archiveFile.get()
|
|
||||||
logger.lifecycle("building docker with jar $jar")
|
|
||||||
inputs.file(jar)
|
|
||||||
|
|
||||||
commandLine(
|
|
||||||
parseSpaceSeparatedArgs(
|
|
||||||
"docker-compose build pdl2k --build-arg JAR_LOCATION=${jar.asFile.canonicalPath}"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
// inputs(tasks.jar.get().archiveFile.get())
|
|
||||||
|
|
||||||
// commandLine(
|
|
||||||
// "docker",
|
|
||||||
// "build",
|
|
||||||
// "--build-arg",
|
|
||||||
// "JAR_FILE=",
|
|
||||||
// "-t dev-adamko/pdl2k"
|
|
||||||
// )
|
|
||||||
}
|
|
||||||
|
|
||||||
//tasks.jar.get().archiveFile.get().asFile.canonicalPath
|
|
||||||
|
|
||||||
tasks.create<Exec>("runInDocker") {
|
|
||||||
group = projectId
|
|
||||||
// docker run -v `pwd`:/mnt java:8 java -jar /mnt/myapp.jar
|
|
||||||
|
|
||||||
dependsOn(tasks.jar)
|
|
||||||
val jarFile = tasks.jar.get().archiveFile.get().asFile
|
|
||||||
inputs.file(jarFile)
|
|
||||||
|
|
||||||
commandLine(
|
|
||||||
listOf(
|
|
||||||
"docker",
|
|
||||||
"run",
|
|
||||||
"--rm",
|
|
||||||
"--name", project.name,
|
|
||||||
// """--workdir="/app" """,
|
|
||||||
"-v", ".//${jarFile.toRelativeString(project.projectDir).replace("\\", "//")}:/mnt/",
|
|
||||||
"openjdk:11.0.6-jre-buster",
|
|
||||||
"ls", "-la", "/mnt/*",
|
|
||||||
// "java", "-jar", "/mnt/${jarFile.name}",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
doFirst {
|
|
||||||
logger.lifecycle("Executing [$commandLine]")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//afterEvaluate {
|
|
||||||
// tasks {
|
|
||||||
// create("jar2", Jar::class).apply {
|
|
||||||
// dependsOn("jvmMainClasses", "jsJar")
|
|
||||||
// group = "jar"
|
|
||||||
// manifest {
|
|
||||||
// attributes(
|
|
||||||
// mapOf(
|
|
||||||
// "Implementation-Title" to rootProject.name,
|
|
||||||
// "Implementation-Version" to rootProject.version,
|
|
||||||
// "Timestamp" to System.currentTimeMillis(),
|
|
||||||
// "Main-Class" to application.mainClass
|
|
||||||
// )
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// from(
|
|
||||||
// configurations
|
|
||||||
// )
|
|
||||||
//
|
|
||||||
// val dependencies =
|
|
||||||
// configurations["jvmRuntimeClasspath"]
|
|
||||||
// .filter { it.name.endsWith(".jar") } +
|
|
||||||
// project.tasks["jvmJar"].outputs.files
|
|
||||||
// dependencies.forEach { from(zipTree(it)) }
|
|
||||||
// into("/lib")
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//val fatJar = task("fatJar", type = Jar::class) {
|
|
||||||
// baseName = "safescape-lib-${project.name}"
|
|
||||||
// // manifest Main-Class attribute is optional.
|
|
||||||
// // (Used only to provide default main class for executable jar)
|
|
||||||
// from(configurations.runtimeClasspath.map({ if (it.isDirectory) it else zipTree(it) }))
|
|
||||||
// with(tasks["jar"] as CopySpec)
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//tasks {
|
|
||||||
// "build" {
|
|
||||||
// dependsOn(fatJar)
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//from(configurations.runtimeClasspath) {
|
|
||||||
// into("lib")
|
|
||||||
//}
|
|
||||||
|
|
@ -6,6 +6,7 @@ services:
|
||||||
container_name: "factorio-events-kafka-pipe"
|
container_name: "factorio-events-kafka-pipe"
|
||||||
build:
|
build:
|
||||||
dockerfile: "kafka-pipe.Dockerfile"
|
dockerfile: "kafka-pipe.Dockerfile"
|
||||||
|
privileged: true
|
||||||
networks:
|
networks:
|
||||||
- "factorio-events-nw"
|
- "factorio-events-nw"
|
||||||
environment:
|
environment:
|
||||||
|
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
ARG JAR_LOCATION
|
|
||||||
|
|
||||||
FROM openjdk:11.0.6-jre-buster
|
|
||||||
ARG JAR_LOCATION
|
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y \
|
|
||||||
curl \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
COPY JAR_LOCATION /app.jar
|
|
||||||
|
|
||||||
ENTRYPOINT ["java","-jar","/app.jar"]
|
|
||||||
|
|
@ -1,31 +1,15 @@
|
||||||
|
|
||||||
#FROM debian:buster-slim
|
|
||||||
FROM docker:dind-rootless
|
FROM docker:dind-rootless
|
||||||
|
|
||||||
ENV FACTORIO_SERVER_CONTAINER_NAME="factorio-server"
|
ENV FACTORIO_SERVER_CONTAINER_NAME="factorio-server"
|
||||||
ENV KAFKA_HOST="kafka-kraft"
|
ENV KAFKA_HOST="kafka"
|
||||||
|
|
||||||
#RUN apt-get update && apt-get install -y --no-install-recommends \
|
# root is required for installing dependencies
|
||||||
# curl \
|
|
||||||
# docker \
|
|
||||||
# kafkacat
|
|
||||||
|
|
||||||
# root is required for following Docker logs
|
|
||||||
USER root
|
USER root
|
||||||
|
|
||||||
RUN apk add --update \
|
RUN apk add --update \
|
||||||
curl \
|
curl \
|
||||||
kafkacat
|
kafkacat
|
||||||
#USER rootless
|
USER rootless
|
||||||
|
|
||||||
# \
|
|
||||||
# && rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
COPY kafka-pipe.sh kafka-pipe.sh
|
COPY kafka-pipe.sh kafka-pipe.sh
|
||||||
|
|
||||||
#RUN useradd --user-group --system --create-home --no-log-init the_engineer
|
|
||||||
#USER the_engineer
|
|
||||||
|
|
||||||
ENTRYPOINT [ "/bin/sh", "/kafka-pipe.sh" ]
|
ENTRYPOINT [ "/bin/sh", "/kafka-pipe.sh" ]
|
||||||
#ENTRYPOINT /bin/bash
|
|
||||||
#CMD exec /kafka-pipe.sh
|
|
||||||
|
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
#!/usr/bin/zsh
|
|
||||||
|
|
||||||
# stream logs from 'factorio' container
|
|
||||||
# follow the logs, and
|
|
||||||
# combine stdout and stderr
|
|
||||||
# only match lines that start with 'FactorioEvent: ',
|
|
||||||
# and only return the stuff *after* 'FactorioEvent: '
|
|
||||||
docker logs --tail 0 -f factorio-server 2>&1 |
|
|
||||||
sed -n -e 's/^FactorioEvent: //p' |
|
|
||||||
kafkacat -P -b localhost -t factorio-server-log
|
|
||||||
|
|
||||||
# listen to events
|
|
||||||
# kafkacat -C -b localhost -t factorio-server-log | jq
|
|
||||||
|
|
||||||
# curl -sS --unix-socket /var/run/docker.sock "http://localhost/v1.41/events?filters={"service":"factorio-server"}" --output - | jq
|
|
||||||
|
|
||||||
curl --no-buffer -sS \
|
|
||||||
--unix-socket /var/run/docker.sock \
|
|
||||||
"http://localhost/v1.41/containers/factorio-server/logs?stdout=true&follow=true&tail=0" |
|
|
||||||
tail -c+9
|
|
||||||
# --output -
|
|
||||||
|
|
||||||
curl \
|
|
||||||
-sS \
|
|
||||||
--unix-socket /var/run/docker.sock \
|
|
||||||
-X POST \
|
|
||||||
--insecure "http://localhost/v1.41/containers/factorio-server/attach?logs=true&stream=true&stdout=true&follow=true" |
|
|
||||||
tail -c+9
|
|
||||||
|
|
||||||
# sed 's/^........//'
|
|
||||||
|
|
||||||
|
|
||||||
# https://stackoverflow.com/questions/42873285/curl-retry-mechanism
|
|
||||||
# --retry-all-errors
|
|
||||||
|
|
||||||
# --header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \
|
|
||||||
# --header "Sec-WebSocket-Version: 13" \
|
|
||||||
# --header "Host: localhost:80" \
|
|
||||||
# --header "Origin: http://localhost:80" \
|
|
||||||
|
|
||||||
curl --include \
|
|
||||||
--unix-socket /var/run/docker.sock \
|
|
||||||
--no-buffer \
|
|
||||||
--header "Connection: Upgrade" \
|
|
||||||
--header "Upgrade: websocket" \
|
|
||||||
--header "Host: localhost:80" \
|
|
||||||
--header "Origin: http://localhost:80" \
|
|
||||||
--header "Sec-WebSocket-Version: 13" \
|
|
||||||
--header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \
|
|
||||||
"http://localhost/v1.41/containers/factorio-server/attach/ws?logs=true&stdout=true"
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
|
|
||||||
### Setup notes
|
### Setup notes
|
||||||
|
|
||||||
Kafka must be connectable from both `localhost` (for cli) and `kafa` (the docker container name).
|
Kafka must be connectable from both `localhost` (for cli) and `kafa` (the docker container name).
|
||||||
|
|
||||||
|
|
||||||
### Useful commands
|
### Useful commands
|
||||||
|
|
||||||
|
|
@ -43,5 +41,12 @@ curl --no-buffer -sS --unix-socket /var/run/docker.sock \
|
||||||
# get logs from Kafka
|
# get logs from Kafka
|
||||||
kafkacat -u -C -b localhost -t factorio-server-log | jq --unbuffered
|
kafkacat -u -C -b localhost -t factorio-server-log | jq --unbuffered
|
||||||
|
|
||||||
```
|
# stream logs, and try trimming first 8 bytes (the header) but it doesn't work
|
||||||
|
curl \
|
||||||
|
-sS \
|
||||||
|
--unix-socket /var/run/docker.sock \
|
||||||
|
-X POST \
|
||||||
|
--insecure "http://localhost/v1.41/containers/factorio-server/attach?logs=true&stream=true&stdout=true&follow=true" |
|
||||||
|
tail -c+9
|
||||||
|
|
||||||
|
```
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
import eu.jrie.jetbrains.kotlinshell.shell.shell
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
shell {
|
|
||||||
|
|
||||||
"echo hello world"()
|
|
||||||
|
|
||||||
// """
|
|
||||||
// curl \
|
|
||||||
// --no-buffer \
|
|
||||||
// -sS \
|
|
||||||
// --unix-socket /var/run/docker.sock \
|
|
||||||
// "http://localhost/v1.41/containers/factorio-server/logs?stdout=true&follow=true&tail=0"
|
|
||||||
// """.trimIndent()
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue