Skip to content

Commit

Permalink
ci: add docker integration and workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
lost-illusi0n committed Sep 10, 2023
1 parent 7929e57 commit 6f0b0e7
Show file tree
Hide file tree
Showing 30 changed files with 98 additions and 25 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/docker-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build

on:
push:
branches: ['master']

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Docker Meta
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha,prefix=
- name: Login to GitHub Container Registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: ./mailserver/
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ Kmail is a lightweight mail server solution written in Kotlin. Instead of packin
> Kmail is incomplete and under active development!
## Getting Started
Running from outside an IDE is not yet supported. Kmail will be dockerized soon.

### Docker
`docker pull ghcr.io/lost-illusi0n/kmail:master`
- map ports `143`, `110`, `587`, `25`
- add volumes that contain your `kmail.toml` and anything else used by Kmail (e.g., certificates)

### Prerequisites
For a smooth experience, you will need to:
Expand Down
1 change: 1 addition & 0 deletions mailserver/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.gradle
**/build/
compose.yaml
19 changes: 19 additions & 0 deletions mailserver/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM azul/zulu-openjdk-alpine:17-latest AS BUILDER
WORKDIR /build/mailserver
COPY . .
RUN ./gradlew runner:installDist --stacktrace --no-daemon

FROM azul/zulu-openjdk-alpine:17-jre-headless-latest
WORKDIR /mailserver
COPY --from=BUILDER /build/mailserver/runner/build/install/runner .

# IMAP
EXPOSE 143
# POP3
EXPOSE 110
# SUBMISSION
EXPOSE 587
# SMTP
EXPOSE 25

ENTRYPOINT [ "/mailserver/bin/runner" ]
39 changes: 22 additions & 17 deletions mailserver/runner/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("multiplatform")
application
kotlin("jvm")
kotlin("plugin.serialization")
}

Expand All @@ -12,26 +13,30 @@ repositories {
maven("https://jitpack.io")
}

application {
mainClass.set("dev.sitar.kmail.runner.LauncherJvmKt")
}

kotlin {
jvm()
jvmToolchain(17)
}

sourceSets["commonMain"].dependencies {
implementation("io.github.microutils:kotlin-logging:3.0.2")
implementation("org.apache.logging.log4j:log4j-slf4j2-impl:2.19.0")
implementation("org.apache.logging.log4j:log4j-core:2.19.0")
implementation("org.apache.logging.log4j:log4j-api:2.19.0")
dependencies {
implementation("io.github.microutils:kotlin-logging:3.0.2")
implementation("org.apache.logging.log4j:log4j-slf4j2-impl:2.19.0")
implementation("org.apache.logging.log4j:log4j-core:2.19.0")
implementation("org.apache.logging.log4j:log4j-api:2.19.0")

implementation("io.ktor:ktor-network-tls-certificates:2.1.3")
implementation("io.ktor:ktor-network-tls-certificates:2.1.3")

implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-toml:2.15.2")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.15.2")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-toml:2.15.2")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.15.2")

implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
implementation("aws.sdk.kotlin:s3:0.32.0-beta")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
implementation("aws.sdk.kotlin:s3:0.32.0-beta")

implementation(project(":smtp-agent"))
implementation(project(":smtp"))
implementation(project(":imap-agent"))
implementation(project(":pop3-agent"))
}
implementation(project(":smtp-agent"))
implementation(project(":smtp"))
implementation(project(":imap-agent"))
implementation(project(":pop3-agent"))
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package dev.sitar.kmail.runner

import dev.sitar.kmail.utils.connection.KtorConnectionFactory
import dev.sitar.kmail.utils.connection.TlsCapableConnectionFactory
import dev.sitar.kmail.utils.server.TlsCapableServerSocketFactory
import io.ktor.network.tls.*
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import java.util.concurrent.Future
import javax.net.ssl.SSLContext

suspend fun main(): Unit = coroutineScope {
dns()
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import java.security.cert.X509Certificate
import java.security.spec.PKCS8EncodedKeySpec
import javax.net.ssl.KeyManagerFactory
import javax.net.ssl.SSLContext
import javax.net.ssl.TrustManager
import javax.net.ssl.TrustManagerFactory
import javax.net.ssl.X509TrustManager

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package dev.sitar.kmail.runner.storage.filesystems

import dev.sitar.kmail.runner.KmailConfig

expect class LocalFileSystem(config: KmailConfig.Mailbox.Filesystem.Local): FileSystem
//expect class LocalFileSystem(config: KmailConfig.Mailbox.Filesystem.Local): FileSystem
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import dev.sitar.kmail.runner.storage.Attributable
import dev.sitar.kmail.runner.storage.Attributes
import java.io.File

actual class LocalFileSystem actual constructor(val config: KmailConfig.Mailbox.Filesystem.Local): FileSystem {
class LocalFileSystem(val config: KmailConfig.Mailbox.Filesystem.Local): FileSystem {
val root = File(config.dir)

override suspend fun init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,20 @@ import mu.KotlinLogging
private val logger = KotlinLogging.logger { }

suspend fun CoroutineScope.mailbox(incoming: Flow<InternetMessage>): StorageLayer {
logger.info { "initiating filesystem" }

val filesystem = when (Config.mailbox.filesystem) {
is KmailConfig.Mailbox.Filesystem.InMemory -> InMemoryFileSystem()
is KmailConfig.Mailbox.Filesystem.Local -> LocalFileSystem(Config.mailbox.filesystem)
is KmailConfig.Mailbox.Filesystem.S3 -> S3FileSystem(Config.mailbox.filesystem)
}

logger.info { "detected a ${Config.mailbox.filesystem} filesystem" }

filesystem.init()

logger.info { "initiated filesystem" }

val storage = KmailStorageLayer(CachedFileSystem(filesystem))

launch {
Expand Down

0 comments on commit 6f0b0e7

Please sign in to comment.