Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepared code for cicd with jenkins #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/aws.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/spring-security-react-ant-design-polls-app.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions deployments/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# 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:
- password=R00t
- name: mysql-user-pass
literals:
- username=callicoder
- password=c@ll1c0d3r
- password=c@ll1c0d3r
- name: mysql-db-url
literals:
- database=polls
- url=jdbc:mysql://polling-app-mysql:3306/polls?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
resources:
- mysql-deployment.yaml
- polling-app-server.yaml
- polling-app-client.yaml
- polling-app-client.yaml
22 changes: 11 additions & 11 deletions deployments/mysql-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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
claimName: mysql-pv-claim
8 changes: 4 additions & 4 deletions deployments/polling-app-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
54 changes: 38 additions & 16 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
frontend:
5 changes: 5 additions & 0 deletions polling-app-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.16.jre7</version>
</dependency>
</dependencies>

<build>
Expand Down
28 changes: 23 additions & 5 deletions polling-app-server/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions secrets/name
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
postgres
1 change: 1 addition & 0 deletions secrets/passwd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
postgres
1 change: 1 addition & 0 deletions secrets/url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jdbc:postgresql://db:5432/polls?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
1 change: 1 addition & 0 deletions secrets/user
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
postgres