feat: updates for docker image
This commit is contained in:
@@ -1 +1,2 @@
|
|||||||
.build/*
|
.build/*
|
||||||
|
mqtt_password.txt
|
||||||
|
|||||||
61
.github/workflows/release.yml
vendored
Normal file
61
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
#
|
||||||
|
name: Create and publish a Docker image
|
||||||
|
|
||||||
|
# Configures this workflow to run every time a change is pushed to the branch called `release`.
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: ['release']
|
||||||
|
|
||||||
|
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
|
||||||
|
env:
|
||||||
|
REGISTRY: ghcr.io
|
||||||
|
IMAGE_NAME: swift-mqtt-dewpoint
|
||||||
|
|
||||||
|
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
|
||||||
|
jobs:
|
||||||
|
build-and-push-image:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
attestations: write
|
||||||
|
id-token: write
|
||||||
|
#
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
|
||||||
|
- name: Log in to the Container registry
|
||||||
|
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
|
||||||
|
- name: Extract metadata (tags, labels) for Docker
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
|
||||||
|
with:
|
||||||
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
|
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
|
||||||
|
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
|
||||||
|
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
|
||||||
|
- name: Build and push Docker image
|
||||||
|
id: push
|
||||||
|
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
|
||||||
|
# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)."
|
||||||
|
- name: Generate artifact attestation
|
||||||
|
uses: actions/attest-build-provenance@v1
|
||||||
|
with:
|
||||||
|
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
|
||||||
|
subject-digest: ${{ steps.push.outputs.digest }}
|
||||||
|
push-to-registry: true
|
||||||
|
|
||||||
|
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -7,3 +7,5 @@ DerivedData/
|
|||||||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
|
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
|
||||||
.dewPoint-env
|
.dewPoint-env
|
||||||
.topics
|
.topics
|
||||||
|
mqtt_password.txt
|
||||||
|
.env
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ protocol BufferInitalizable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension Double: BufferInitalizable {
|
extension Double: BufferInitalizable {
|
||||||
|
|
||||||
/// Attempt to create / parse a double from a byte buffer.
|
/// Attempt to create / parse a double from a byte buffer.
|
||||||
init?(buffer: inout ByteBuffer) {
|
init?(buffer: inout ByteBuffer) {
|
||||||
guard let string = buffer.readString(
|
guard let string = buffer.readString(
|
||||||
@@ -61,7 +61,7 @@ extension Result where Success == MQTTPublishInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension Optional where Wrapped == ByteBuffer {
|
extension Optional where Wrapped == ByteBuffer {
|
||||||
|
|
||||||
func parse<T>(as type: T.Type) -> T? where T: BufferInitalizable {
|
func parse<T>(as type: T.Type) -> T? where T: BufferInitalizable {
|
||||||
switch self {
|
switch self {
|
||||||
case var .some(buffer):
|
case var .some(buffer):
|
||||||
@@ -73,14 +73,14 @@ extension Optional where Wrapped == ByteBuffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fileprivate struct TemperatureAndHumiditySensorKeyPathEnvelope {
|
fileprivate struct TemperatureAndHumiditySensorKeyPathEnvelope {
|
||||||
|
|
||||||
let humidityTopic: KeyPath<Topics.Sensors, String>
|
let humidityTopic: KeyPath<Topics.Sensors, String>
|
||||||
let temperatureTopic: KeyPath<Topics.Sensors, String>
|
let temperatureTopic: KeyPath<Topics.Sensors, String>
|
||||||
let temperatureState: WritableKeyPath<State.Sensors, Temperature?>
|
let temperatureState: WritableKeyPath<State.Sensors, Temperature?>
|
||||||
let humidityState: WritableKeyPath<State.Sensors, RelativeHumidity?>
|
let humidityState: WritableKeyPath<State.Sensors, RelativeHumidity?>
|
||||||
|
|
||||||
func addListener(to client: MQTTNIO.MQTTClient, topics: Topics, state: State) {
|
func addListener(to client: MQTTNIO.MQTTClient, topics: Topics, state: State) {
|
||||||
|
|
||||||
let temperatureTopic = topics.sensors[keyPath: temperatureTopic]
|
let temperatureTopic = topics.sensors[keyPath: temperatureTopic]
|
||||||
client.logger.trace("Adding listener for topic: \(temperatureTopic)")
|
client.logger.trace("Adding listener for topic: \(temperatureTopic)")
|
||||||
client.addPublishListener(named: temperatureTopic) { result in
|
client.addPublishListener(named: temperatureTopic) { result in
|
||||||
@@ -90,7 +90,7 @@ fileprivate struct TemperatureAndHumiditySensorKeyPathEnvelope {
|
|||||||
state.sensors[keyPath: temperatureState] = temperature
|
state.sensors[keyPath: temperatureState] = temperature
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let humidityTopic = topics.sensors[keyPath: humidityTopic]
|
let humidityTopic = topics.sensors[keyPath: humidityTopic]
|
||||||
client.logger.trace("Adding listener for topic: \(humidityTopic)")
|
client.logger.trace("Adding listener for topic: \(humidityTopic)")
|
||||||
client.addPublishListener(named: humidityTopic) { result in
|
client.addPublishListener(named: humidityTopic) { result in
|
||||||
@@ -159,7 +159,7 @@ extension State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension Client.SensorPublishRequest {
|
extension Client.SensorPublishRequest {
|
||||||
|
|
||||||
func dewPointData(topics: Topics, units: PsychrometricEnvironment.Units?) -> (DewPoint, String)? {
|
func dewPointData(topics: Topics, units: PsychrometricEnvironment.Units?) -> (DewPoint, String)? {
|
||||||
switch self {
|
switch self {
|
||||||
case let .mixed(sensor):
|
case let .mixed(sensor):
|
||||||
@@ -176,7 +176,7 @@ extension Client.SensorPublishRequest {
|
|||||||
return (dp, topics.sensors.supplyAirSensor.dewPoint)
|
return (dp, topics.sensors.supplyAirSensor.dewPoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func enthalpyData(altitude: Length, topics: Topics, units: PsychrometricEnvironment.Units?) -> (EnthalpyOf<MoistAir>, String)? {
|
func enthalpyData(altitude: Length, topics: Topics, units: PsychrometricEnvironment.Units?) -> (EnthalpyOf<MoistAir>, String)? {
|
||||||
switch self {
|
switch self {
|
||||||
case let .mixed(sensor):
|
case let .mixed(sensor):
|
||||||
@@ -193,7 +193,7 @@ extension Client.SensorPublishRequest {
|
|||||||
return (enthalpy, topics.sensors.supplyAirSensor.enthalpy)
|
return (enthalpy, topics.sensors.supplyAirSensor.enthalpy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setHasProcessed(state: State) {
|
func setHasProcessed(state: State) {
|
||||||
switch self {
|
switch self {
|
||||||
case .mixed:
|
case .mixed:
|
||||||
@@ -209,7 +209,7 @@ extension Client.SensorPublishRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension MQTTNIO.MQTTClient {
|
extension MQTTNIO.MQTTClient {
|
||||||
|
|
||||||
func publishDewPoint(
|
func publishDewPoint(
|
||||||
request: Client.SensorPublishRequest,
|
request: Client.SensorPublishRequest,
|
||||||
state: State,
|
state: State,
|
||||||
@@ -225,7 +225,8 @@ extension MQTTNIO.MQTTClient {
|
|||||||
return publish(
|
return publish(
|
||||||
to: topic,
|
to: topic,
|
||||||
payload: ByteBufferAllocator().buffer(string: "\(roundedDewPoint)"),
|
payload: ByteBufferAllocator().buffer(string: "\(roundedDewPoint)"),
|
||||||
qos: .atLeastOnce
|
qos: .atLeastOnce,
|
||||||
|
retain: true
|
||||||
)
|
)
|
||||||
.map { (self, request, state, topics) }
|
.map { (self, request, state, topics) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
# run this with docker-compose -f docker/docker-compose.yml run test
|
# run this with docker-compose -f docker/docker-compose.yml run test
|
||||||
services:
|
services:
|
||||||
|
server:
|
||||||
|
image: swift-mqtt-dewpoint:latest
|
||||||
|
env_file: .env
|
||||||
|
command: /bin/bash -xc "./dewPoint-controller"
|
||||||
|
|
||||||
test:
|
test:
|
||||||
image: swift:latest
|
image: swift:latest
|
||||||
#build:
|
#build:
|
||||||
@@ -39,3 +44,4 @@ networks:
|
|||||||
test:
|
test:
|
||||||
driver: bridge
|
driver: bridge
|
||||||
external: false
|
external: false
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user