deployment
This commit is contained in:
parent
defee32084
commit
04b0218280
28
.woodpecker.yml
Normal file
28
.woodpecker.yml
Normal file
@ -0,0 +1,28 @@
|
||||
steps:
|
||||
build:
|
||||
image: plugins/kaniko
|
||||
settings:
|
||||
repo: ${FORGE_NAME}/${CI_REPO}
|
||||
registry:
|
||||
from_secret: container_registry
|
||||
tags: latest,${CI_COMMIT_SHA},${CI_COMMIT_TAG}
|
||||
username:
|
||||
from_secret: container_registry_username
|
||||
password:
|
||||
from_secret: container_registry_password
|
||||
dockerfile: Dockerfile
|
||||
when:
|
||||
- event: [push, tag]
|
||||
|
||||
deploy:
|
||||
image: portainer/kubectl-shell:latest
|
||||
secrets:
|
||||
- source: kube_config
|
||||
target: KUBE_CONFIG_CONTENT
|
||||
commands:
|
||||
- export IMAGE_TAG=$CI_COMMIT_TAG
|
||||
- printf "$KUBE_CONFIG_CONTENT" > /tmp/kubeconfig
|
||||
- export KUBECONFIG=/tmp/kubeconfig
|
||||
- ./deployment/deploy.sh
|
||||
when:
|
||||
- event: tag
|
15
Dockerfile
Normal file
15
Dockerfile
Normal file
@ -0,0 +1,15 @@
|
||||
FROM golang:1.22.5-alpine3.20 as builder
|
||||
|
||||
RUN mkdir -p /go/src
|
||||
COPY ./src/ /go/src
|
||||
WORKDIR /go/src/ma
|
||||
RUN go build -a -installsuffix nocgo -o ma main.go
|
||||
|
||||
|
||||
FROM scratch
|
||||
|
||||
ENV MA_CONF ""
|
||||
|
||||
COPY --from=builder /go/src/ma ./
|
||||
ENTRYPOINT ["./ma"]
|
||||
|
@ -1,7 +1,11 @@
|
||||
N=homea
|
||||
|
||||
PGHOST=`kubectl get services traefik -n system -o jsonpath="{.status.loadBalancer.ingress[0].ip}"`
|
||||
PGPASSWORD=`kubectl get secrets ma-db-cred -n $N -o jsonpath="{.data.PGPASSWORD}" | base64 --decode`
|
||||
PGUSER=`kubectl get secrets ma-db-cred -n $N -o jsonpath="{.data.PGUSER}" | base64 --decode`
|
||||
PGSSLMODE=`kubectl get secrets ma-db-cred -n $N -o jsonpath="{.data.PGSSLMODE}" | base64 --decode`
|
||||
PGDATABASE="matest"
|
||||
export PGUSER PGHOST PGPASSWORD PGSSLMODE PGDATABASE
|
||||
|
||||
MA_CONF=`cat config-test.json`
|
||||
export MA_CONF
|
||||
|
@ -6,8 +6,10 @@
|
||||
"includeTopics": [
|
||||
"#"
|
||||
],
|
||||
"includeTopics": [
|
||||
"mainscnt/#"
|
||||
"excludeTopics": [
|
||||
"IoT/Watchdog",
|
||||
"snmp",
|
||||
"MainsCnt/#",
|
||||
"cem/#"
|
||||
]
|
||||
}
|
||||
|
28
deployment/deploy-yml.tmpl
Normal file
28
deployment/deploy-yml.tmpl
Normal file
@ -0,0 +1,28 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: ma
|
||||
labels:
|
||||
app: ma
|
||||
annotations:
|
||||
secret.reloader.stakater.com/reload: ma-db-cred
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: ma
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: ma
|
||||
spec:
|
||||
containers:
|
||||
- name: ma
|
||||
image: %IMAGE%
|
||||
imagePullPolicy: Always
|
||||
envFrom:
|
||||
- secretRef:
|
||||
name: ma-db-cred
|
||||
- configMapRef:
|
||||
name: ma-conf
|
||||
|
29
deployment/deploy.sh
Executable file
29
deployment/deploy.sh
Executable file
@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
|
||||
ARG1=$1
|
||||
NAMESPACE=`cat namespace`
|
||||
IMAGE_NAME=$FORGE_NAME/$CI_REPO
|
||||
|
||||
DEPLOYMENT_DIR=$PWD/deployment
|
||||
|
||||
|
||||
|
||||
pushd $DEPLOYMENT_DIR > /dev/null
|
||||
|
||||
./roll-db-credential.sh
|
||||
|
||||
kubectl create configmap ma-conf \
|
||||
--from-literal=MA_CONF="`cat config.json`" \
|
||||
--dry-run=client \
|
||||
--o yaml \
|
||||
--save-config | \
|
||||
kubectl apply -f - -n $NAMESPACE
|
||||
|
||||
cat deploy-yml.tmpl | \
|
||||
sed -e 's,%IMAGE%,'$IMAGE_NAME':'$IMAGE_TAG','g | \
|
||||
kubectl apply -f - -n $NAMESPACE
|
||||
|
||||
|
||||
popd /dev/null
|
1
deployment/namespace
Normal file
1
deployment/namespace
Normal file
@ -0,0 +1 @@
|
||||
homea
|
@ -9,7 +9,7 @@ export PGSSLMODE=require
|
||||
DATABASE=ma
|
||||
LOGIN=ma
|
||||
PASSWORD=`openssl rand -base64 24`
|
||||
NAMESPACE=homea
|
||||
NAMESPACE=`cat namespace`
|
||||
|
||||
psql <<EOF
|
||||
do
|
||||
|
@ -10,9 +10,12 @@ import "ma/mqtt"
|
||||
import "ma/counter"
|
||||
import "ma/database"
|
||||
|
||||
var dbh *database.DatabaseHandle
|
||||
|
||||
|
||||
func InitArchiver() {
|
||||
log.Printf("Archiver initializing")
|
||||
dbh = database.NewDatabaseHandle()
|
||||
}
|
||||
|
||||
func InputArchiver() {
|
||||
@ -27,6 +30,7 @@ func InputArchiver() {
|
||||
|
||||
func handleMessage(message database.Message) {
|
||||
log.Printf("Archiving Timestamp: %s, Topic: %s, Payload: %s", message.Time, message.Topic, message.Payload)
|
||||
dbh.StoreMessage(&message)
|
||||
counter.S("Stored")
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user