feat: working on docker build
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
# Build the executable
|
# Build the executable
|
||||||
FROM swift as build
|
FROM swift:5.10 AS build
|
||||||
WORKDIR /build
|
WORKDIR /build
|
||||||
COPY ./Package.* ./
|
COPY ./Package.* ./
|
||||||
RUN swift package resolve
|
RUN swift package resolve
|
||||||
@@ -8,6 +8,6 @@ COPY . .
|
|||||||
RUN swift build --enable-test-discovery -c release -Xswiftc -g
|
RUN swift build --enable-test-discovery -c release -Xswiftc -g
|
||||||
|
|
||||||
# Run image
|
# Run image
|
||||||
FROM swift
|
FROM swift:5.10
|
||||||
WORKDIR /run
|
WORKDIR /run
|
||||||
COPY --from=build /build/.build/release /run
|
COPY --from=build /build/.build/release /run
|
||||||
|
|||||||
18
Makefile
18
Makefile
@@ -1,24 +1,24 @@
|
|||||||
|
|
||||||
bootstrap-env:
|
bootstrap-env:
|
||||||
@cp Bootstrap/dewPoint-env-example .dewPoint-env
|
@cp Bootstrap/dewPoint-env-example .dewPoint-env
|
||||||
|
|
||||||
bootstrap-topics:
|
bootstrap-topics:
|
||||||
@cp Bootstrap/topics-example .topics
|
@cp Bootstrap/topics-example .topics
|
||||||
|
|
||||||
bootstrap: bootstrap-env bootstrap-topics
|
bootstrap: bootstrap-env bootstrap-topics
|
||||||
|
|
||||||
build:
|
build:
|
||||||
@swift build
|
@swift build
|
||||||
|
|
||||||
run:
|
run:
|
||||||
@swift run dewPoint-controller
|
@swift run dewPoint-controller
|
||||||
|
|
||||||
start-mosquitto:
|
start-mosquitto:
|
||||||
@docker compose start mosquitto
|
@docker-compose start mosquitto
|
||||||
|
|
||||||
stop-mosquitto:
|
stop-mosquitto:
|
||||||
@docker compose rm -f mosquitto || true
|
@docker-compose rm -f mosquitto || true
|
||||||
|
|
||||||
test-docker:
|
test-docker:
|
||||||
@docker compose run -i test
|
@docker-compose run -i test
|
||||||
@docker compose kill mosquitto-test
|
@docker-compose kill mosquitto-test
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// swift-tools-version:5.5
|
// swift-tools-version:5.10
|
||||||
|
|
||||||
import PackageDescription
|
import PackageDescription
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import NIO
|
|||||||
import Psychrometrics
|
import Psychrometrics
|
||||||
|
|
||||||
extension Client {
|
extension Client {
|
||||||
|
|
||||||
// The state passed in here needs to be a class or we get escaping errors in the `addListeners` method.
|
// The state passed in here needs to be a class or we get escaping errors in the `addListeners` method.
|
||||||
public static func live(
|
public static func live(
|
||||||
client: MQTTNIO.MQTTClient,
|
client: MQTTNIO.MQTTClient,
|
||||||
@@ -45,12 +45,13 @@ import NIOTransportServices
|
|||||||
import EnvVars
|
import EnvVars
|
||||||
|
|
||||||
public class AsyncClient {
|
public class AsyncClient {
|
||||||
public static let eventLoopGroup = NIOTSEventLoopGroup()
|
//public static let eventLoopGroup = NIOTSEventLoopGroup()
|
||||||
|
public static let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
|
||||||
public let client: MQTTClient
|
public let client: MQTTClient
|
||||||
public private(set) var shuttingDown: Bool
|
public private(set) var shuttingDown: Bool
|
||||||
|
|
||||||
var logger: Logger { client.logger }
|
var logger: Logger { client.logger }
|
||||||
|
|
||||||
public init(envVars: EnvVars, logger: Logger) {
|
public init(envVars: EnvVars, logger: Logger) {
|
||||||
let config = MQTTClient.Configuration.init(
|
let config = MQTTClient.Configuration.init(
|
||||||
version: .v3_1_1,
|
version: .v3_1_1,
|
||||||
@@ -70,7 +71,7 @@ public class AsyncClient {
|
|||||||
)
|
)
|
||||||
self.shuttingDown = false
|
self.shuttingDown = false
|
||||||
}
|
}
|
||||||
|
|
||||||
public func connect() async {
|
public func connect() async {
|
||||||
do {
|
do {
|
||||||
try await self.client.connect()
|
try await self.client.connect()
|
||||||
@@ -87,17 +88,17 @@ public class AsyncClient {
|
|||||||
logger.trace("Connection Failed.\n\(error)")
|
logger.trace("Connection Failed.\n\(error)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func shutdown() async {
|
public func shutdown() async {
|
||||||
self.shuttingDown = true
|
self.shuttingDown = true
|
||||||
try? await self.client.disconnect()
|
try? await self.client.disconnect()
|
||||||
try? await self.client.shutdown()
|
try? await self.client.shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
func addSensorListeners() async {
|
func addSensorListeners() async {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to save the recieved values somewhere.
|
// Need to save the recieved values somewhere.
|
||||||
func addPublishListener<T>(
|
func addPublishListener<T>(
|
||||||
topic: String,
|
topic: String,
|
||||||
@@ -121,8 +122,8 @@ public class AsyncClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private func publish(string: String, to topic: String) async throws {
|
private func publish(string: String, to topic: String) async throws {
|
||||||
try await self.client.publish(
|
try await self.client.publish(
|
||||||
to: topic,
|
to: topic,
|
||||||
@@ -130,26 +131,26 @@ public class AsyncClient {
|
|||||||
qos: .atLeastOnce
|
qos: .atLeastOnce
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func publish(double: Double, to topic: String) async throws {
|
private func publish(double: Double, to topic: String) async throws {
|
||||||
let rounded = round(double * 100) / 100
|
let rounded = round(double * 100) / 100
|
||||||
try await publish(string: "\(rounded)", to: topic)
|
try await publish(string: "\(rounded)", to: topic)
|
||||||
}
|
}
|
||||||
|
|
||||||
func publishDewPoint(_ request: Client.SensorPublishRequest) async throws {
|
func publishDewPoint(_ request: Client.SensorPublishRequest) async throws {
|
||||||
// fix
|
// fix
|
||||||
guard let (dewPoint, topic) = request.dewPointData(topics: .init(), units: nil) else { return }
|
guard let (dewPoint, topic) = request.dewPointData(topics: .init(), units: nil) else { return }
|
||||||
try await self.publish(double: dewPoint.rawValue, to: topic)
|
try await self.publish(double: dewPoint.rawValue, to: topic)
|
||||||
logger.debug("Published dewpoint: \(dewPoint.rawValue), to: \(topic)")
|
logger.debug("Published dewpoint: \(dewPoint.rawValue), to: \(topic)")
|
||||||
}
|
}
|
||||||
|
|
||||||
func publishEnthalpy(_ request: Client.SensorPublishRequest) async throws {
|
func publishEnthalpy(_ request: Client.SensorPublishRequest) async throws {
|
||||||
// fix
|
// fix
|
||||||
guard let (enthalpy, topic) = request.enthalpyData(altitude: .seaLevel, topics: .init(), units: nil) else { return }
|
guard let (enthalpy, topic) = request.enthalpyData(altitude: .seaLevel, topics: .init(), units: nil) else { return }
|
||||||
try await self.publish(double: enthalpy.rawValue, to: topic)
|
try await self.publish(double: enthalpy.rawValue, to: topic)
|
||||||
logger.debug("Publihsed enthalpy: \(enthalpy.rawValue), to: \(topic)")
|
logger.debug("Publihsed enthalpy: \(enthalpy.rawValue), to: \(topic)")
|
||||||
}
|
}
|
||||||
|
|
||||||
public func publishSensor(_ request: Client.SensorPublishRequest) async throws {
|
public func publishSensor(_ request: Client.SensorPublishRequest) async throws {
|
||||||
try await publishDewPoint(request)
|
try await publishDewPoint(request)
|
||||||
try await publishEnthalpy(request)
|
try await publishEnthalpy(request)
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
# run this with docker-compose -f docker/docker-compose.yml run test
|
# run this with docker-compose -f docker/docker-compose.yml run test
|
||||||
version: "3"
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
test:
|
test:
|
||||||
image: swift:latest
|
image: swift:latest
|
||||||
|
|||||||
Reference in New Issue
Block a user