Skip to content

Commit

Permalink
chore(dp): One postgresql instance in dev/CI
Browse files Browse the repository at this point in the history
Signed-off-by: Tomasz Gromowski <tomasz@freedomfi.com>
  • Loading branch information
sklgromek committed Jun 7, 2022
1 parent 5e606ca commit 33274d7
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 67 deletions.
12 changes: 5 additions & 7 deletions dp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ orc8r_integration_tests: init_orc8r _ci_init cleanup_test_db
dev_integration_tests: init_orc8r _ci_init cleanup_test_db
kubectl delete jobs -l jobName=domain-proxy-db-setup --ignore-not-found=true
kubectl delete pods test-runner-dev --ignore-not-found=true
skaffold dev -p orc8r-deployment,integration-tests-no-orc8,integration-tests-dev --trigger=manual
skaffold dev -p orc8r-deployment,integration-tests-no-orc8,integration-tests-orc8r-only,integration-tests-dev --trigger=manual

.PHONY: orc8r
orc8r: init_orc8r dev_orc8r
Expand Down Expand Up @@ -216,13 +216,11 @@ build_db:

.PHONY: cleanup_test_db
cleanup_test_db: _switch_k8s_context
kubectl exec -it postgres-database-0 \
--container postgres-test -- \
psql -p 5433 -U postgres -c \
kubectl exec -it postgres-database-0 -- \
psql -U postgres -c \
"drop database dp_test with (force);" || true ;\
kubectl exec -it postgres-database-0 \
--container postgres-test -- \
psql -p 5433 -U postgres -c \
kubectl exec -it postgres-database-0 -- \
psql -U postgres -c \
"create database dp_test;" || true;

LOGS_COUNT ?= 1000
Expand Down
3 changes: 3 additions & 0 deletions dp/cloud/docker/postgresql/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM postgres:13.3

COPY --chmod=755 create_magma_dbs.sh /docker-entrypoint-initdb.d/create_magma_dbs.sh
19 changes: 19 additions & 0 deletions dp/cloud/docker/postgresql/create_magma_dbs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# Copyright 2022 The Magma Authors.

# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -e

echo "Creating postgresql DB dp_test"
psql -U "${POSTGRES_USER}" -c "CREATE DATABASE dp_test"
echo "Grant privileges to ${POSTGRES_USER} on dp_test..."
psql -U "${POSTGRES_USER}" -c "GRANT ALL PRIVILEGES ON DATABASE dp_test TO ${POSTGRES_USER}"
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ controller:
database:
driver: postgres # mysql/postgres
sql_dialect: psql # maria/psql
db: dp_test
db: dp
host: db
port: 5433
port: 5432
user: postgres
pass: postgres
service_registry:
Expand Down Expand Up @@ -135,11 +135,11 @@ nms:
service: true
env:
api_host: orc8r-nginx-proxy:443
mysql_db: dp_test
mysql_db: dp
mysql_dialect: postgres
mysql_host: db
mysql_pass: postgres
mysql_port: 5433
mysql_port: 5432
mysql_user: postgres
image:
repository: magmalte
Expand Down
2 changes: 1 addition & 1 deletion dp/cloud/python/magma/db_service/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class TestConfig(Config):
Configuration class for db service
"""
SQLALCHEMY_DB_URI = os.environ.get(
'SQLALCHEMY_DB_URI', 'postgresql+psycopg2://postgres:postgres@db:5433/dp_test',
'SQLALCHEMY_DB_URI', 'postgresql+psycopg2://postgres:postgres@db:5432/dp_test',
)


Expand Down
20 changes: 20 additions & 0 deletions dp/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ build:
context: ..
docker:
dockerfile: orc8r/cloud/docker/fluentd_forward/Dockerfile
- image: dp-postgres
context: ../dp/cloud/docker/postgresql
docker:
dockerfile: ../dp/cloud/docker/postgresql/Dockerfile

deploy:
kubeContext: minikube
Expand Down Expand Up @@ -133,6 +137,20 @@ profiles:
value:
manifests:
- "./tools/deployment/tests/test_runner_deployment_orc8r.yml"
- op: add
path: /deploy/helm/releases/1/overrides
value:
nms:
magmalte:
env:
mysql_db: dp_test
- op: add
path: /deploy/helm/releases/2/overrides
value:
controller:
spec:
database:
db: dp_test
- name: integration-tests-dev
patches:
- op: add
Expand Down Expand Up @@ -267,3 +285,5 @@ profiles:
patches:
- op: remove
path: /build/artifacts/4 # remove fake sas image
- op: remove
path: /build/artifacts/7 # remove postgresql image
57 changes: 2 additions & 55 deletions dp/tools/deployment/vendor/postgresql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ spec:
spec:
containers:
- name: postgres
image: postgres:13.3
image: dp-postgres:latest
imagePullPolicy: IfNotPresent
volumeMounts:
- name: db-disk
mountPath: /var/lib/postgresql/data
Expand Down Expand Up @@ -52,49 +53,6 @@ spec:
successThreshold: 1
timeoutSeconds: 10
failureThreshold: 3
- name: postgres-test
image: postgres:13.3
args:
- -p
- "5433"
volumeMounts:
- name: db-disk2
mountPath: /var/lib/postgresql/data2
env:
- name: POSTGRES_DB
value: "dp_test"
- name: POSTGRES_PASSWORD
value: postgres
- name: PGDATA
value: /var/lib/postgresql/data2/pgdata
livenessProbe:
exec:
command:
- /usr/bin/pg_isready
- -U
- "postgres"
- "--port=5433"
- -h
- 127.0.0.1
failureThreshold: 3
initialDelaySeconds: 20
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 10
readinessProbe:
exec:
command:
- /usr/bin/pg_isready
- -U
- "postgres"
- "--port=5433"
- -h
- 127.0.0.1
initialDelaySeconds: 30
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 10
failureThreshold: 3
volumeClaimTemplates:
- metadata:
name: db-disk
Expand All @@ -103,16 +61,8 @@ spec:
resources:
requests:
storage: 1Gi
- metadata:
name: db-disk2
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi

---

apiVersion: v1
kind: Service
metadata:
Expand All @@ -125,6 +75,3 @@ spec:
- name: db1
port: 5432
targetPort: 5432
- name: db2
port: 5433
targetPort: 5433

0 comments on commit 33274d7

Please sign in to comment.