From f7671c16f3b32df4a3486e9ba7895c0838564427 Mon Sep 17 00:00:00 2001 From: Maduabuchi Date: Mon, 9 Nov 2020 15:54:25 +0100 Subject: [PATCH] prepared code for cicd with jenkins --- .idea/.gitignore | 8 +++ .idea/aws.xml | 17 ++++++ .idea/misc.xml | 30 +++++++++++ .idea/modules.xml | 8 +++ ...ng-security-react-ant-design-polls-app.iml | 10 ++++ .idea/vcs.xml | 6 +++ deployments/kustomization.yaml | 6 +-- deployments/mysql-deployment.yaml | 22 ++++---- deployments/polling-app-server.yaml | 8 +-- docker-compose.yml | 54 +++++++++++++------ polling-app-server/pom.xml | 5 ++ .../src/main/resources/application.properties | 28 ++++++++-- secrets/name | 1 + secrets/passwd | 1 + secrets/url | 1 + secrets/user | 1 + 16 files changed, 167 insertions(+), 39 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/aws.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/spring-security-react-ant-design-polls-app.iml create mode 100644 .idea/vcs.xml create mode 100644 secrets/name create mode 100644 secrets/passwd create mode 100644 secrets/url create mode 100644 secrets/user diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..73f69e09 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/aws.xml b/.idea/aws.xml new file mode 100644 index 00000000..e14a2062 --- /dev/null +++ b/.idea/aws.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..403d16e4 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,30 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..c3e94d0b --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/spring-security-react-ant-design-polls-app.iml b/.idea/spring-security-react-ant-design-polls-app.iml new file mode 100644 index 00000000..0f244380 --- /dev/null +++ b/.idea/spring-security-react-ant-design-polls-app.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/deployments/kustomization.yaml b/deployments/kustomization.yaml index 302245c9..4343e7da 100644 --- a/deployments/kustomization.yaml +++ b/deployments/kustomization.yaml @@ -1,4 +1,4 @@ -# The secrets file should not be checked into Git. It's published only for demonstration purpose. +# The url file should not be checked into Git. It's published only for demonstration purpose. secretGenerator: - name: mysql-root-pass literals: @@ -6,7 +6,7 @@ secretGenerator: - name: mysql-user-pass literals: - username=callicoder - - password=c@ll1c0d3r + - password=c@ll1c0d3r - name: mysql-db-url literals: - database=polls @@ -14,4 +14,4 @@ secretGenerator: resources: - mysql-deployment.yaml - polling-app-server.yaml - - polling-app-client.yaml + - polling-app-client.yaml diff --git a/deployments/mysql-deployment.yaml b/deployments/mysql-deployment.yaml index 143e087f..04ede52a 100644 --- a/deployments/mysql-deployment.yaml +++ b/deployments/mysql-deployment.yaml @@ -5,15 +5,15 @@ metadata: labels: type: local spec: - storageClassName: standard # Storage class. A PV Claim requesting the same storageClass can be bound to this volume. + storageClassName: standard # Storage class. A PV Claim requesting the same storageClass can be bound to this volume. capacity: storage: 250Mi accessModes: - ReadWriteOnce hostPath: # hostPath PersistentVolume is used for development and testing. It uses a file/directory on the Node to emulate network-attached storage path: "/mnt/data" - persistentVolumeReclaimPolicy: Retain # Retain the PersistentVolume even after PersistentVolumeClaim is deleted. The volume is considered “released”. But it is not yet available for another claim because the previous claimant’s data remains on the volume. ---- + persistentVolumeReclaimPolicy: Retain # Retain the PersistentVolume even after PersistentVolumeClaim is deleted. The volume is considered “released”. But it is not yet available for another claim because the previous claimant’s data remains on the volume. +--- apiVersion: v1 kind: PersistentVolumeClaim # Create a PersistentVolumeClaim to request a PersistentVolume storage metadata: # Claim name and labels @@ -29,7 +29,7 @@ spec: # Access mode and resource limits storage: 250Mi --- apiVersion: v1 # API version -kind: Service # Type of kubernetes resource +kind: Service # Type of kubernetes resource metadata: name: polling-app-mysql # Name of the resource labels: # Labels that will be applied to the resource @@ -46,7 +46,7 @@ apiVersion: apps/v1 kind: Deployment # Type of the kubernetes resource metadata: name: polling-app-mysql # Name of the deployment - labels: # Labels applied to this deployment + labels: # Labels applied to this deployment app: polling-app spec: selector: @@ -64,9 +64,9 @@ spec: containers: - image: mysql:5.6 # The container image name: mysql - env: # Environment variables passed to the container - - name: MYSQL_ROOT_PASSWORD - valueFrom: # Read environment variables from kubernetes secrets + env: # Environment variables passed to the container + - name: MYSQL_ROOT_PASSWORD + valueFrom: # Read environment variables from kubernetes url secretKeyRef: name: mysql-root-pass key: password @@ -86,12 +86,12 @@ spec: name: mysql-user-pass key: password ports: - - containerPort: 3306 # The port that the container exposes + - containerPort: 3306 # The port that the container exposes name: mysql volumeMounts: - name: mysql-persistent-storage # This name should match the name specified in `volumes.name` mountPath: /var/lib/mysql - volumes: # A PersistentVolume is mounted as a volume to the Pod + volumes: # A PersistentVolume is mounted as a volume to the Pod - name: mysql-persistent-storage persistentVolumeClaim: - claimName: mysql-pv-claim \ No newline at end of file + claimName: mysql-pv-claim diff --git a/deployments/polling-app-server.yaml b/deployments/polling-app-server.yaml index 70a10758..4c0a258a 100644 --- a/deployments/polling-app-server.yaml +++ b/deployments/polling-app-server.yaml @@ -27,7 +27,7 @@ spec: memory: "200Mi" env: # Environment variables supplied to the Pod - name: SPRING_DATASOURCE_USERNAME # Name of the environment variable - valueFrom: # Get the value of environment variable from kubernetes secrets + valueFrom: # Get the value of environment variable from kubernetes url secretKeyRef: name: mysql-user-pass key: username @@ -44,12 +44,12 @@ spec: --- apiVersion: v1 # API version kind: Service # Type of the kubernetes resource -metadata: +metadata: name: polling-app-server # Name of the kubernetes resource labels: # Labels that will be applied to this resource app: polling-app-server -spec: - type: NodePort # The service will be exposed by opening a Port on each node and proxying it. +spec: + type: NodePort # The service will be exposed by opening a Port on each node and proxying it. selector: app: polling-app-server # The service exposes Pods with label `app=polling-app-server` ports: # Forward incoming connections on port 8080 to the target port 8080 diff --git a/docker-compose.yml b/docker-compose.yml index 7615aae9..581a2b8f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,17 +13,21 @@ services: ports: - "8080:8080" # Forward the exposed port 8080 on the container to port 8080 on the host machine restart: always - depends_on: + depends_on: - db # This service depends on mysql. Start that first. environment: # Pass environment variables to the service - SPRING_DATASOURCE_URL: jdbc:mysql://db:3306/polls?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false - SPRING_DATASOURCE_USERNAME: callicoder - SPRING_DATASOURCE_PASSWORD: callicoder + - SPRING_DATASOURCE_URL_FILE=/run/url/db-url + - SPRING_DATASOURCE_USERNAME_FILE=/run/url/db-user + - SPRING_DATASOURCE_PASSWORD=/run/url.txt/db-passwd + secrets: + - db-url + - db-user + - db-passwd networks: # Networks to join (Services on the same network can communicate with each other using their name) - backend - frontend - # Frontend Service + # Frontend Service app-client: build: context: polling-app-client # Use an image built from the specified dockerfile in the `polling-app-client` directory. @@ -36,29 +40,47 @@ services: depends_on: - app-server networks: - - frontend + - frontend # Database Service (Mysql) db: - image: mysql:5.7 + image: postgres:13 ports: - - "3306:3306" + - "5432:5432" restart: always environment: - MYSQL_DATABASE: polls - MYSQL_USER: callicoder - MYSQL_PASSWORD: callicoder - MYSQL_ROOT_PASSWORD: root + - POSTGRES_DATABASE=/run/url/name + - POSTGRES_USER_FILE=/run/url/user + - POSTGRES_PASSWORD_FILE=/run/url/passwd + secrets: + - name + - user + - passwd volumes: - - db-data:/var/lib/mysql + - db-data:/var/lib/postgresql/data networks: - - backend - + - backend + # Volumes volumes: db-data: +# Secrets +secrets: + db-url: + file: ./secrets/url.txt + db-user: + file: ./secrets/user.txt + db-passwd: + file: ./secrets/passwd.txt + name: + file: ./secrets/name.txt + user: + file: ./secrets/user.txt + passwd: + file: ./secrets/passwd.txt + # Networks to be created to facilitate communication between containers networks: backend: - frontend: \ No newline at end of file + frontend: diff --git a/polling-app-server/pom.xml b/polling-app-server/pom.xml index ab8d0a81..83d32579 100644 --- a/polling-app-server/pom.xml +++ b/polling-app-server/pom.xml @@ -68,6 +68,11 @@ spring-security-test test + + org.postgresql + postgresql + 42.2.16.jre7 + diff --git a/polling-app-server/src/main/resources/application.properties b/polling-app-server/src/main/resources/application.properties index 1863936e..0994c97c 100644 --- a/polling-app-server/src/main/resources/application.properties +++ b/polling-app-server/src/main/resources/application.properties @@ -1,16 +1,34 @@ ## Server Properties -server.port= 8080 +server.port=9090 server.compression.enabled=true ## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties) -spring.datasource.url= jdbc:mysql://localhost:3306/polling_app?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false -spring.datasource.username= root -spring.datasource.password= callicoder + + + +# Database Properties +spring.jpa.database=POSTGRESQL + +spring.datasource.platform=postgres + +#spring.datasource.url=${DATABASE_URL:jdbc:postgresql://localhost:5432/postgres} +#i have to change this url to point to jenkins for testing purpose +spring.datasource.url=${DATABASE_URL:jdbc:postgresql://localhost:5432/dsdb} + +spring.datasource.username=${Username:dssuite} + +spring.datasource.password=${Password:dssuite} + +spring.jpa.show-sql=true + +spring.jpa.generate-ddl=true + +spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true ## Hibernate Properties # The SQL dialect makes Hibernate generate better SQL for the chosen database -spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect +spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQL92Dialect spring.jpa.hibernate.ddl-auto = update ## Hibernate Logging diff --git a/secrets/name b/secrets/name new file mode 100644 index 00000000..f1349944 --- /dev/null +++ b/secrets/name @@ -0,0 +1 @@ +postgres diff --git a/secrets/passwd b/secrets/passwd new file mode 100644 index 00000000..f1349944 --- /dev/null +++ b/secrets/passwd @@ -0,0 +1 @@ +postgres diff --git a/secrets/url b/secrets/url new file mode 100644 index 00000000..4b24cfda --- /dev/null +++ b/secrets/url @@ -0,0 +1 @@ +jdbc:postgresql://db:5432/polls?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false diff --git a/secrets/user b/secrets/user new file mode 100644 index 00000000..f1349944 --- /dev/null +++ b/secrets/user @@ -0,0 +1 @@ +postgres