diff --git a/.github/workflows/infracost.yaml b/.github/workflows/infracost.yaml new file mode 100644 index 0000000..63142f0 --- /dev/null +++ b/.github/workflows/infracost.yaml @@ -0,0 +1,80 @@ +# The GitHub Actions docs (https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#on) +# describe other options for 'on', 'pull_request' is a good default. +on: [pull_request] +env: + # If you use private modules you'll need this env variable to use + # the same ssh-agent socket value across all jobs & steps. + SSH_AUTH_SOCK: /tmp/ssh_agent.sock +jobs: + infracost: + name: Infracost + runs-on: ubuntu-latest + permissions: + contents: read + # Required to post comments + pull-requests: write + + env: + TF_ROOT: examples/terraform-project/code + # If you're using Terraform Cloud/Enterprise and have variables or private modules stored + # on there, specify the following to automatically retrieve the variables: + # INFRACOST_TERRAFORM_CLOUD_TOKEN: ${{ secrets.TFC_TOKEN }} + # INFRACOST_TERRAFORM_CLOUD_HOST: app.terraform.io # Change this if you're using Terraform Enterprise + + steps: + # If you use private modules, add an environment variable or secret + # called GIT_SSH_KEY with your private key, so Infracost can access + # private repositories (similar to how Terraform/Terragrunt does). + # - name: add GIT_SSH_KEY + # run: | + # ssh-agent -a $SSH_AUTH_SOCK + # mkdir -p ~/.ssh + # echo "${{ secrets.GIT_SSH_KEY }}" | tr -d '\r' | ssh-add - + # ssh-keyscan github.com >> ~/.ssh/known_hosts + + - name: Setup Infracost + uses: infracost/actions/setup@v2 + # See https://github.com/infracost/actions/tree/master/setup for other inputs + # If you can't use this action, see Docker images in https://infracost.io/cicd + with: + api-key: ${{ secrets.INFRACOST_API_KEY }} + + # Checkout the base branch of the pull request (e.g. main/master). + - name: Checkout base branch + uses: actions/checkout@v3 + with: + ref: '${{ github.event.pull_request.base.ref }}' + + # Generate Infracost JSON file as the baseline. + - name: Generate Infracost cost estimate baseline + run: | + infracost breakdown --path=${TF_ROOT} \ + --format=json \ + --out-file=/tmp/infracost-base.json + + # Checkout the current PR branch so we can create a diff. + - name: Checkout PR branch + uses: actions/checkout@v3 + + # Generate an Infracost diff and save it to a JSON file. + - name: Generate Infracost diff + run: | + infracost diff --path=${TF_ROOT} \ + --format=json \ + --compare-to=/tmp/infracost-base.json \ + --out-file=/tmp/infracost.json + + # Posts a comment to the PR using the 'update' behavior. + # This creates a single comment and updates it. The "quietest" option. + # The other valid behaviors are: + # delete-and-new - Delete previous comments and create a new one. + # hide-and-new - Minimize previous comments and create a new one. + # new - Create a new cost estimate comment on every push. + # See https://www.infracost.io/docs/features/cli_commands/#comment-on-pull-requests for other options. + - name: Post Infracost comment + run: | + infracost comment github --path=/tmp/infracost.json \ + --repo=$GITHUB_REPOSITORY \ + --github-token=${{github.token}} \ + --pull-request=${{github.event.pull_request.number}} \ + --behavior=update diff --git a/Dockerfile b/Dockerfile index 286d795..9b35904 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,8 @@ FROM python:3.7.5 WORKDIR /app COPY . . -RUN pip install flask -RUN python -m pip install -r requirements.txt +RUN pip install flask +RUN python -m pip install -r requirements.txt ENV FLASK_APP=main.py ENV FLASK_ENV=development diff --git a/docker-compose.yaml b/docker-compose.yaml index ba7e664..82173c5 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -14,19 +14,22 @@ services: - 3305:3306 restart: on-failure volumes: - - mariadb:/var/lib/mysql - # command: flask run - + - mariadb-notes:/var/lib/mysql app: + image: python_app build: . + environment: + DB_HOST: db + DB_PORT: '3306' + DB_NAME: note + DB_USERNAME: note + DB_PASSWORD: note ports: - 5001:5000 depends_on: - db - - - + volumes: - mariadb: + mariadb-notes: driver: local diff --git a/flask-depl.yaml b/flask-depl.yaml new file mode 100644 index 0000000..5f7f42f --- /dev/null +++ b/flask-depl.yaml @@ -0,0 +1,214 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: flask-app + labels: + app: flask +spec: + replicas: 1 + selector: + matchLabels: + app: flask + template: + metadata: + labels: + app: flask + spec: + # nodeName: luna.pride.improwised.dev + # initContainers: + # - command: ["flask", "db", "upgrade"] + # image: ankitjilka31/flask-note:1.2.2 + # name: flask-migrate + # envFrom: + # - configMapRef: + # name: db-config + # - secretRef: + # name: maria-secret + # # env: + # # - name: DB_HOST + # # value: maria-service + + # # - name: DB_NAME + # # value: mydb + + # # - name: DB_USERNAME + # # value: hello + + # # - name: DB_PASSWORD + # # value: hello + + # # - name: DB_PORT + # # value: '3306' + + # # - name: PORT + # # value: '5000' + + containers: + - name: flask-container + image: ankitjilka31/flask-note:1.3 + ports: + - containerPort: 5000 + envFrom: + - configMapRef: + name: db-config + - secretRef: + name: maria-secret + + # env: + # - name: DB_USERNAME + # valueFrom: + # secretKeyRef: + # name: maria-secret + # key: MARIADB_USER + # - name: DB_PASSWORD + # valueFrom: + # secretKeyRef: + # name: maria-secret + # key: MARIADB_PASSWORD + # - name: DB_HOST + # valueFrom : + # configMapKeyRef : + # name : db-config + # key : host + # - name: DB_NAME + # valueFrom : + # configMapKeyRef : + # name : db-config + # key : dbName + # - name: DB_USERNAME + # valueFrom: + # secretKeyRef: + # name: maria-secret + # key: maria-username + # - name: DB_PASSWORD + # valueFrom: + # secretKeyRef: + # name: maria-secret + # key: maria-password + # - name: DB_PORT + # valueFrom : + # configMapKeyRef : + # name : db-config + # key : dbPort + # - name: PORT + # valueFrom : + # configMapKeyRef : + # name : db-config + # key : port + + # - name: DB_HOST + # value: maria-service + + # - name: DB_NAME + # value: mydb + + # - name: DB_USERNAME + # value: hello + + # - name: DB_PASSWORD + # value: hello + + # - name: DB_PORT + # value: '3306' + + # - name: PORT + # value: '5000' + +--- + +apiVersion: v1 +kind: Service +metadata: + name: flask-app-service +spec: + selector: + app: flask + type: LoadBalancer + ports: + - protocol: TCP + port: 8081 + targetPort: 5000 + + + +--- + + +apiVersion: batch/v1 +kind: Job +metadata: + name: db-up-job +spec: + ttlSecondsAfterFinished: 0 + template: + spec: + nodeName: luna.pride.improwised.dev + containers: + - name: flask-container + image: ankitjilka31/flask-note:1.3.0 + command: ["flask", "db", "upgrade"] + + + envFrom: + - configMapRef: + name: db-config + - secretRef: + name: maria-secret + + # env: + # - name: DB_HOST + # value: maria-service + + # - name: DB_NAME + # value: mydb + + # - name: DB_USERNAME + # value: hello + + # - name: DB_PASSWORD + # value: hello + + # - name: DB_PORT + # value: '3306' + + # - name: PORT + # value: '5000' + + + restartPolicy: Never + + # env: + # - name: DB_HOST + # valueFrom : + # configMapKeyRef : + # name : db-config + # key : DB_HOST + # - name: DB_NAME + # valueFrom : + # configMapKeyRef : + # name : db-config + # key : DB_NAME + # - name: DB_USERNAME + # valueFrom: + # secretKeyRef: + # name: maria-secret + # key: MARIADB_USER + # - name: DB_PASSWORD + # valueFrom: + # secretKeyRef: + # name: maria-secret + # key: MARIADB_PASSWORD + # - name: DB_PORT + # valueFrom : + # configMapKeyRef : + # name : db-config + # key : DB_PORT + # - name: PORT + # valueFrom : + # configMapKeyRef : + # name : db-config + # key : PORT + + + + diff --git a/ingress-single.yaml b/ingress-single.yaml new file mode 100644 index 0000000..116b4f9 --- /dev/null +++ b/ingress-single.yaml @@ -0,0 +1,29 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-ex + annotations: + ingress.kubernetes.io/ssl-redirect: "false" +spec: + ingressClassName: traefik + rules: + - host: "myapps.com" + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: flask-app-service + port: + number: 8081 + - host: "myappskhush.com" + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: appservice + port: + number: 80 diff --git a/kubernetes/flask-depl.yaml b/kubernetes/flask-depl.yaml new file mode 100644 index 0000000..10c26cb --- /dev/null +++ b/kubernetes/flask-depl.yaml @@ -0,0 +1,77 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: flask-app + labels: + app: flask +spec: + replicas: 1 + selector: + matchLabels: + app: flask + template: + metadata: + labels: + app: flask + spec: + initContainers: + - command: ["flask", "db", "upgrade"] + image: ankitjilka31/flask-note:1.2.2 + name: flask-migrate + env: + - name: DB_HOST + value: maria-service + + - name: DB_NAME + value: mydb + + - name: DB_USERNAME + value: toor + + - name: DB_PASSWORD + value: toor + + - name: DB_PORT + value: '3306' + + - name: PORT + value: '5000' + + containers: + - name: flask-container + image: ankitjilka31/flask-note:1.2.2 + ports: + - containerPort: 5000 + env: + - name: DB_HOST + value: maria-service + + - name: DB_NAME + value: mydb + + - name: DB_USERNAME + value: toor + + - name: DB_PASSWORD + value: toor + + - name: DB_PORT + value: '3306' + + - name: PORT + value: '5000' + +--- +apiVersion: v1 +kind: Service +metadata: + name: flask-app-service +spec: + selector: + app: flask + type: NodePort + ports: + - protocol: TCP + port: 8081 + targetPort: 5000 + nodePort: 32222 \ No newline at end of file diff --git a/kubernetes/mariadb.yaml b/kubernetes/mariadb.yaml new file mode 100644 index 0000000..e6d9ccd --- /dev/null +++ b/kubernetes/mariadb.yaml @@ -0,0 +1,54 @@ + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mariadb-depl + labels: + app: mydb +spec: + replicas: 1 + selector: + matchLabels: + app: maria + strategy: + type: Recreate + template: + metadata: + labels: + app: maria + spec: + containers: + - name: mariadb-container + image: mariadb + ports: + - containerPort: 3306 + env: + - name: MARIADB_ROOT_PASSWORD + value: toor + - name: MARIADB_DATABASE + value: mydb + - name: MARIADB_USER + value: toor + - name: MARIADB_PASSWORD + value: toor + volumeMounts: + - mountPath: /data/db + name: maria-volume + volumes: + - name: maria-volume + hostPath: + path: /data + +--- + +apiVersion: v1 +kind: Service +metadata: + name: maria-service +spec: + selector: + app: maria + ports: + - protocol: TCP + port: 3306 + targetPort: 3306 \ No newline at end of file diff --git a/kustomize/flask-depl.yaml b/kustomize/flask-depl.yaml new file mode 100644 index 0000000..8921b18 --- /dev/null +++ b/kustomize/flask-depl.yaml @@ -0,0 +1,145 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: flask-app + # namespace: ankit + labels: + app: flask +spec: + replicas: 1 + selector: + matchLabels: + app: flask + template: + metadata: + labels: + app: flask + spec: + # nodeName: luna.pride.improwised.dev + # initContainers: + # - command: ["flask", "db", "upgrade"] + # image: ankitjilka31/flask-note:1.2.2 + # name: flask-migrate + # envFrom: + # - configMapRef: + # name: db-config + # - secretRef: + # name: maria-secret + # # env: + # # - name: DB_HOST + # # value: maria-service + + # # - name: DB_NAME + # # value: mydb + + # # - name: DB_USERNAME + # # value: hello + + # # - name: DB_PASSWORD + # # value: hello + + # # - name: DB_PORT + # # value: '3306' + + # # - name: PORT + # # value: '5000' + + containers: + - name: flask-container + image: ankitjilka31/flask-note:1.3 + ports: + - containerPort: 5000 + envFrom: + - configMapRef: + name: db-config + - secretRef: + name: maria-secret + + # env: + # - name: DB_USERNAME + # valueFrom: + # secretKeyRef: + # name: maria-secret + # key: MARIADB_USER + # - name: DB_PASSWORD + # valueFrom: + # secretKeyRef: + # name: maria-secret + # key: MARIADB_PASSWORD + # - name: DB_HOST + # valueFrom : + # configMapKeyRef : + # name : db-config + # key : host + # - name: DB_NAME + # valueFrom : + # configMapKeyRef : + # name : db-config + # key : dbName + # - name: DB_USERNAME + # valueFrom: + # secretKeyRef: + # name: maria-secret + # key: maria-username + # - name: DB_PASSWORD + # valueFrom: + # secretKeyRef: + # name: maria-secret + # key: maria-password + # - name: DB_PORT + # valueFrom : + # configMapKeyRef : + # name : db-config + # key : dbPort + # - name: PORT + # valueFrom : + # configMapKeyRef : + # name : db-config + # key : port + + # - name: DB_HOST + # value: maria-service + + # - name: DB_NAME + # value: mydb + + # - name: DB_USERNAME + # value: hello + + # - name: DB_PASSWORD + # value: hello + + # - name: DB_PORT + # value: '3306' + + # - name: PORT + # value: '5000' + +--- + +apiVersion: v1 +kind: Service +metadata: + name: flask-app-service + # namespace: ankit + labels: + app: flasksvc + annotations: + velero.io/retain-clusterip: "true" + +spec: + selector: + app: flask + type: LoadBalancer + ports: + - protocol: TCP + port: 8081 + targetPort: 5000 + + + + + + + + diff --git a/kustomize/ingress-single.yaml b/kustomize/ingress-single.yaml new file mode 100644 index 0000000..a6bd22b --- /dev/null +++ b/kustomize/ingress-single.yaml @@ -0,0 +1,30 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-ex + # namespace: ankit + annotations: + ingress.kubernetes.io/ssl-redirect: "false" +spec: + ingressClassName: traefik + rules: + - host: "myapps.com" + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: flask-app-service + port: + number: 8081 + - host: "myappskhush.com" + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: appservice + port: + number: 80 diff --git a/kustomize/maria-config.yaml b/kustomize/maria-config.yaml new file mode 100644 index 0000000..cf01bc5 --- /dev/null +++ b/kustomize/maria-config.yaml @@ -0,0 +1,15 @@ +apiVersion : v1 +kind : ConfigMap +metadata: + name : db-config + # namespace: ankit + labels: + app: confg +data: + DB_HOST: maria-service + DB_NAME: mydb + DB_PORT: '3306' + PORT: '5000' + MARIADB_DATABASE: mydb + MARIADB_USER: hello + diff --git a/kustomize/maria-secret.yaml b/kustomize/maria-secret.yaml new file mode 100644 index 0000000..9d2aacd --- /dev/null +++ b/kustomize/maria-secret.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Secret +metadata: + name: maria-secret + # namespace: ankit + labels: + app: scrts +type: Opaque +stringData: + MARIADB_ROOT_PASSWORD: "hello" + MARIADB_PASSWORD: "hello" + DB_USERNAME: "hello" + DB_PASSWORD: "hello" \ No newline at end of file diff --git a/kustomize/mariadb.yaml b/kustomize/mariadb.yaml new file mode 100644 index 0000000..048b59d --- /dev/null +++ b/kustomize/mariadb.yaml @@ -0,0 +1,144 @@ + +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: mariadb-depl + # namespace: ankit + labels: + app: maria +spec: + replicas: 1 + selector: + matchLabels: + app: maria + template: + metadata: + labels: + app: maria + spec: + # nodeSelector: + # name: ankit + containers: + - name: mariadb-container + image: mariadb + ports: + - containerPort: 3306 + envFrom: + - configMapRef: + name: db-config + - secretRef: + name: maria-secret + volumeMounts: + - mountPath: /var/lib/mysql + name: maria-volume + volumeClaimTemplates: + - metadata: + name: maria-volume + # reclaimPolicy: Retain + spec: + accessModes: [ "ReadWriteOnce" ] + storageClassName: "local-path" + + resources: + requests: + storage: 1Gi + +--- + +apiVersion: v1 +kind: Service +metadata: + name: maria-service + # namespace: ankit + labels: + app: mariasvc + annotations: + velero.io/retain-clusterip: "true" +spec: + selector: + app: maria + ports: + - protocol: TCP + port: 3306 + targetPort: 3306 + +--- + + +apiVersion: batch/v1 +kind: Job +metadata: + name: db-up-job + # namespace: ankit + labels: + app: dbjob +spec: + # ttlSecondsAfterFinished: 0 + template: + spec: + nodeName: luna.pride.improwised.dev + containers: + - name: flask-container + image: ankitjilka31/flask-note:1.3 + command: ["flask", "db", "upgrade"] + + + envFrom: + - configMapRef: + name: db-config + - secretRef: + name: maria-secret + + # env: + # - name: DB_HOST + # value: maria-service + + # - name: DB_NAME + # value: mydb + + # - name: DB_USERNAME + # value: hello + + # - name: DB_PASSWORD + # value: hello + + # - name: DB_PORT + # value: '3306' + + # - name: PORT + # value: '5000' + + + restartPolicy: Never + + # env: + # - name: DB_HOST + # valueFrom : + # configMapKeyRef : + # name : db-config + # key : DB_HOST + # - name: DB_NAME + # valueFrom : + # configMapKeyRef : + # name : db-config + # key : DB_NAME + # - name: DB_USERNAME + # valueFrom: + # secretKeyRef: + # name: maria-secret + # key: MARIADB_USER + # - name: DB_PASSWORD + # valueFrom: + # secretKeyRef: + # name: maria-secret + # key: MARIADB_PASSWORD + # - name: DB_PORT + # valueFrom : + # configMapKeyRef : + # name : db-config + # key : DB_PORT + # - name: PORT + # valueFrom : + # configMapKeyRef : + # name : db-config + # key : PORT diff --git a/main.py b/main.py index b5c181a..e568f8a 100644 --- a/main.py +++ b/main.py @@ -1,8 +1,7 @@ from website import create_app -import os -port = os.environ.get('PORT') | "5000" app = create_app() if __name__ == '__main__': - app.run(debug=True, port=port) + app.run(debug=True,) + diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..cfda5d6 --- /dev/null +++ b/main.tf @@ -0,0 +1,18 @@ +provider "aws" { + region = "us-east-1" + skip_credentials_validation = true + skip_requesting_account_id = true + access_key = "mock_access_key" + secret_key = "mock_secret_key" +} + +module "base" { + source = "../modules/example" + + instance_type = "t2.micro" + root_block_device_volume_size = 50 + block_device_volume_size = 100 + block_device_iops = 400 + + hello_world_function_memory_size = 512 +} diff --git a/maria-config.yaml b/maria-config.yaml new file mode 100644 index 0000000..9a46316 --- /dev/null +++ b/maria-config.yaml @@ -0,0 +1,12 @@ +apiVersion : v1 +kind : ConfigMap +metadata: + name : db-config +data: + DB_HOST: maria-service + DB_NAME: mydb + DB_PORT: '3306' + PORT: '5000' + MARIADB_DATABASE: mydb + MARIADB_USER: hello + diff --git a/maria-secret.yaml b/maria-secret.yaml new file mode 100644 index 0000000..675ef2c --- /dev/null +++ b/maria-secret.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Secret +metadata: + name: maria-secret +type: Opaque +stringData: + MARIADB_ROOT_PASSWORD: "hello" + MARIADB_PASSWORD: "hello" + DB_USERNAME: "hello" + DB_PASSWORD: "hello" \ No newline at end of file diff --git a/mariadb.yaml b/mariadb.yaml new file mode 100644 index 0000000..9f144b3 --- /dev/null +++ b/mariadb.yaml @@ -0,0 +1,55 @@ + +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: mariadb-depl + labels: + app: mydb +spec: + replicas: 1 + selector: + matchLabels: + app: maria + template: + metadata: + labels: + app: maria + spec: + # nodeSelector: + # name: ankit + containers: + - name: mariadb-container + image: mariadb + ports: + - containerPort: 3306 + envFrom: + - configMapRef: + name: db-config + - secretRef: + name: maria-secret + volumeMounts: + - mountPath: /var/lib/mysql + name: maria-volume + volumeClaimTemplates: + - metadata: + name: maria-volume + spec: + accessModes: [ "ReadWriteOnce" ] + storageClassName: "local-path" + resources: + requests: + storage: 1Gi + +--- + +apiVersion: v1 +kind: Service +metadata: + name: maria-service +spec: + selector: + app: maria + ports: + - protocol: TCP + port: 3306 + targetPort: 3306 \ No newline at end of file diff --git a/trialFolder/maria.yaml b/trialFolder/maria.yaml new file mode 100644 index 0000000..6dffcad --- /dev/null +++ b/trialFolder/maria.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Pod +metadata: + name: mariatrial-pod +spec: + containers: + - name: mariatrial + image: mariadb + ports: + - containerPort: 3306 + env: + - name: MARIADB_ROOT_PASSWORD + value: toor + - name: MARIADB_DATABASE + value: mydb + - name: MARIADB_USER + value: toor + - name: MARIADB_PASSWORD + value: toor \ No newline at end of file diff --git a/website/__init__.py b/website/__init__.py index 9948f80..dc0d230 100644 --- a/website/__init__.py +++ b/website/__init__.py @@ -21,9 +21,9 @@ def create_app(): from .auth import auth app.register_blueprint(auth, url_prefix='/') app.register_blueprint(views, url_prefix='/') - + # migrations - + migrate.init_app(app, db) # for user seesion management