-
Notifications
You must be signed in to change notification settings - Fork 10
190 lines (167 loc) · 6.47 KB
/
uns_graphql-app.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: UNS GraphQL Client
on:
push:
branches:
- "**"
paths:
- "02_mqtt-cluster/**/*.py*"
- "02_mqtt-cluster/pyproject.toml"
- "02_mqtt-cluster/poetry.lock"
- "07_uns_graphql/**/*.py"
- "07_uns_graphql/pyproject.toml"
- "07_uns_graphql/poetry.lock"
- "07_uns_graphql/Dockerfile"
- ".github/workflows/uns_graphql-app.yml"
- ".github/include/**"
pull_request:
branches:
- "**"
paths:
- "02_mqtt-cluster/**/*.py*"
- "02_mqtt-cluster/pyproject.toml"
- "02_mqtt-cluster/poetry.lock"
- "07_uns_graphql/**/*.py"
- "07_uns_graphql/pyproject.toml"
- "07_uns_graphql/poetry.lock"
- "07_uns_graphql/Dockerfile"
- ".github/workflows/uns_graphql-app.yml"
- ".github/include/**"
workflow_dispatch:
inputs:
pytest_add_opts: # trunk-ignore(checkov/CKV_GHA_7)
description: "additional pytest options"
type: string
permissions:
contents: read
jobs:
generate_random_password:
runs-on: ubuntu-latest
outputs:
neo4j_pwd: ${{ steps.random_strings.outputs.neo4j_pwd}}
# trunk-ignore(actionlint/expression)
postgres_pwd: ${{ steps.random_strings.outputs.postgres_pwd }}
uns_historian_pwd: ${{ steps.random_strings.outputs.uns_historian_pwd}}
steps:
- id: random_strings
run: |
echo "neo4j_pwd=$(openssl rand -base64 32 | tr -dc '[:alnum:]')" >> $GITHUB_OUTPUT
echo "postgres_pwd=$(openssl rand -base64 32 | tr -dc '[:alnum:]')" >> $GITHUB_OUTPUT
echo "uns_historian_pwd=$(openssl rand -base64 32 | tr -dc '[:alnum:]')" >> $GITHUB_OUTPUT
build_code:
runs-on: ubuntu-latest
needs: generate_random_password
environment: dev
env:
UNS_mqtt__host: "localhost"
UNS_mqtt__port: 1883
UNS_graphdb__url: "bolt://localhost:7687"
UNS_graphdb__username: "neo4j"
UNS_graphdb__password: ${{ needs.generate_random_password.outputs.neo4j_pwd }}
UNS_historian__hostname: "localhost"
UNS_historian__database: "uns_historian"
UNS_historian__table: "unifiednamespace"
UNS_historian__username: "uns_dbuser"
UNS_historian__password: ${{ needs.generate_random_password.outputs.uns_historian_pwd }}
POSTGRES_PASSWORD: ${{ needs.generate_random_password.outputs.postgres_pwd }}
UNS_kafka.config: "{ 'group.id' = 'uns_graphql', 'client.id' = 'uns_graphql_client', 'bootstrap.servers' ='localhost:9092' }"
services:
uns_mqtt:
image: "emqx/emqx:latest"
ports:
- "1883:1883"
uns_graphdb:
image: "neo4j:latest"
ports:
- "7474:7474"
- "7687:7687"
env:
NEO4J_AUTH: neo4j/${{ env.UNS_graphdb__password }}
apoc.export.file.enabled: true
apoc.import.file.enabled: true
apoc.import.file.use_neo4j_config: true
NEO4J_PLUGINS: '["apoc"]'
uns_timescaledb:
image: "timescale/timescaledb:latest-pg16"
ports:
- "5432:5432"
env:
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
uns_kafka:
image: "bitnami/kafka:latest"
ports:
- "9092:9092"
env:
ALLOW_PLAINTEXT_LISTENER: "yes"
KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://localhost:9092"
KAFKA_CFG_NODE_ID: 0
KAFKA_CFG_PROCESS_ROLES: controller,broker
KAFKA_CFG_LISTENERS: "PLAINTEXT://:9092,CONTROLLER://:9093"
KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: "CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT"
KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: "0@uns_kafka:9093"
KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER
steps:
- uses: actions/checkout@v4
- name: Setup with python environment
uses: ./.github/include/setup_python/
with:
module: 07_uns_graphql
- name: Create Database for Integration Testing
env:
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
UNS_historian__password: ${{ env.UNS_historian__password }}
run: |
echo "CREATE database $UNS_historian__database;
\c $UNS_historian__database;
CREATE EXTENSION IF NOT EXISTS timescaledb;
CREATE ROLE $UNS_historian__username
LOGIN
PASSWORD '$UNS_historian__password';
ALTER DATABASE $UNS_historian__database OWNER TO $UNS_historian__username;
" | PGPASSWORD=${POSTGRES_PASSWORD} psql -h ${UNS_historian__hostname} -U postgres -p 5432
echo "CREATE TABLE $UNS_historian__table (
time TIMESTAMPTZ NOT NULL,
topic text NOT NULL,
client_id text,
mqtt_msg JSONB,
CONSTRAINT unique_event UNIQUE (time, topic, client_id, mqtt_msg)
);
SELECT create_hypertable('$UNS_historian__table', 'time');
" | PGPASSWORD=${UNS_historian__password} psql -h ${UNS_historian__hostname} -U $UNS_historian__username -d $UNS_historian__database -p 5432
- name: Run all type of tests
uses: ./.github/include/execute_tests/
timeout-minutes: 3
with:
module: 07_uns_graphql
integration_tests: true
SAFETY_API_KEY: ${{ secrets.SAFETY_API_KEY }}
pytest_flags: ${{ inputs.pytest_add_opts }}
- name: Create graphQL schema
env:
schema_file: "./schema/uns_schema.graphql"
run: |
cd 07_uns_graphql
# create the schema
poetry run strawberry export-schema \
uns_graphql.uns_graphql_app:UNSGraphql.schema \
--output $schema_file
if git diff --quiet -- "$schema_file"; then
echo "Schema Unchanged"
else
# check in the modified file
git config --global user.email "actions@github.com"
git config --global user.name "Github Actions"
# Ensure that this check-in does not triggering another build
git add $schema_file
git commit -m "updated schema file for graphql api"
fi
build_docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Compile and Test Dockerfile
uses: ./.github/include/test_docker_builds/
with:
module: 07_uns_graphql
image_name: uns/graphql