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

Add proper support for connection to RDS PostgreSQL #7

Merged
merged 21 commits into from
Dec 3, 2024
Merged
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
28 changes: 15 additions & 13 deletions .github/workflows/friendly-umbrella-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,48 @@ jobs:
steps:
- name: Checkout Friendly-Umbrella
uses: actions/checkout@v2

- name: Retrieve Security Scan Secrets
uses: aws-actions/aws-secretsmanager-get-secrets@v2
with:
secret-ids: |
, ${{ secrets.SECURITY_SCAN_SECRET }}
RDS, ${{ secrets.RDS_CREDS_SECRET }}
parse-json-secrets: true

- name: Build Docker Image
run: |
run: |

# Build Friendly-Umbrella Image
docker build -t ${{ secrets.ECR_REPO }}:$GITHUB_SHA .

- name: Security Scan with Twistlock
run: |
run: |

curl -k -u "$TL_USER:$TL_PASSWORD" "$TL_CONSOLE_URL/api/v1/util/twistcli" --output twistcli
chmod +x twistcli

./twistcli images scan --details -address "${TL_CONSOLE_URL}" -u "${TL_USER}" -p "${TL_PASSWORD}" ${{ secrets.ECR_REPO }}:$GITHUB_SHA tee twistcli.log; EXITCODE=$?


- name: Push to ECR
run: |

# Login to ECR
aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username ${{ secrets.AWS_USERNAME }} --password-stdin ${{ secrets.ECR_REGISTRY }}
aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username ${{ secrets.AWS_USERNAME }} --password-stdin ${{ secrets.ECR_REGISTRY }}

# Push to ECR
docker push ${{ secrets.ECR_REPO }}:$GITHUB_SHA

- name: Install K8s/Helm
run: |

# Install Helm
# Install Helm
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh

# Install kubectl
# Install kubectl
curl -o ./kubectl https://s3.us-west-2.amazonaws.com/amazon-eks/1.25.14/2023-10-17/bin/linux/amd64/kubectl
curl -o ./kubectl.sha256 https://s3.us-west-2.amazonaws.com/amazon-eks/1.25.14/2023-10-17/bin/linux/amd64/kubectl.sha256
(diff <(openssl sha256 kubectl | awk {'print $2'}) <(cat kubectl.sha256 | awk {'print $1'}) &&
Expand All @@ -64,12 +65,13 @@ jobs:

- name: Install Helm Chart on EKS
run: >
helm upgrade --install friendly-umbrella ./helm
helm upgrade --install friendly-umbrella ./helm
-n ${{ secrets.NAMESPACE }} -f ./helm/values.yaml
--set image.repository=${{ secrets.ECR_REPO }}
--set image.tag=$GITHUB_SHA
--set initContainers[0].image.repository=${{ secrets.ECR_REPO }}
--set initContainers[0].image.tag=$GITHUB_SHA
--set containers[0].image.repository=${{ secrets.ECR_REPO }}
--set containers[0].image.tag=$GITHUB_SHA
--set mapping.host=${{ secrets.HOST }}
--set serviceAccount.name=${{ secrets.K8S_SERVICE_ACCOUNT }}
--set config.AWS_STORAGE_BUCKET_NAME=${{ secrets.BUCKET_NAME }}
--set serviceAccount.name=${{ secrets.K8S_SERVICE_ACCOUNT }}
--set config.AWS_STORAGE_BUCKET_NAME=${{ secrets.BUCKET_NAME }}
--set config.DATABASE_URL=$RDS_DATABASE_URL
4 changes: 2 additions & 2 deletions helm/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
{{- with .Values.config }}
{{- toYaml . | nindent 4 }}
{{- range $key, $value := .Values.config }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- end }}
75 changes: 62 additions & 13 deletions helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,70 @@ spec:
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}

initContainers:
{{- range .Values.initContainers }}
- name: {{ .name }}
image: "{{.image.repository}}:{{ .image.tag}}"
imagePullPolicy: {{ .image.pullPolicy }}
ports:
- name: http
containerPort: {{ .port }}
protocol: TCP
{{- if .command }}
command:
{{- range .command }}
- {{ . | quote }}
{{- end }}
{{- end }}
{{ if .args }}
args:
{{- range .args }}
- "{{ . }}"
{{- end }}
{{- end }}
envFrom:
- configMapRef:
name: {{ $.Release.Name }}-configmap
{{ if .env}}
env:
{{- range .env }}
- name: {{ .name }}
value: {{ .value | quote }}
{{- end }}
{{- end }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
{{- with .Values.image }}
image: "{{ .repository }}:{{ .tag }}"
imagePullPolicy: {{ .pullPolicy }}
{{- range .Values.containers }}
- name: {{ .name }}
image: "{{.image.repository}}:{{ .image.tag}}"
imagePullPolicy: {{ .image.pullPolicy }}
ports:
- name: http
containerPort: {{ .port }}
protocol: TCP
{{- if .command }}
command:
{{- range .command }}
- {{ . | quote }}
{{- end }}
envFrom:
- configMapRef:
name: {{ .Release.Name }}-configmap
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP

{{- end }}
{{ if .args }}
args:
{{- range .args }}
- "{{ . }}"
{{- end }}
{{- end }}
envFrom:
- configMapRef:
name: {{ $.Release.Name }}-configmap
{{ if .env}}
env:
{{- range .env }}
- name: {{ .name }}
value: {{ .value | quote }}
{{- end }}
{{- end }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
23 changes: 22 additions & 1 deletion helm/values.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
# This sets the container image more information can be found here: https://kubernetes.io/docs/concepts/containers/images/

initContainers:
- name: friendly-umbrella-init
image:
repository: friendly-umbrella
pullPolicy: IfNotPresent
tag: "latest"
port: 8000
command: ["sh", "-c"]
args:
- python manage.py migrate

containers:
- name: friendly-umbrella
image:
repository: friendly-umbrella
pullPolicy: IfNotPresent
tag: "latest"
port: 8000

image:
repository: friendly-umbrella
tag: "latest"
Expand All @@ -13,10 +33,11 @@ serviceAccount:

config:
AWS_STORAGE_BUCKET_NAME: bucket_name
DATABASE_URL: database_url

mapping:
enabled: true
host: "friendly-umbrella.localhost"
ambassador_id:
- "--apiVersion-v3alpha1-only--default"
prefix: "/"
prefix: "/"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies = [
"django-storages>=1.14.4",
"django>=4.2,<5",
"gunicorn>=23.0.0",
"psycopg>=3.2.3",
"psycopg2-binary>=2.9",
"whitenoise>=6.7.0",
]

Expand Down