From 4a93ed2ee5e0fb3fdcb568ffbe29c9ad60b2f02c Mon Sep 17 00:00:00 2001 From: Wade Chen Date: Sun, 30 Jun 2024 10:09:37 +0000 Subject: [PATCH 01/10] prepare env --- Dockerfile | 28 +++++++++++++++++ analytics/__pycache__/config.cpython-38.pyc | Bin 0 -> 691 bytes buildspec.yaml | 18 +++++++++++ postgresql-deployment.yaml | 32 ++++++++++++++++++++ postgresql-service.yaml | 10 ++++++ pv.yaml | 13 ++++++++ pvc.yaml | 10 ++++++ 7 files changed, 111 insertions(+) create mode 100644 Dockerfile create mode 100644 analytics/__pycache__/config.cpython-38.pyc create mode 100644 buildspec.yaml create mode 100644 postgresql-deployment.yaml create mode 100644 postgresql-service.yaml create mode 100644 pv.yaml create mode 100644 pvc.yaml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..52ea27ea --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ + +# Use Python Python 3.10 as the base image +FROM python:3.9-slim-buster + +# Set the working directory inside the container +WORKDIR /app + +# Copy the current directory contents to the container at /app +COPY /analytics/ /app + +RUN apt update -y +RUN apt install build-essential libpq-dev -y +RUN pip install --upgrade pip setuptools wheel +RUN pip install --upgrade pip && pip install -r requirements.txt +# RUN pip install --no-cache-dir -r /app/requirements.txt + +# Expose 5000 +EXPOSE 5000 + +# Set an environment variable +ENV DB_USERNAME myuser +ENV DB_PASSWORD mypassword +ENV DB_HOST=127.0.0.1 +ENV DB_PORT=5433 +ENV DB_NAME=mydatabase + +# Run the application when the container starts +CMD python app.py \ No newline at end of file diff --git a/analytics/__pycache__/config.cpython-38.pyc b/analytics/__pycache__/config.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2657d98edb1f5841f8f9fbd25ed70aaaa50f2418 GIT binary patch literal 691 zcmYk4&2HL26oqGOjE(sTX)3i{bYB+44GD@AMO8?lO(hai98`5SmgBh)z+h*_AtI|v zeT=A5vh1$UGuy8E3aolLhKp*GW*PSctm=4J*nC;>Xj^V}=K%*+|+tkgXec%GY&8nd6s;svDQ6WP3o zR018!-zlr`5}5adm%&1IRhV$qySUlMP-yBw#=V?^lsGAD#i3Y&}xULtRqa z{DY~TqGmJ)~@qDDTNGfBPh7=lRX4TAl@;da_X@!nuWx{+h7SWs)`K5Ow zLCpObWDxsO-bR8eeFO3qP#Nvc@!;c6BDQdPCM(y$F;f})0XPBQY3w$e_1QQO5vEy;1CVw9R@SFCmlzHb z#8^ZV2$H%?e35`~{J9@4lW`!O_2}(*sjS0U#BV})hd&{aFHtONX(d|HY--a=x;2Zw H(JbvRcIv@9 literal 0 HcmV?d00001 diff --git a/buildspec.yaml b/buildspec.yaml new file mode 100644 index 00000000..5aaa1c06 --- /dev/null +++ b/buildspec.yaml @@ -0,0 +1,18 @@ +version: 0.2 + +phases: + pre_build: + commands: + - echo Logging into ECR + - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com + build: + commands: + - echo Starting build at `date` + - echo Building the Docker image... + - docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG . + - docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG + post_build: + commands: + - echo Completed build at `date` + - echo Pushing the Docker image... + - docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG diff --git a/postgresql-deployment.yaml b/postgresql-deployment.yaml new file mode 100644 index 00000000..ca9b7df2 --- /dev/null +++ b/postgresql-deployment.yaml @@ -0,0 +1,32 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: postgresql +spec: + selector: + matchLabels: + app: postgresql + template: + metadata: + labels: + app: postgresql + spec: + containers: + - name: postgresql + image: postgres:latest + env: + - name: POSTGRES_DB + value: mydatabase + - name: POSTGRES_USER + value: myuser + - name: POSTGRES_PASSWORD + value: mypassword + ports: + - containerPort: 5432 + volumeMounts: + - mountPath: /var/lib/postgresql/data + name: postgresql-storage + volumes: + - name: postgresql-storage + persistentVolumeClaim: + claimName: postgresql-pvc \ No newline at end of file diff --git a/postgresql-service.yaml b/postgresql-service.yaml new file mode 100644 index 00000000..733e368f --- /dev/null +++ b/postgresql-service.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Service +metadata: + name: postgresql-service +spec: + ports: + - port: 5432 + targetPort: 5432 + selector: + app: postgresql \ No newline at end of file diff --git a/pv.yaml b/pv.yaml new file mode 100644 index 00000000..31facea9 --- /dev/null +++ b/pv.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: PersistentVolume +metadata: + name: my-manual-pv +spec: + capacity: + storage: 1Gi + accessModes: + - ReadWriteOnce + persistentVolumeReclaimPolicy: Retain + storageClassName: gp2 + hostPath: + path: "/mnt/data" \ No newline at end of file diff --git a/pvc.yaml b/pvc.yaml new file mode 100644 index 00000000..dc1e507a --- /dev/null +++ b/pvc.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: postgresql-pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi \ No newline at end of file From 6f8661463bf397972544b7a89becd865992fc3ca Mon Sep 17 00:00:00 2001 From: Wade Chen Date: Sun, 30 Jun 2024 13:07:25 +0000 Subject: [PATCH 02/10] update dockerfile --- Dockerfile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 52ea27ea..c70d502f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,12 +17,12 @@ RUN pip install --upgrade pip && pip install -r requirements.txt # Expose 5000 EXPOSE 5000 -# Set an environment variable -ENV DB_USERNAME myuser -ENV DB_PASSWORD mypassword -ENV DB_HOST=127.0.0.1 -ENV DB_PORT=5433 -ENV DB_NAME=mydatabase +# # Set an environment variable +# ENV DB_USERNAME myuser +# ENV DB_PASSWORD mypassword +# ENV DB_HOST=127.0.0.1 +# ENV DB_PORT=5433 +# ENV DB_NAME=mydatabase # Run the application when the container starts CMD python app.py \ No newline at end of file From 2dc51b4882a19b15163d7e91cdbc6b321f920a9e Mon Sep 17 00:00:00 2001 From: Wade Chen Date: Fri, 12 Jul 2024 07:15:46 +0000 Subject: [PATCH 03/10] codebuild practice --- Dockerfile | 20 ++---- configmap.yml | 9 +++ deployment/coworking.yaml => coworking.yaml | 0 deployment/configmap.yaml | 14 ++-- deployment/deployment.yaml | 78 +++++++++++++++++++++ deployment/secret.yaml | 7 ++ deployment__.yaml | 48 +++++++++++++ 7 files changed, 156 insertions(+), 20 deletions(-) create mode 100644 configmap.yml rename deployment/coworking.yaml => coworking.yaml (100%) create mode 100644 deployment/deployment.yaml create mode 100644 deployment/secret.yaml create mode 100644 deployment__.yaml diff --git a/Dockerfile b/Dockerfile index c70d502f..2c58c9dd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,28 +1,22 @@ - # Use Python Python 3.10 as the base image -FROM python:3.9-slim-buster +FROM python:3.10.14-slim-bullseye # Set the working directory inside the container WORKDIR /app # Copy the current directory contents to the container at /app -COPY /analytics/ /app +COPY ./analytics/ /app RUN apt update -y RUN apt install build-essential libpq-dev -y RUN pip install --upgrade pip setuptools wheel RUN pip install --upgrade pip && pip install -r requirements.txt -# RUN pip install --no-cache-dir -r /app/requirements.txt - -# Expose 5000 -EXPOSE 5000 -# # Set an environment variable -# ENV DB_USERNAME myuser -# ENV DB_PASSWORD mypassword -# ENV DB_HOST=127.0.0.1 -# ENV DB_PORT=5433 -# ENV DB_NAME=mydatabase +ENV DB_USERNAME=myuser +ENV DB_PASSWORD=${POSTGRES_PASSWORD} +ENV DB_HOST=127.0.0.1 +ENV DB_PORT=5433 +ENV DB_NAME=mydatabase # Run the application when the container starts CMD python app.py \ No newline at end of file diff --git a/configmap.yml b/configmap.yml new file mode 100644 index 00000000..af03e156 --- /dev/null +++ b/configmap.yml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: my-postgres-db-configmap +data: + DB_USERNAME: "myuser" + DB_NAME: "mydatabase" + DB_HOST: "postgresql-service" + DB_PORT: "5432" \ No newline at end of file diff --git a/deployment/coworking.yaml b/coworking.yaml similarity index 100% rename from deployment/coworking.yaml rename to coworking.yaml diff --git a/deployment/configmap.yaml b/deployment/configmap.yaml index 7dcae113..72fd6c6d 100644 --- a/deployment/configmap.yaml +++ b/deployment/configmap.yaml @@ -1,17 +1,17 @@ apiVersion: v1 kind: ConfigMap metadata: - name: + name: dbconfigmap data: - DB_NAME: - DB_USER: - DB_HOST: - DB_PORT: + DB_NAME: "mydatabase" + DB_USER: "myuser" + DB_HOST: "postgresql-service" + DB_PORT: "5432" --- apiVersion: v1 kind: Secret metadata: - name: + name: dbsecret type: Opaque data: - : \ No newline at end of file + DB_PASSWORD: bXlwYXNzd29yZA== \ No newline at end of file diff --git a/deployment/deployment.yaml b/deployment/deployment.yaml new file mode 100644 index 00000000..e220ec63 --- /dev/null +++ b/deployment/deployment.yaml @@ -0,0 +1,78 @@ +apiVersion: v1 +kind: Service +metadata: + name: coworking +spec: + type: LoadBalancer + selector: + service: coworking + ports: + - name: "5153" + protocol: TCP + port: 5153 + targetPort: 5153 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: coworking + labels: + name: coworking +spec: + replicas: 1 + selector: + matchLabels: + service: coworking + template: + metadata: + labels: + service: coworking + spec: + containers: + - name: coworking + image: 497971030638.dkr.ecr.us-east-1.amazonaws.com/coworking:0.0.2 + imagePullPolicy: Always + livenessProbe: + httpGet: + path: /health_check + port: 5153 + initialDelaySeconds: 5 + timeoutSeconds: 2 + readinessProbe: + httpGet: + path: "/readiness_check" + port: 5153 + initialDelaySeconds: 5 + timeoutSeconds: 5 + envFrom: + - secretRef: + name: dbsecret + - configMapRef: + name: dbconfigmap + env: + - name: DB_USER + valueFrom: + configMapKeyRef: + name: dbconfigmap + key: DB_USER + - name: DB_NAME + valueFrom: + configMapKeyRef: + name: dbconfigmap + key: DB_NAME + - name: DB_HOST + valueFrom: + configMapKeyRef: + name: dbconfigmap + key: DB_HOST + - name: DB_PORT + valueFrom: + configMapKeyRef: + name: dbconfigmap + key: DB_PORT + - name: DB_PASSWORD + valueFrom: + secretKeyRef: + name: dbsecret + key: DB_PASSWORD + restartPolicy: Always \ No newline at end of file diff --git a/deployment/secret.yaml b/deployment/secret.yaml new file mode 100644 index 00000000..043900f4 --- /dev/null +++ b/deployment/secret.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: Secret +metadata: + name: dbsecret +type: Opaque +data: + DB_PASSWORD: bXlwYXNzd29yZA== \ No newline at end of file diff --git a/deployment__.yaml b/deployment__.yaml new file mode 100644 index 00000000..074a0aaf --- /dev/null +++ b/deployment__.yaml @@ -0,0 +1,48 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: analytics-api + labels: + name: analytics-api +spec: + replicas: 1 + selector: + matchLabels: + service: analytics-api + template: + metadata: + labels: + service: analytics-api + spec: + containers: + - name: analyticsapi + image: 811760461644.dkr.ecr.us-east-1.amazonaws.com/analytics:0.0.1 + imagePullPolicy: Always + env: + - name: DB_USERNAME + valueFrom: + configMapKeyRef: + name: dbconfigmap + key: DB_USERNAME + - name: DB_NAME + valueFrom: + configMapKeyRef: + name: dbconfigmap + key: DB_NAME + - name: DB_HOST + valueFrom: + configMapKeyRef: + name: dbconfigmap + key: DB_HOST + - name: DB_PORT + valueFrom: + configMapKeyRef: + name: dbconfigmap + key: DB_PORT + - name: DB_PASSWORD + valueFrom: + secretKeyRef: + name: dbsecret + key: DB_PASSWORD + ports: + - containerPort: 5153 \ No newline at end of file From cbdf77c80d3e8b9137a5371cc5df867980666710 Mon Sep 17 00:00:00 2001 From: Wade Chen Date: Fri, 12 Jul 2024 07:30:19 +0000 Subject: [PATCH 04/10] updata python version --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2c58c9dd..1138d2a5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Use Python Python 3.10 as the base image -FROM python:3.10.14-slim-bullseye +FROM python:3.10-slim-bullseye # Set the working directory inside the container WORKDIR /app From 0ad33793ace7ca43e056e1c2fed807f2e2492cff Mon Sep 17 00:00:00 2001 From: Wade Chen Date: Fri, 12 Jul 2024 13:26:58 +0000 Subject: [PATCH 05/10] update --- .github/workflows/manual.yml | 46 ------------ Dockerfile | 1 - analytics/__pycache__/config.cpython-38.pyc | Bin 691 -> 0 bytes configmap.yml | 9 --- deployment/configmap.yaml | 16 +--- coworking.yaml => deployment/coworking.yaml | 8 +- deployment/deployment.yaml | 78 -------------------- deployment/{secret.yaml => secrets.yaml} | 0 deployment__.yaml | 48 ------------ 9 files changed, 8 insertions(+), 198 deletions(-) delete mode 100644 .github/workflows/manual.yml delete mode 100644 analytics/__pycache__/config.cpython-38.pyc delete mode 100644 configmap.yml rename coworking.yaml => deployment/coworking.yaml (83%) delete mode 100644 deployment/deployment.yaml rename deployment/{secret.yaml => secrets.yaml} (100%) delete mode 100644 deployment__.yaml diff --git a/.github/workflows/manual.yml b/.github/workflows/manual.yml deleted file mode 100644 index 7e5c2878..00000000 --- a/.github/workflows/manual.yml +++ /dev/null @@ -1,46 +0,0 @@ -# Workflow to ensure whenever a Github PR is submitted, -# a JIRA ticket gets created automatically. -name: Manual Workflow - -# Controls when the action will run. -on: - # Triggers the workflow on pull request events but only for the master branch - pull_request_target: - types: [opened, reopened] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -jobs: - test-transition-issue: - name: Convert Github Issue to Jira Issue - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@master - - - name: Login - uses: atlassian/gajira-login@master - env: - JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} - JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} - JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} - - - name: Create NEW JIRA ticket - id: create - uses: atlassian/gajira-create@v2.0.1 - with: - project: CONUPDATE - issuetype: Task - summary: | - Github PR [Assign the ND component] | Repo: ${{ github.repository }} | PR# ${{github.event.number}} - description: | - Repo link: https://github.com/${{ github.repository }} - PR no. ${{ github.event.pull_request.number }} - PR title: ${{ github.event.pull_request.title }} - PR description: ${{ github.event.pull_request.description }} - In addition, please resolve other issues, if any. - fields: '{"components": [{"name":"Github PR"}], "customfield_16449":"https://classroom.udacity.com/", "customfield_16450":"Resolve the PR", "priority":{"id": "4"}}' - - - name: Log created issue - run: echo "Issue ${{ steps.create.outputs.issue }} was created" diff --git a/Dockerfile b/Dockerfile index 1138d2a5..d88ae1ad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,6 @@ RUN pip install --upgrade pip setuptools wheel RUN pip install --upgrade pip && pip install -r requirements.txt ENV DB_USERNAME=myuser -ENV DB_PASSWORD=${POSTGRES_PASSWORD} ENV DB_HOST=127.0.0.1 ENV DB_PORT=5433 ENV DB_NAME=mydatabase diff --git a/analytics/__pycache__/config.cpython-38.pyc b/analytics/__pycache__/config.cpython-38.pyc deleted file mode 100644 index 2657d98edb1f5841f8f9fbd25ed70aaaa50f2418..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 691 zcmYk4&2HL26oqGOjE(sTX)3i{bYB+44GD@AMO8?lO(hai98`5SmgBh)z+h*_AtI|v zeT=A5vh1$UGuy8E3aolLhKp*GW*PSctm=4J*nC;>Xj^V}=K%*+|+tkgXec%GY&8nd6s;svDQ6WP3o zR018!-zlr`5}5adm%&1IRhV$qySUlMP-yBw#=V?^lsGAD#i3Y&}xULtRqa z{DY~TqGmJ)~@qDDTNGfBPh7=lRX4TAl@;da_X@!nuWx{+h7SWs)`K5Ow zLCpObWDxsO-bR8eeFO3qP#Nvc@!;c6BDQdPCM(y$F;f})0XPBQY3w$e_1QQO5vEy;1CVw9R@SFCmlzHb z#8^ZV2$H%?e35`~{J9@4lW`!O_2}(*sjS0U#BV})hd&{aFHtONX(d|HY--a=x;2Zw H(JbvRcIv@9 diff --git a/configmap.yml b/configmap.yml deleted file mode 100644 index af03e156..00000000 --- a/configmap.yml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: my-postgres-db-configmap -data: - DB_USERNAME: "myuser" - DB_NAME: "mydatabase" - DB_HOST: "postgresql-service" - DB_PORT: "5432" \ No newline at end of file diff --git a/deployment/configmap.yaml b/deployment/configmap.yaml index 72fd6c6d..a56590b9 100644 --- a/deployment/configmap.yaml +++ b/deployment/configmap.yaml @@ -3,15 +3,7 @@ kind: ConfigMap metadata: name: dbconfigmap data: - DB_NAME: "mydatabase" - DB_USER: "myuser" - DB_HOST: "postgresql-service" - DB_PORT: "5432" ---- -apiVersion: v1 -kind: Secret -metadata: - name: dbsecret -type: Opaque -data: - DB_PASSWORD: bXlwYXNzd29yZA== \ No newline at end of file + DB_NAME: mydatabase + DB_USER: myuser + DB_HOST: postgresql-service + DB_PORT: 5432 \ No newline at end of file diff --git a/coworking.yaml b/deployment/coworking.yaml similarity index 83% rename from coworking.yaml rename to deployment/coworking.yaml index cf86a612..fc4c964c 100644 --- a/coworking.yaml +++ b/deployment/coworking.yaml @@ -30,7 +30,7 @@ spec: spec: containers: - name: coworking - image: + image: 497971030638.dkr.ecr.us-east-1.amazonaws.com/coworking:0.0.2 imagePullPolicy: IfNotPresent livenessProbe: httpGet: @@ -46,11 +46,11 @@ spec: timeoutSeconds: 5 envFrom: - configMapRef: - name: + name: dbconfigmap env: - name: DB_PASSWORD valueFrom: secretKeyRef: - name: - key: + name: dbsecret + key: DB_PASSWORD restartPolicy: Always \ No newline at end of file diff --git a/deployment/deployment.yaml b/deployment/deployment.yaml deleted file mode 100644 index e220ec63..00000000 --- a/deployment/deployment.yaml +++ /dev/null @@ -1,78 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: coworking -spec: - type: LoadBalancer - selector: - service: coworking - ports: - - name: "5153" - protocol: TCP - port: 5153 - targetPort: 5153 ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: coworking - labels: - name: coworking -spec: - replicas: 1 - selector: - matchLabels: - service: coworking - template: - metadata: - labels: - service: coworking - spec: - containers: - - name: coworking - image: 497971030638.dkr.ecr.us-east-1.amazonaws.com/coworking:0.0.2 - imagePullPolicy: Always - livenessProbe: - httpGet: - path: /health_check - port: 5153 - initialDelaySeconds: 5 - timeoutSeconds: 2 - readinessProbe: - httpGet: - path: "/readiness_check" - port: 5153 - initialDelaySeconds: 5 - timeoutSeconds: 5 - envFrom: - - secretRef: - name: dbsecret - - configMapRef: - name: dbconfigmap - env: - - name: DB_USER - valueFrom: - configMapKeyRef: - name: dbconfigmap - key: DB_USER - - name: DB_NAME - valueFrom: - configMapKeyRef: - name: dbconfigmap - key: DB_NAME - - name: DB_HOST - valueFrom: - configMapKeyRef: - name: dbconfigmap - key: DB_HOST - - name: DB_PORT - valueFrom: - configMapKeyRef: - name: dbconfigmap - key: DB_PORT - - name: DB_PASSWORD - valueFrom: - secretKeyRef: - name: dbsecret - key: DB_PASSWORD - restartPolicy: Always \ No newline at end of file diff --git a/deployment/secret.yaml b/deployment/secrets.yaml similarity index 100% rename from deployment/secret.yaml rename to deployment/secrets.yaml diff --git a/deployment__.yaml b/deployment__.yaml deleted file mode 100644 index 074a0aaf..00000000 --- a/deployment__.yaml +++ /dev/null @@ -1,48 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: analytics-api - labels: - name: analytics-api -spec: - replicas: 1 - selector: - matchLabels: - service: analytics-api - template: - metadata: - labels: - service: analytics-api - spec: - containers: - - name: analyticsapi - image: 811760461644.dkr.ecr.us-east-1.amazonaws.com/analytics:0.0.1 - imagePullPolicy: Always - env: - - name: DB_USERNAME - valueFrom: - configMapKeyRef: - name: dbconfigmap - key: DB_USERNAME - - name: DB_NAME - valueFrom: - configMapKeyRef: - name: dbconfigmap - key: DB_NAME - - name: DB_HOST - valueFrom: - configMapKeyRef: - name: dbconfigmap - key: DB_HOST - - name: DB_PORT - valueFrom: - configMapKeyRef: - name: dbconfigmap - key: DB_PORT - - name: DB_PASSWORD - valueFrom: - secretKeyRef: - name: dbsecret - key: DB_PASSWORD - ports: - - containerPort: 5153 \ No newline at end of file From efc751ced6459c591027bf42d699cf9b8f96b246 Mon Sep 17 00:00:00 2001 From: Wade Chen Date: Fri, 12 Jul 2024 13:43:52 +0000 Subject: [PATCH 06/10] for rebuild --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d88ae1ad..0dbb677d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -# Use Python Python 3.10 as the base image +# Python Python 3.10 as the base image FROM python:3.10-slim-bullseye # Set the working directory inside the container From 71e33434d9b035c817ce71d88c10151da28d9eee Mon Sep 17 00:00:00 2001 From: Wade Chen Date: Fri, 12 Jul 2024 13:47:38 +0000 Subject: [PATCH 07/10] update dockerfile --- Dockerfile | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0dbb677d..382be35a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Python Python 3.10 as the base image -FROM python:3.10-slim-bullseye +FROM python:3.10.14-slim # Set the working directory inside the container WORKDIR /app @@ -12,10 +12,5 @@ RUN apt install build-essential libpq-dev -y RUN pip install --upgrade pip setuptools wheel RUN pip install --upgrade pip && pip install -r requirements.txt -ENV DB_USERNAME=myuser -ENV DB_HOST=127.0.0.1 -ENV DB_PORT=5433 -ENV DB_NAME=mydatabase - # Run the application when the container starts CMD python app.py \ No newline at end of file From 0c4cb3ab68ff9a1629c299d4112454f3b3aa9a9f Mon Sep 17 00:00:00 2001 From: Wade Chen Date: Fri, 12 Jul 2024 13:48:59 +0000 Subject: [PATCH 08/10] update dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 382be35a..da8f28ad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Python Python 3.10 as the base image -FROM python:3.10.14-slim +FROM public.ecr.aws/docker/library/python:3.10-alpine # Set the working directory inside the container WORKDIR /app From 6a55abd681083a515faf78089d7723c4a34dda9e Mon Sep 17 00:00:00 2001 From: Wade Chen Date: Fri, 12 Jul 2024 13:51:10 +0000 Subject: [PATCH 09/10] update dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index da8f28ad..288e36af 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Python Python 3.10 as the base image -FROM public.ecr.aws/docker/library/python:3.10-alpine +FROM public.ecr.aws/docker/library/python:3.10-slim # Set the working directory inside the container WORKDIR /app From 890d360335e7560c4f0a5cb83a75d4293bd9973e Mon Sep 17 00:00:00 2001 From: Wade Chen Date: Sun, 14 Jul 2024 12:17:08 +0000 Subject: [PATCH 10/10] update for rebuild --- deployment-local/service.yaml | 14 ++++++++++++++ deployment/configmap.yaml | 8 ++++---- deployment/coworking.yaml | 22 ++++++++++++++++++++++ 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 deployment-local/service.yaml diff --git a/deployment-local/service.yaml b/deployment-local/service.yaml new file mode 100644 index 00000000..887f5a8c --- /dev/null +++ b/deployment-local/service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: analyticslb + labels: + app: analytics-api +spec: + type: LoadBalancer + selector: + app: analytics-api + ports: + - protocol: TCP + port: 80 + targetPort: 5153 \ No newline at end of file diff --git a/deployment/configmap.yaml b/deployment/configmap.yaml index a56590b9..589bfb23 100644 --- a/deployment/configmap.yaml +++ b/deployment/configmap.yaml @@ -3,7 +3,7 @@ kind: ConfigMap metadata: name: dbconfigmap data: - DB_NAME: mydatabase - DB_USER: myuser - DB_HOST: postgresql-service - DB_PORT: 5432 \ No newline at end of file + DB_NAME: "mydatabase" + DB_USERNAME: "myuser" + DB_HOST: "postgresql-service" + DB_PORT: "5432" \ No newline at end of file diff --git a/deployment/coworking.yaml b/deployment/coworking.yaml index fc4c964c..e18c353b 100644 --- a/deployment/coworking.yaml +++ b/deployment/coworking.yaml @@ -45,9 +45,31 @@ spec: initialDelaySeconds: 5 timeoutSeconds: 5 envFrom: + - secretRef: + name: dbsecret - configMapRef: name: dbconfigmap env: + - name: DB_USERNAME + valueFrom: + configMapKeyRef: + name: dbconfigmap + key: DB_USERNAME + - name: DB_NAME + valueFrom: + configMapKeyRef: + name: dbconfigmap + key: DB_NAME + - name: DB_HOST + valueFrom: + configMapKeyRef: + name: dbconfigmap + key: DB_HOST + - name: DB_PORT + valueFrom: + configMapKeyRef: + name: dbconfigmap + key: DB_PORT - name: DB_PASSWORD valueFrom: secretKeyRef: