project re-organisation, and rename

This commit is contained in:
Adam 2021-12-01 16:57:46 +01:00
parent 53862ef1b5
commit 633e898f3c
52 changed files with 525 additions and 387 deletions

View file

@ -0,0 +1,77 @@
import dev.adamko.factoriowebmap.configurations.asConsumer
import dev.adamko.factoriowebmap.configurations.factorioModAttributes
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs
plugins {
id("dev.adamko.factoriowebmap.archetype.process-runner")
}
val tokens: Map<String, String> by project.extra
val modInfraDir: Directory = layout.projectDirectory.dir("infra")
val factorioServerDataDir: Directory = modInfraDir.dir("factorio-server")
val factorioMod: Configuration by configurations.creating {
asConsumer()
factorioModAttributes(objects)
}
dependencies {
factorioMod(projects.modules.eventsMod)
}
val deployModToServer by tasks.registering(Copy::class) {
description = "Copy the mod to the Factorio Docker server"
group = project.name
from(factorioMod)
into(factorioServerDataDir.dir("mods"))
doLast {
logger.lifecycle("Copying mods ${source.files} to $destinationDir")
}
}
//<editor-fold desc="Factorio server lifecycle tasks">
val factorioServerStop = tasks.register<Exec>("factorioServerStop") {
group = project.name
mustRunAfter(deployModToServer)
workingDir(modInfraDir)
commandLine = parseSpaceSeparatedArgs("docker-compose stop factorio-server")
}
val factorioServerUp = tasks.register<Exec>("factorioServerUp") {
group = project.name
mustRunAfter(deployModToServer)
dependsOn(factorioServerStop)
workingDir(modInfraDir)
commandLine = parseSpaceSeparatedArgs("docker-compose up -d factorio-server")
}
val factorioServerRestart: Task by tasks.creating {
group = project.name
dependsOn(factorioServerStop, factorioServerUp)
}
//</editor-fold>
tasks.build { dependsOn(deployModToServer) }
tasks.processRun {
description = "Build the mod, upload to Server and Client, and start both"
dependsOn(
deployModToServer,
factorioServerRestart,
)
}
tasks.processKill {
dependsOn(
factorioServerStop,
)
}

View file

@ -0,0 +1 @@
COMPOSE_PROJECT_NAME=factorio-infra

View file

@ -0,0 +1 @@
factorio-server

View file

@ -0,0 +1,39 @@
version: "3.9"
services:
factorio-server:
image: factoriotools/factorio:1.1.48
# logging:
# driver: "json-file"
container_name: "factorio-server"
restart: "unless-stopped"
networks:
- "factorio-events-nw"
ports:
- "34197:34197/udp" # factorio
- "27015:27015/tcp" # rcon
volumes:
- "./factorio-server:/factorio"
# logging:
# driver: "mickyg/kafka-logdriver:latest"
# options:
# KAFKA_BROKER_ADDR: "kafka-kraft"
# LOG_TOPIC: "dockerlogs-factorio-server"
# LOG_TAG: "factorio-server"
# environment:
# RCON_PORT: 27715
# environment:
# - PUID=1000
# - PGID=1000
# - UPDATE_MODS_ON_START=true
# - USERNAME=FactorioUsername
# - TOKEN=FactorioToken
networks:
kafka-nw:
name: "kafka-nw"
external: true
factorio-events-nw:
name: "factorio-events-nw"

View file

@ -0,0 +1,23 @@
ARG factorioVersion=1.1.42
FROM factoriotools/factorio:$factorioVersion
#RUN apk add --update \
# curl \
# kafkacat \
# ;
ENV KCAT_CONFIG="/kcat.conf"
RUN apt-get update && apt-get install -y \
kafkacat \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /
COPY kafka-pipe.sh kafka-pipe.sh

View file

@ -0,0 +1,24 @@
#!/usr/bin/bash
# Pipe Docker logs from a Factorio server to a Kafka topic
echo "Piping logs from $FACTORIO_SERVER_CONTAINER_NAME to $KAFKA_HOST"
# generate some distinctive key for messages from this server
SERVER_HASH=openssl dgst -sha3-512 "$CONFIG/server-settings.json"
trap endProcess SIGINT
endProcess() {
echo "Exiting Factorio Events Kafka Pipe"
exit
}
while :; do
sed -n -e 's/^FactorioEvent: //p' |
kafkacat -F "$KCAT_PROP_FILE"
echo "Error - retrying in 10 seconds"
sleep 10
done

View file

@ -0,0 +1 @@
enable.idempotence=true