Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanMarie Mariadassou authored and JeanMarie Mariadassou committed Sep 28, 2023
2 parents 35012ac + 4928b80 commit 18017d8
Show file tree
Hide file tree
Showing 17 changed files with 107 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file is sensitive since rules below may be used for restricting who can
# This file is sensitive since rules below may be used for restricting who can
# make access control changes.
/.github/CODEOWNERS @GSA-TTS/FAC-admins
/.github/workflows/restore-database.yml @GSA-TTS/FAC-admins @asteel-gsa


# Changes to the following Terraform directory will impact access control in cloud.gov spaces. Any PR involving these files should get a review from someone in FAC-admins.
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/backup-database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
required: true
type: string
default: dev

jobs:
backup-database:
name: Backup ${{ inputs.environment }} database
Expand All @@ -20,7 +21,7 @@ jobs:
uses: actions/checkout@v4

- name: Bind backups bucket to ${{ inputs.environment }} application
if: ${{ inputs.environment == 'dev'}}
if: ${{ inputs.environment == 'dev' || inputs.environment == 'production' }}
uses: cloud-gov/cg-cli-tools@main
with:
cf_username: ${{ secrets.CF_USERNAME }}
Expand All @@ -30,7 +31,7 @@ jobs:
command: cf bind-service gsa-fac backups -w

- name: Backup the database in ${{ inputs.environment }}
if: ${{ inputs.environment == 'dev'}}
if: ${{ inputs.environment == 'dev' || inputs.environment == 'production' }}
uses: cloud-gov/cg-cli-tools@main
with:
cf_username: ${{ secrets.CF_USERNAME }}
Expand All @@ -40,12 +41,12 @@ jobs:
command: cf run-task gsa-fac -k 2G -m 2G --name pg_backup --command "./backup_database.sh ${{ env.space }}"

- name: Sleep for 5 minutes to ensure backup occurs
if: ${{ inputs.environment == 'dev'}}
if: ${{ inputs.environment == 'dev' || inputs.environment == 'production' }}
run: sleep 5m
shell: bash

- name: Unbind backup s3 bucket from ${{ inputs.environment }} application
if: ${{ inputs.environment == 'dev'}}
if: ${{ inputs.environment == 'dev' || inputs.environment == 'production' }}
uses: cloud-gov/cg-cli-tools@main
with:
cf_username: ${{ secrets.CF_USERNAME }}
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/restore-database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ on:
required: true
type: string # YYYY-MM-DD-HHmm

<<<<<<< HEAD

jobs:
restore-database:
=======
jobs:
restore-database:
if: contains('["asteel-gsa","JeanMarie-TTS"]', github.actor)
>>>>>>> 4928b800d0264b7ff6aa58820cc85c67f8c9b1ce
name: Restore ${{ inputs.environment }} database
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
Expand Down
5 changes: 5 additions & 0 deletions backend/Apple_M1_Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ ENV PYTHONUNBUFFERED 1
RUN apt-get -y update
RUN apt-get -y install git

RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install --no-install-recommends --assume-yes \
postgresql-client

# RUN --mount=type=cache,target=/root/.cache \

WORKDIR ..
Expand Down
Binary file removed backend/static/img/favicons/favicon-114.png
Binary file not shown.
Binary file removed backend/static/img/favicons/favicon-144.png
Binary file not shown.
Binary file removed backend/static/img/favicons/favicon-16.png
Binary file not shown.
Binary file removed backend/static/img/favicons/favicon-192.png
Binary file not shown.
Binary file removed backend/static/img/favicons/favicon-40.png
Binary file not shown.
Binary file removed backend/static/img/favicons/favicon-57.png
Binary file not shown.
Binary file removed backend/static/img/favicons/favicon-72.png
Binary file not shown.
Binary file modified backend/static/img/favicons/favicon.ico
Binary file not shown.
Binary file removed backend/static/img/favicons/favicon.png
Binary file not shown.
4 changes: 4 additions & 0 deletions backend/static/img/favicons/icon_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions backend/support/management/commands/collect_metrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from datetime import datetime
from django.core.management.base import BaseCommand
from config import settings
from django.db import connection, models
from django.apps import apps


class Command(BaseCommand):
help = """
Collect metrics about the database and media.
For the database, list table, row count and size
For media files, list file types, create date and size
"""

def handle(self, *args, **kwargs):
print(f"Metrics for {settings.ENVIRONMENT} collected at {datetime.now()}")
self.dump_db_metrics()
self.dump_media_metrics()

def dump_db_metrics(self):
def get_table_size(model):
cursor = connection.cursor()
cursor.execute(f"SELECT pg_total_relation_size('{model._meta.db_table}');")
table_size = cursor.fetchone()[0]
cursor.close()
return table_size

total_size = 0
for app in apps.get_app_configs():
print(f"App: {app.name}:")
for model in app.get_models():
row_count = model.objects.count()
table_size = get_table_size(model)
total_size += table_size
print(
f" * {model._meta.verbose_name}: {row_count} rows, {table_size} bytes"
)
print(f" ** Database size: {total_size} bytes **")

def dump_media_metrics(self):
total_size = 0
for app in apps.get_app_configs():
for model in app.get_models():
for field in model._meta.get_fields():
if isinstance(field, models.FileField):
print(
f"{app.name} : {model._meta.verbose_name} : {field.name}:"
)
count = size = 0
for row in model.objects.all():
count += 1
size += getattr(row, field.name).file.size
print(f"{count} instances, {size} bytes")
total_size += size
print(f" ** Media size: {total_size} bytes **")
29 changes: 29 additions & 0 deletions backend/support/management/commands/purge_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from django.core.management.base import BaseCommand
from django.apps import apps
from audit.models import SingleAuditChecklist
from config import settings


class Command(BaseCommand):
help = """
This is a testing utility that should only be used locally and in dev.
It deletes all data in the postgres database.
It was build to test backup and restore,
"""

def handle(self, *args, **kwargs):
if settings.ENVIRONMENT not in [
"DEVELOPMENT",
"LOCAL",
]:
print("This command works only in LOCAL or DEVELOPMENT environments")
else:
self.purge_tables()

def purge_tables(self):
# Delete SAC first to aboid FK protection issues
SingleAuditChecklist.objects.all().delete()

for app in apps.get_app_configs():
for model in app.get_models():
model.objects.all().delete()
1 change: 1 addition & 0 deletions backend/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
href="{% static 'compiled/scss/main-post.css' %}"
media="all"
type="text/css"/>
<link rel="icon" type="image/x-icon" href="{% static 'img/favicons/icon_logo.svg' %}" />
{% block title %}
{% if post.title %}
<title>{{ post.title }}</title>
Expand Down

0 comments on commit 18017d8

Please sign in to comment.