diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..f0b2e162 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,110 @@ +name: vprofile actions +on: workflow_dispatch +env: + AWS_REGION: us-east-1 + ECR_REPOSITORY: vprofileapp + EKS_CLUSTER: vprofile-eks + +jobs: + Testing: + runs-on: ubuntu-latest + steps: + - name: Code checkout + uses: actions/checkout@v4 + + - name: Maven test + run: mvn test + + - name: Checkstyle + run: mvn checkstyle:checkstyle + + # Setup java 11 to be default (sonar-scanner requirement as of 5.x) + - name: Set Java 11 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' # See 'Supported distributions' for available options + java-version: '11' + + # Setup sonar-scanner + - name: Setup SonarQube + uses: warchant/setup-sonar-scanner@v7 + + + # Run sonar-scanner + - name: SonarQube Scan + run: sonar-scanner + -Dsonar.host.url=${{ secrets.SONAR_URL }} + -Dsonar.login=${{ secrets.SONAR_TOKEN }} + -Dsonar.organization=${{ secrets.SONAR_ORGANIZATION }} + -Dsonar.projectKey=${{ secrets.SONAR_PROJECT_KEY }} + -Dsonar.sources=src/ + -Dsonar.junit.reportsPath=target/surefire-reports/ + -Dsonar.jacoco.reportsPath=target/jacoco.exec + -Dsonar.java.checkstyle.reportPaths=target/checkstyle-result.xml + -Dsonar.java.binaries=target/test-classes/com/visualpathit/account/controllerTest/ + + # Check the Quality Gate status. + - name: SonarQube Quality Gate check + id: sonarqube-quality-gate-check + uses: sonarsource/sonarqube-quality-gate-action@master + # Force to fail step after specific time. + timeout-minutes: 5 + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_URL }} #OPTIONAL + + BUILD_AND_PUBLISH: + needs: Testing + runs-on: ubuntu-latest + steps: + - name: Code checkout + uses: actions/checkout@v4 + + - name: Build & Upload image to ECR + uses: appleboy/docker-ecr-action@master + with: + access_key: ${{ secrets.AWS_ACCESS_KEY_ID }} + secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + registry: ${{ secrets.REGISTRY }} + repo: ${{ env.ECR_REPOSITORY }} + region: ${{ env.AWS_REGION }} + tags: latest,${{ github.run_number }} + daemon_off: false + dockerfile: ./Dockerfile + context: ./ + + DeployToEKS: + needs: BUILD_AND_PUBLISH + runs-on: ubuntu-latest + steps: + - name: Code checkout + uses: actions/checkout@v4 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ env.AWS_REGION }} + + - name: Get Kube config file + run: aws eks update-kubeconfig --region ${{ env.AWS_REGION }} --name ${{ env.EKS_CLUSTER }} + + - name: Print config file + run: cat ~/.kube/config + + - name: Login to ECR + run: kubectl create secret docker-registry regcred --docker-server=${{ secrets.REGISTRY }} --docker-username=AWS --docker-password=$(aws ecr get-login-password) + + - name: Deploy Helm + uses: bitovi/github-actions-deploy-eks-helm@v1.2.8 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ env.AWS_REGION }} + cluster-name: ${{ env.EKS_CLUSTER }} + #config-files: .github/values/dev.yaml + chart-path: helm/vprofilecharts + namespace: default + values: appimage=${{ secrets.REGISTRY }}/${{ env.ECR_REPOSITORY }},apptag=${{ github.run_number }} + name: vprofile-stack \ No newline at end of file diff --git a/helm/vprofilecharts/.helmignore b/helm/vprofilecharts/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/helm/vprofilecharts/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/helm/vprofilecharts/Chart.yaml b/helm/vprofilecharts/Chart.yaml new file mode 100644 index 00000000..582281f7 --- /dev/null +++ b/helm/vprofilecharts/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: vprofilecharts +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/helm/vprofilecharts/templates/app-secret.yml b/helm/vprofilecharts/templates/app-secret.yml new file mode 100644 index 00000000..17771a78 --- /dev/null +++ b/helm/vprofilecharts/templates/app-secret.yml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: Secret +metadata: + name: app-secret +type: Opaque +data: + db-pass: dnByb2RicGFzcw== + rmq-pass: Z3Vlc3Q= diff --git a/helm/vprofilecharts/templates/db-CIP.yml b/helm/vprofilecharts/templates/db-CIP.yml new file mode 100644 index 00000000..2ecb8da7 --- /dev/null +++ b/helm/vprofilecharts/templates/db-CIP.yml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: vprodb +spec: + ports: + - port: 3306 + targetPort: vprodb-port + protocol: TCP + selector: + app: vprodb + type: ClusterIP diff --git a/helm/vprofilecharts/templates/mc-CIP.yml b/helm/vprofilecharts/templates/mc-CIP.yml new file mode 100644 index 00000000..ab74ddb7 --- /dev/null +++ b/helm/vprofilecharts/templates/mc-CIP.yml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: vprocache01 +spec: + ports: + - port: 11211 + targetPort: vpromc-port + protocol: TCP + selector: + app: vpromc + type: ClusterIP diff --git a/helm/vprofilecharts/templates/mcdep.yml b/helm/vprofilecharts/templates/mcdep.yml new file mode 100644 index 00000000..d7e1804e --- /dev/null +++ b/helm/vprofilecharts/templates/mcdep.yml @@ -0,0 +1,22 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: vpromc + labels: + app: vpromc +spec: + selector: + matchLabels: + app: vpromc + replicas: 1 + template: + metadata: + labels: + app: vpromc + spec: + containers: + - name: vpromc + image: memcached + ports: + - name: vpromc-port + containerPort: 11211 diff --git a/helm/vprofilecharts/templates/rmq-CIP-service.yml b/helm/vprofilecharts/templates/rmq-CIP-service.yml new file mode 100644 index 00000000..129c6243 --- /dev/null +++ b/helm/vprofilecharts/templates/rmq-CIP-service.yml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: vpromq01 +spec: + ports: + - port: 5672 + targetPort: vpromq01-port + protocol: TCP + selector: + app: vpromq01 + type: ClusterIP diff --git a/helm/vprofilecharts/templates/rmq-dep.yml b/helm/vprofilecharts/templates/rmq-dep.yml new file mode 100644 index 00000000..b8c6ea4a --- /dev/null +++ b/helm/vprofilecharts/templates/rmq-dep.yml @@ -0,0 +1,31 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: vpromq01 + labels: + app: vpromq01 +spec: + selector: + matchLabels: + app: vpromq01 + replicas: 1 + template: + metadata: + labels: + app: vpromq01 + spec: + containers: + - name: vpromq01 + image: rabbitmq + ports: + - name: vpromq01-port + containerPort: 15672 + env: + - name: RABBITMQ_DEFAULT_PASS + valueFrom: + secretKeyRef: + name: app-secret + key: rmq-pass + - name: RABBITMQ_DEFAULT_USER + value: "guest" + diff --git a/helm/vprofilecharts/templates/vproapp-service.yml b/helm/vprofilecharts/templates/vproapp-service.yml new file mode 100644 index 00000000..3c5510cc --- /dev/null +++ b/helm/vprofilecharts/templates/vproapp-service.yml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: my-app +spec: + ports: + - port: 8080 + protocol: TCP + targetPort: 8080 + selector: + app: vproapp + type: ClusterIP diff --git a/helm/vprofilecharts/templates/vproappdep.yml b/helm/vprofilecharts/templates/vproappdep.yml new file mode 100644 index 00000000..79a6b515 --- /dev/null +++ b/helm/vprofilecharts/templates/vproappdep.yml @@ -0,0 +1,29 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: vproapp + labels: + app: vproapp +spec: + replicas: 1 + selector: + matchLabels: + app: vproapp + template: + metadata: + labels: + app: vproapp + spec: + containers: + - name: vproapp + image: vprofile/vprofileapp + ports: + - name: vproapp-port + containerPort: 8080 + initContainers: + - name: init-mydb + image: busybox + command: ['sh', '-c', 'until nslookup vprodb.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mydb; sleep 2; done;'] + - name: init-memcache + image: busybox + command: ['sh', '-c', 'until nslookup vprocache01.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mydb; sleep 2; done;'] diff --git a/helm/vprofilecharts/templates/vprodbdep.yml b/helm/vprofilecharts/templates/vprodbdep.yml new file mode 100644 index 00000000..a11b9e9c --- /dev/null +++ b/helm/vprofilecharts/templates/vprodbdep.yml @@ -0,0 +1,32 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: vprodb + labels: + app: vprodb +spec: + selector: + matchLabels: + app: vprodb + replicas: 1 + template: + metadata: + labels: + app: vprodb + spec: + containers: + - name: vprodb + image: vprofile/vprofiledb + ports: + - name: vprodb-port + containerPort: 3306 + env: + - name: MYSQL_ROOT_PASSWORD + valueFrom: + secretKeyRef: + name: app-secret + key: db-pass +# env: +# - name: MYSQL_ROOT_PASSWORD +# value: "vprodbpass" + diff --git a/helm/vprofilecharts/templates/vproingress.yaml b/helm/vprofilecharts/templates/vproingress.yaml new file mode 100644 index 00000000..1effb9c1 --- /dev/null +++ b/helm/vprofilecharts/templates/vproingress.yaml @@ -0,0 +1,19 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: vpro-ingress + annotations: + nginx.ingress.kubernetes.io/use-regex: "true" +spec: + ingressClassName: nginx + rules: + - host: vprofile.euthy.xyz + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: my-app + port: + number: 8080 diff --git a/helm/vprofilecharts/values.yaml b/helm/vprofilecharts/values.yaml new file mode 100644 index 00000000..df5aff36 --- /dev/null +++ b/helm/vprofilecharts/values.yaml @@ -0,0 +1,107 @@ +# Default values for vprofilecharts. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: nginx + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Automatically mount a ServiceAccount's API credentials? + automount: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} +podLabels: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +livenessProbe: + httpGet: + path: / + port: http +readinessProbe: + httpGet: + path: / + port: http + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +# Additional volumes on the output Deployment definition. +volumes: [] +# - name: foo +# secret: +# secretName: mysecret +# optional: false + +# Additional volumeMounts on the output Deployment definition. +volumeMounts: [] +# - name: foo +# mountPath: "/etc/foo" +# readOnly: true + +nodeSelector: {} + +tolerations: [] + +affinity: {} diff --git a/kubernetes/vpro-app/vproingress.yaml b/kubernetes/vpro-app/vproingress.yaml index 9c6a1cd2..1effb9c1 100644 --- a/kubernetes/vpro-app/vproingress.yaml +++ b/kubernetes/vpro-app/vproingress.yaml @@ -7,7 +7,7 @@ metadata: spec: ingressClassName: nginx rules: - - host: vprofile.thehkh.com + - host: vprofile.euthy.xyz http: paths: - path: /