From 066e08f85504f644614fbeb27368b7f9deffd25e Mon Sep 17 00:00:00 2001 From: 1Rayan Date: Mon, 7 Oct 2024 00:26:00 +0300 Subject: [PATCH 1/2] initall commit with docker file and buildspec.yml file configured --- .gitignore | 1 + Dockerfile | 18 ++++++++++++++++++ buildspec.yml | 18 ++++++++++++++++++ postgresql-deployment.yaml | 32 ++++++++++++++++++++++++++++++++ postgresql-service.yaml | 10 ++++++++++ pv.yaml | 13 +++++++++++++ pvc.yaml | 11 +++++++++++ 7 files changed, 103 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 buildspec.yml 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/.gitignore b/.gitignore new file mode 100644 index 00000000..ed8ebf58 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..35d7b5e0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM python:3.9-slim + +RUN apt-get update && \ + apt-get install -y --no-install-recommends build-essential libpq-dev && \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +COPY analytics/requirements.txt . + +RUN pip install --upgrade pip setuptools wheel +RUN pip install -r requirements.txt + +COPY analytics/ . + +EXPOSE 5153 + +CMD ["python", "app.py"] \ No newline at end of file diff --git a/buildspec.yml b/buildspec.yml new file mode 100644 index 00000000..e45d37e9 --- /dev/null +++ b/buildspec.yml @@ -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:$CODEBUILD_BUILD_NUMBER . + - docker tag $IMAGE_REPO_NAME:$CODEBUILD_BUILD_NUMBER $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$CODEBUILD_BUILD_NUMBER + 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:$CODEBUILD_BUILD_NUMBER \ No newline at end of file diff --git a/postgresql-deployment.yaml b/postgresql-deployment.yaml new file mode 100644 index 00000000..8c0518b5 --- /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: mydb + - name: POSTGRES_USER + value: rayan + - name: POSTGRES_PASSWORD + value: 4x2Qf0k6sl7 + 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..dfab0a71 --- /dev/null +++ b/pvc.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: postgresql-pvc +spec: + storageClassName: gp2 + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi \ No newline at end of file From eee8608891fb63bae1223d6c5b1bab7145cd378d Mon Sep 17 00:00:00 2001 From: 1Rayan Date: Mon, 7 Oct 2024 01:42:56 +0300 Subject: [PATCH 2/2] update docker file --- Dockerfile | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 35d7b5e0..d8434548 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.9-slim +FROM python:3.12-slim RUN apt-get update && \ apt-get install -y --no-install-recommends build-essential libpq-dev && \ @@ -6,13 +6,11 @@ RUN apt-get update && \ WORKDIR /app -COPY analytics/requirements.txt . +COPY /analytics/ /app RUN pip install --upgrade pip setuptools wheel -RUN pip install -r requirements.txt - -COPY analytics/ . +RUN pip install --no-cache-dir -r /app/requirements.txt EXPOSE 5153 -CMD ["python", "app.py"] \ No newline at end of file +CMD ["python", "app/app.py"]