From a8fd173bf89a36fd7bcb2a957c863ca6faf82b5e Mon Sep 17 00:00:00 2001 From: Lachlan Glen <54282009+lachlanglen@users.noreply.github.com> Date: Fri, 31 May 2024 17:31:35 -0400 Subject: [PATCH 1/7] Testnet -> Dev (#26) * add deploy-testnet.yml * add testnet deployment workflow & appspec * testnet workflow debugging * upload appspec as artifact * upload zipped codebase to s3 in workflow * continue working on after_install_testnet * separate watchtower log groups by django env * add testnet potlock TLA to indexer handler * add POTLOCK_TLA to settings * add dev.potlock.io and test-dev.potlock.io to allowed hosts * remove admin dashboard edit access * remove admin edit permission for all models * add timestamp to deployment zip filename * add env vars to deploy-testnet * add after_install_dev script --- .github/workflows/deploy-dev.yml | 51 ++++++++++ .github/workflows/deploy-testnet.yml | 66 +++++++++++++ .github/workflows/deploy.yml | 106 -------------------- accounts/admin.py | 47 +++++++-- activities/admin.py | 44 ++++++--- appspec-dev.yml | 16 +++ appspec-testnet.yml | 16 +++ base/settings.py | 14 ++- donations/admin.py | 9 ++ indexer_app/admin.py | 15 ++- indexer_app/handler.py | 12 ++- indexer_app/utils.py | 3 +- lists/admin.py | 70 +++++++++++--- pots/admin.py | 63 ++++++++++++ pots/utils.py | 4 +- scripts/after_install.sh | 64 +----------- scripts/after_install_dev.sh | 140 +++++++++++++++++++++++++++ scripts/after_install_testnet.sh | 67 +++++++++++++ tokens/admin.py | 34 +++++-- 19 files changed, 622 insertions(+), 219 deletions(-) create mode 100644 .github/workflows/deploy-dev.yml create mode 100644 .github/workflows/deploy-testnet.yml delete mode 100644 .github/workflows/deploy.yml create mode 100644 appspec-dev.yml create mode 100644 appspec-testnet.yml mode change 100755 => 100644 scripts/after_install.sh create mode 100755 scripts/after_install_dev.sh create mode 100755 scripts/after_install_testnet.sh diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml new file mode 100644 index 0000000..334d04e --- /dev/null +++ b/.github/workflows/deploy-dev.yml @@ -0,0 +1,51 @@ +name: Dev deploy to EC2 on Push + +on: + push: + branches: [dev] + +env: + AWS_REGION: "us-east-1" + +# Permission can be added at job level or workflow level +permissions: + id-token: write # This is required for requesting the JWT + contents: read # This is required for actions/checkout +jobs: + DeployToCodeDeploy: + runs-on: ubuntu-latest + steps: + - name: Git clone the repository + uses: actions/checkout@v3 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1.7.0 + with: + role-to-assume: arn:aws:iam::471112976510:role/GitHubAction-AssumeRoleWithAction + role-session-name: GitHub_to_AWS_via_FederatedOIDC + aws-region: ${{ env.AWS_REGION }} + + - name: Generate appspec.yml for dev + run: cp appspec-dev.yml appspec.yml + + - name: Set environment variables + id: vars + run: | + echo "DATETIME=$(date +'%Y-%m-%d_%H-%M-%S')" >> $GITHUB_ENV + echo "FILENAME=django-indexer-dev-${DATETIME}.zip" >> $GITHUB_ENV + echo "S3_BUCKET=django-indexer-dev" >> $GITHUB_ENV + + - name: Create zip of repository + run: zip -r "${{ env.FILENAME }}" . + + - name: Upload repository to S3 + run: aws s3 cp "${{ env.FILENAME }}" "s3://${{ env.S3_BUCKET }}/" + + - name: Create CodeDeploy Deployment + id: deploy + run: | + aws deploy create-deployment \ + --application-name django-indexer \ + --deployment-group-name django-indexer-dev-group \ + --deployment-config-name CodeDeployDefault.AllAtOnce \ + --s3-location bucket=${{ env.S3_BUCKET }},bundleType=zip,key=${{ env.FILENAME }} diff --git a/.github/workflows/deploy-testnet.yml b/.github/workflows/deploy-testnet.yml new file mode 100644 index 0000000..d22df3c --- /dev/null +++ b/.github/workflows/deploy-testnet.yml @@ -0,0 +1,66 @@ +name: Testnet deploy to EC2 on Push + +on: + push: + branches: [testnet] + +env: + AWS_REGION: "us-east-1" + +# Permission can be added at job level or workflow level +permissions: + id-token: write # This is required for requesting the JWT + contents: read # This is required for actions/checkout +jobs: + DeployToCodeDeploy: + runs-on: ubuntu-latest + steps: + - name: Git clone the repository + uses: actions/checkout@v3 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1.7.0 + with: + role-to-assume: arn:aws:iam::471112976510:role/GitHubAction-AssumeRoleWithAction + role-session-name: GitHub_to_AWS_via_FederatedOIDC + aws-region: ${{ env.AWS_REGION }} + + - name: Generate appspec.yml for testnet + run: cp appspec-testnet.yml appspec.yml + + - name: Set environment variables + id: vars + run: | + echo "DATETIME=$(date +'%Y-%m-%d_%H-%M-%S')" >> $GITHUB_ENV + echo "FILENAME=django-indexer-testnet-${DATETIME}.zip" >> $GITHUB_ENV + echo "S3_BUCKET=django-indexer-testnet" >> $GITHUB_ENV + + - name: Create zip of repository + run: zip -r "${{ env.FILENAME }}" . + + - name: Upload repository to S3 + run: aws s3 cp "${{ env.FILENAME }}" "s3://${{ env.S3_BUCKET }}/" + + - name: Create CodeDeploy Deployment + id: deploy + run: | + aws deploy create-deployment \ + --application-name django-indexer-testnet \ + --deployment-group-name django-indexer-testnet-group \ + --deployment-config-name CodeDeployDefault.AllAtOnce \ + --s3-location bucket=${{ env.S3_BUCKET }},bundleType=zip,key=${{ env.FILENAME }} + + # - name: Create zip of repository + # run: zip -r django-indexer-testnet.zip . + + # - name: Upload repository to S3 + # run: aws s3 cp django-indexer-testnet.zip s3://django-indexer-testnet/ + + # - name: Create CodeDeploy Deployment + # id: deploy + # run: | + # aws deploy create-deployment \ + # --application-name django-indexer-testnet \ + # --deployment-group-name django-indexer-testnet-group \ + # --deployment-config-name CodeDeployDefault.AllAtOnce \ + # --s3-location bucket=django-indexer-testnet,bundleType=zip,key=django-indexer-testnet.zip diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 554fb7f..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,106 +0,0 @@ -name: Deploy to EC2 on Push - -on: - push: - branches: [dev] - -env: - AWS_REGION: "us-east-1" - -# Permission can be added at job level or workflow level -permissions: - id-token: write # This is required for requesting the JWT - contents: read # This is required for actions/checkout -jobs: - AssumeRoleAndCallIdentity: - runs-on: ubuntu-latest - steps: - - name: Git clone the repository - uses: actions/checkout@v3 - - name: configure aws credentials - uses: aws-actions/configure-aws-credentials@v1.7.0 - with: - role-to-assume: arn:aws:iam::471112976510:role/GitHubAction-AssumeRoleWithAction - role-session-name: GitHub_to_AWS_via_FederatedOIDC - aws-region: ${{ env.AWS_REGION }} - # Hello from AWS: WhoAmI - - name: Sts GetCallerIdentity - run: | - aws sts get-caller-identity - - # Step 3 - check the application-name and deployment group name - - name: Create CodeDeploy Deployment - id: deploy - run: | - aws deploy create-deployment \ - --application-name django-indexer \ - --deployment-group-name django-indexer-dev \ - --deployment-config-name CodeDeployDefault.AllAtOnce \ - --github-location repository=${{ github.repository }},commitId=${{ github.sha }} - -# name: Deploy to EC2 on Push - -# on: -# push: -# branches: -# - main -# - dev - -# jobs: -# deploy: -# runs-on: ubuntu-latest -# environment: -# name: ${{ github.ref == 'refs/heads/main' && 'prod' || 'dev' }} -# steps: -# - name: Checkout code -# uses: actions/checkout@v2 - -# - name: Set up SSH key -# uses: webfactory/ssh-agent@v0.5.3 -# with: -# ssh-private-key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} - -# - name: Push new code to EC2 -# run: | -# rsync -avz --exclude '.git*' --exclude 'node_modules' ./ ${{ vars.EC2_USER }}@${{ vars.EC2_SSH_HOST }}:/home/ec2-user/django-indexer -# echo "Code has been pushed to the EC2 instance." - -# - name: Check for pending migrations -# id: check_migrations -# run: | -# echo "Checking for pending migrations..." -# pending_migrations=$(ssh -o "StrictHostKeyChecking=no" ${{ vars.EC2_USER }}@${{ vars.EC2_SSH_HOST }} "cd /home/ec2-user/django-indexer && source env/bin/activate && python manage.py showmigrations --plan | grep '\[ \]'") -# echo "::set-output name=pending::${pending_migrations}" -# if [ -z "$pending_migrations" ]; then -# echo "No migrations found." -# else: -# echo "Migrations found, stopping services." - -# - name: Stop services if migrations are pending -# if: steps.check_migrations.outputs.pending -# run: | -# echo "Stopping services..." -# ssh -o "StrictHostKeyChecking=no" ${{ vars.EC2_USER }}@${{ vars.EC2_SSH_HOST }} "sudo systemctl stop gunicorn.service indexer.service" - -# - name: Run migrations -# if: steps.check_migrations.outputs.pending -# run: | -# echo "Running migrations..." -# ssh -o "StrictHostKeyChecking=no" ${{ vars.EC2_USER }}@${{ vars.EC2_SSH_HOST }} "cd /home/ec2-user/django-indexer && source env/bin/activate && python manage.py migrate" - -# - name: Run collectstatic -# run: | -# echo "Running collectstatic..." -# ssh -o "StrictHostKeyChecking=no" ${{ vars.EC2_USER }}@${{ vars.EC2_SSH_HOST }} "cd /home/ec2-user/django-indexer && source env/bin/activate && python manage.py collectstatic --noinput" - -# - name: Restart services if migrations were run -# if: steps.check_migrations.outputs.pending -# run: | -# echo "Restarting services after migrations..." -# ssh -o "StrictHostKeyChecking=no" ${{ vars.EC2_USER }}@${{ vars.EC2_SSH_HOST }} "sudo systemctl restart gunicorn.service indexer.service" - -# - name: Restart services if no migrations -# if: steps.check_migrations.outputs.pending == '' -# run: | -# echo "Restarting services without migration..." -# ssh -o "StrictHostKeyChecking=no" ${{ vars.EC2_USER }}@${{ vars.EC2_SSH_HOST }} "sudo systemctl restart gunicorn.service" diff --git a/accounts/admin.py b/accounts/admin.py index fb44fbe..3b8aca7 100644 --- a/accounts/admin.py +++ b/accounts/admin.py @@ -1,25 +1,52 @@ from django.contrib import admin + from .models import Account + @admin.register(Account) class AccountAdmin(admin.ModelAdmin): - list_display = ('id', 'total_donations_in_usd', 'total_donations_out_usd', 'total_matching_pool_allocations_usd', 'donors_count') - search_fields = ('id',) # Allow searching by account address - list_filter = ('total_donations_in_usd', 'total_donations_out_usd') # Filter by donation amounts - ordering = ('-total_donations_in_usd',) # Default ordering + list_display = ( + "id", + "total_donations_in_usd", + "total_donations_out_usd", + "total_matching_pool_allocations_usd", + "donors_count", + ) + search_fields = ("id",) # Allow searching by account address + list_filter = ( + "total_donations_in_usd", + "total_donations_out_usd", + ) # Filter by donation amounts + ordering = ("-total_donations_in_usd",) # Default ordering # Optionally, format decimal fields for better readability in the admin def total_donations_in_usd_display(self, obj): return "${:,.2f}".format(obj.total_donations_in_usd) - total_donations_in_usd_display.admin_order_field = 'total_donations_in_usd' - total_donations_in_usd_display.short_description = 'Total Donations Received (USD)' + + total_donations_in_usd_display.admin_order_field = "total_donations_in_usd" + total_donations_in_usd_display.short_description = "Total Donations Received (USD)" def total_donations_out_usd_display(self, obj): return "${:,.2f}".format(obj.total_donations_out_usd) - total_donations_out_usd_display.admin_order_field = 'total_donations_out_usd' - total_donations_out_usd_display.short_description = 'Total Donations Sent (USD)' + + total_donations_out_usd_display.admin_order_field = "total_donations_out_usd" + total_donations_out_usd_display.short_description = "Total Donations Sent (USD)" def total_matching_pool_allocations_usd_display(self, obj): return "${:,.2f}".format(obj.total_matching_pool_allocations_usd) - total_matching_pool_allocations_usd_display.admin_order_field = 'total_matching_pool_allocations_usd' - total_matching_pool_allocations_usd_display.short_description = 'Total Matching Pool Allocations (USD)' + + total_matching_pool_allocations_usd_display.admin_order_field = ( + "total_matching_pool_allocations_usd" + ) + total_matching_pool_allocations_usd_display.short_description = ( + "Total Matching Pool Allocations (USD)" + ) + + def has_add_permission(self, request): + return False + + def has_change_permission(self, request, obj=None): + return False + + def has_delete_permission(self, request, obj=None): + return False diff --git a/activities/admin.py b/activities/admin.py index cab9f72..219e369 100644 --- a/activities/admin.py +++ b/activities/admin.py @@ -1,30 +1,52 @@ from django.contrib import admin from django.utils.html import format_html -from .models import Activity, Account + +from .models import Account, Activity + @admin.register(Activity) class ActivityAdmin(admin.ModelAdmin): - list_display = ('id', 'signer_address', 'receiver_address', 'timestamp', 'type', 'transaction_link', 'action_result') - list_filter = ('timestamp', 'type', 'signer', 'receiver') - search_fields = ('signer__id', 'receiver__id', 'tx_hash') - date_hierarchy = 'timestamp' - ordering = ('-timestamp',) + list_display = ( + "id", + "signer_address", + "receiver_address", + "timestamp", + "type", + "transaction_link", + "action_result", + ) + list_filter = ("timestamp", "type", "signer", "receiver") + search_fields = ("signer__id", "receiver__id", "tx_hash") + date_hierarchy = "timestamp" + ordering = ("-timestamp",) def signer_address(self, obj): return obj.signer.id - signer_address.admin_order_field = 'signer' - signer_address.short_description = 'Signer Address' + + signer_address.admin_order_field = "signer" + signer_address.short_description = "Signer Address" def receiver_address(self, obj): return obj.receiver.id - receiver_address.admin_order_field = 'receiver' - receiver_address.short_description = 'Receiver Address' + + receiver_address.admin_order_field = "receiver" + receiver_address.short_description = "Receiver Address" def transaction_link(self, obj): url = f"https://nearblocks.io?query={obj.tx_hash}" return format_html('{}', url, obj.tx_hash) - transaction_link.short_description = 'Transaction Hash' # Sets the column header + + transaction_link.short_description = "Transaction Hash" # Sets the column header # def action_result_summary(self, obj): # return "Has Result" if obj.action_result else "No Result" # action_result_summary.short_description = 'Action Result' + + def has_add_permission(self, request): + return False + + def has_change_permission(self, request, obj=None): + return False + + def has_delete_permission(self, request, obj=None): + return False diff --git a/appspec-dev.yml b/appspec-dev.yml new file mode 100644 index 0000000..192e4cf --- /dev/null +++ b/appspec-dev.yml @@ -0,0 +1,16 @@ +version: 0.0 +os: linux +files: + - source: / + destination: /home/ec2-user/django-indexer +hooks: + # # Install: + AfterInstall: + - location: scripts/after_install_dev.sh + timeout: 300 + runas: ec2-user +# ApplicationStart: +# - location: scripts/application_start.sh +# timeout: 300 +# runas: root +# # ValidateService: diff --git a/appspec-testnet.yml b/appspec-testnet.yml new file mode 100644 index 0000000..b006f0e --- /dev/null +++ b/appspec-testnet.yml @@ -0,0 +1,16 @@ +version: 0.0 +os: linux +files: + - source: / + destination: /home/ec2-user/django-indexer-testnet +hooks: + # # Install: + AfterInstall: + - location: scripts/after_install_testnet.sh + timeout: 300 + runas: ec2-user +# ApplicationStart: +# - location: scripts/application_start.sh +# timeout: 300 +# runas: root +# # ValidateService: diff --git a/base/settings.py b/base/settings.py index ce99c04..7525f40 100644 --- a/base/settings.py +++ b/base/settings.py @@ -30,7 +30,12 @@ # TODO: update before prod release SECRET_KEY = "django-insecure-=r_v_es6w6rxv42^#kc2hca6p%=fe_*cog_5!t%19zea!enlju" -ALLOWED_HOSTS = ["ec2-100-27-57-47.compute-1.amazonaws.com", "127.0.0.1"] +ALLOWED_HOSTS = [ + "ec2-100-27-57-47.compute-1.amazonaws.com", + "127.0.0.1", + "dev.potlock.io", + "test-dev.potlock.io", +] # Env vars AWS_ACCESS_KEY_ID = os.environ.get("PL_AWS_ACCESS_KEY_ID") @@ -52,6 +57,8 @@ REDIS_PORT = os.environ.get("PL_REDIS_PORT", 6379) SENTRY_DSN = os.environ.get("PL_SENTRY_DSN") +POTLOCK_TLA = "potlock.testnet" if ENVIRONMENT == "testnet" else "potlock.near" + BLOCK_SAVE_HEIGHT = os.environ.get("BLOCK_SAVE_HEIGHT") COINGECKO_URL = ( @@ -213,6 +220,9 @@ log_level = getattr(logging, LOG_LEVEL, logging.INFO) # print("LOG_LEVEL: ", LOG_LEVEL) +# Set log group name based on environment +log_group_name = f"django-indexer-{ENVIRONMENT}" + # Setting up the logging configuration LOGGING = { "version": 1, @@ -254,7 +264,7 @@ LOGGING["handlers"]["watchtower"] = { "class": "watchtower.CloudWatchLogHandler", "boto3_client": boto3_logs_client, - "log_group_name": "django-indexer", + "log_group_name": log_group_name, "formatter": "standard", "level": log_level, } diff --git a/donations/admin.py b/donations/admin.py index 43f87d3..f27994d 100644 --- a/donations/admin.py +++ b/donations/admin.py @@ -59,3 +59,12 @@ def formfield_for_dbfield(self, db_field, request, **kwargs): field.widget.format = "%d-%m-%Y %H:%M" field.widget.attrs.update({"class": "vDateField", "size": "20"}) return field + + def has_add_permission(self, request): + return False + + def has_change_permission(self, request, obj=None): + return False + + def has_delete_permission(self, request, obj=None): + return False diff --git a/indexer_app/admin.py b/indexer_app/admin.py index 3b56656..e94e67a 100644 --- a/indexer_app/admin.py +++ b/indexer_app/admin.py @@ -1,7 +1,18 @@ from django.contrib import admin + from .models import BlockHeight + @admin.register(BlockHeight) class BlockHeightAdmin(admin.ModelAdmin): - list_display = ('id', 'block_height', 'updated_at') - ordering = ('-updated_at',) + list_display = ("id", "block_height", "updated_at") + ordering = ("-updated_at",) + + def has_add_permission(self, request): + return False + + def has_change_permission(self, request, obj=None): + return False + + def has_delete_permission(self, request, obj=None): + return False diff --git a/indexer_app/handler.py b/indexer_app/handler.py index 9d86fbf..0cdfa99 100644 --- a/indexer_app/handler.py +++ b/indexer_app/handler.py @@ -2,6 +2,7 @@ import json from datetime import datetime +from django.conf import settings from django.core.cache import cache from near_lake_framework import near_primitives @@ -49,8 +50,9 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess for shard in streamer_message.shards: for receipt_execution_outcome in shard.receipt_execution_outcomes: # we only want to proceed if it's a potlock tx and it succeeded.... (unreadable if statement?) + lists_contract = "lists." + settings.POTLOCK_TLA if not receipt_execution_outcome.receipt.receiver_id.endswith( - "potlock.near" + settings.POTLOCK_TLA ) or ( "SuccessReceiptId" not in receipt_execution_outcome.execution_outcome.outcome.status @@ -232,7 +234,7 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess logger.info( f"registrations incoming: {args_dict}, {action}" ) - if receiver_id != "lists.potlock.near": + if receiver_id != lists_contract: break await handle_new_list_registration( args_dict, receiver_id, signer_id, receipt, status_obj @@ -306,7 +308,7 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess "owner_remove_admins" ): # TODO: use update_admins event instead of method call to handle all cases logger.info(f"attempting to remove admins....: {args_dict}") - if receiver_id != "lists.potlock.near": + if receiver_id != lists_contract: break await handle_list_admin_removal( args_dict, receiver_id, signer_id, receipt.receipt_id @@ -315,14 +317,14 @@ async def handle_streamer_message(streamer_message: near_primitives.StreamerMess case "create_list": logger.info(f"creating list... {args_dict}, {action}") - if receiver_id != "lists.potlock.near": + if receiver_id != lists_contract: break await handle_new_list(signer_id, receiver_id, status_obj) break case "upvote": logger.info(f"up voting... {args_dict}") - if receiver_id != "lists.potlock.near": + if receiver_id != lists_contract: break await handle_list_upvote( args_dict, receiver_id, signer_id, receipt.receipt_id diff --git a/indexer_app/utils.py b/indexer_app/utils.py index 7e44c2f..5f394a3 100644 --- a/indexer_app/utils.py +++ b/indexer_app/utils.py @@ -633,10 +633,11 @@ async def handle_new_donations( log_data: list, ): logger.info(f"new donation data: {data}, {receiverId}") + donate_contract_addr = "donate." + settings.POTLOCK_TLA if ( actionName == "direct" - ) and receiverId == "donate.potlock.near": # early pot donations followed similarly to direct donations i.e they returned result instead of events. + ) and receiverId == donate_contract_addr: # early pot donations followed similarly to direct donations i.e they returned result instead of events. logger.info("calling donate contract...") # Handle direct donation diff --git a/lists/admin.py b/lists/admin.py index ae08c51..db244ed 100644 --- a/lists/admin.py +++ b/lists/admin.py @@ -1,22 +1,68 @@ from django.contrib import admin -from .models import List, ListUpvote, ListRegistration, Account + +from .models import Account, List, ListRegistration, ListUpvote + @admin.register(List) class ListAdmin(admin.ModelAdmin): - list_display = ('id', 'name', 'owner', 'default_registration_status', 'created_at', 'updated_at') - list_filter = ('created_at', 'updated_at', 'default_registration_status') - search_fields = ('name', 'owner__id') - ordering = ('-created_at',) + list_display = ( + "id", + "name", + "owner", + "default_registration_status", + "created_at", + "updated_at", + ) + list_filter = ("created_at", "updated_at", "default_registration_status") + search_fields = ("name", "owner__id") + ordering = ("-created_at",) + + def has_add_permission(self, request): + return False + + def has_change_permission(self, request, obj=None): + return False + + def has_delete_permission(self, request, obj=None): + return False + @admin.register(ListUpvote) class ListUpvoteAdmin(admin.ModelAdmin): - list_display = ('id', 'list', 'account', 'created_at') - list_filter = ('created_at',) - search_fields = ('list__name', 'account__id') + list_display = ("id", "list", "account", "created_at") + list_filter = ("created_at",) + search_fields = ("list__name", "account__id") + + def has_add_permission(self, request): + return False + + def has_change_permission(self, request, obj=None): + return False + + def has_delete_permission(self, request, obj=None): + return False + @admin.register(ListRegistration) class ListRegistrationAdmin(admin.ModelAdmin): - list_display = ('id', 'list', 'registrant', 'registered_by', 'status', 'submitted_at', 'updated_at') - list_filter = ('status', 'submitted_at', 'updated_at') - search_fields = ('list__name', 'registrant__id', 'registered_by__id') - ordering = ('-submitted_at',) + list_display = ( + "id", + "list", + "registrant", + "registered_by", + "status", + "submitted_at", + "updated_at", + ) + list_filter = ("status", "submitted_at", "updated_at") + search_fields = ("list__name", "registrant__id", "registered_by__id") + ordering = ("-submitted_at",) + + def has_add_permission(self, request): + return False + + def has_change_permission(self, request, obj=None): + return False + + def has_delete_permission(self, request, obj=None): + return False diff --git a/pots/admin.py b/pots/admin.py index 09e40b3..aca414b 100644 --- a/pots/admin.py +++ b/pots/admin.py @@ -46,6 +46,15 @@ def get_form(self, request, obj=None, **kwargs): ) return form + def has_add_permission(self, request): + return False + + def has_change_permission(self, request, obj=None): + return False + + def has_delete_permission(self, request, obj=None): + return False + class PotForm(forms.ModelForm): class Meta: @@ -73,6 +82,15 @@ def get_form(self, request, obj=None, **kwargs): form.base_fields["admins"].queryset = obj.admins.all() return form + def has_add_permission(self, request): + return False + + def has_change_permission(self, request, obj=None): + return False + + def has_delete_permission(self, request, obj=None): + return False + @admin.register(PotApplication) class PotApplicationAdmin(admin.ModelAdmin): @@ -80,6 +98,15 @@ class PotApplicationAdmin(admin.ModelAdmin): search_fields = ("pot__id", "applicant__id") list_filter = ("status", "submitted_at") + def has_add_permission(self, request): + return False + + def has_change_permission(self, request, obj=None): + return False + + def has_delete_permission(self, request, obj=None): + return False + @admin.register(PotApplicationReview) class PotApplicationReviewAdmin(admin.ModelAdmin): @@ -95,6 +122,15 @@ class PotApplicationReviewAdmin(admin.ModelAdmin): search_fields = ("application__id", "reviewer__id") list_filter = ("status", "reviewed_at") + def has_add_permission(self, request): + return False + + def has_change_permission(self, request, obj=None): + return False + + def has_delete_permission(self, request, obj=None): + return False + @admin.register(PotPayout) class PotPayoutAdmin(admin.ModelAdmin): @@ -102,6 +138,15 @@ class PotPayoutAdmin(admin.ModelAdmin): search_fields = ("pot__id", "recipient__id") list_filter = ("paid_at",) + def has_add_permission(self, request): + return False + + def has_change_permission(self, request, obj=None): + return False + + def has_delete_permission(self, request, obj=None): + return False + @admin.register(PotPayoutChallenge) class PotPayoutChallengeAdmin(admin.ModelAdmin): @@ -109,9 +154,27 @@ class PotPayoutChallengeAdmin(admin.ModelAdmin): search_fields = ("challenger__id", "pot__id") list_filter = ("created_at",) + def has_add_permission(self, request): + return False + + def has_change_permission(self, request, obj=None): + return False + + def has_delete_permission(self, request, obj=None): + return False + @admin.register(PotPayoutChallengeAdminResponse) class PotPayoutChallengeAdminResponseAdmin(admin.ModelAdmin): list_display = ("id", "pot", "admin", "created_at", "resolved") search_fields = ("admin__id", "challenge__id") list_filter = ("created_at", "resolved") + + def has_add_permission(self, request): + return False + + def has_change_permission(self, request, obj=None): + return False + + def has_delete_permission(self, request, obj=None): + return False diff --git a/pots/utils.py b/pots/utils.py index 01bfab6..1a5f991 100644 --- a/pots/utils.py +++ b/pots/utils.py @@ -4,12 +4,12 @@ def match_pot_factory_version_pattern(receiver): - """Matches the base pot factory version pattern without a subaccount.""" + """Matches the base pot factory version pattern without a subaccount. NB: does not currently handle testnet factory.""" pattern = f"^{BASE_PATTERN}" return bool(re.match(pattern, receiver)) def match_pot_subaccount_version_pattern(receiver): - """Matches the pot factory version pattern with a subaccount.""" + """Matches the pot factory version pattern with a subaccount. NB: does not currently handle testnet factory.""" pattern = f"^[a-zA-Z0-9_]+\.{BASE_PATTERN}" return bool(re.match(pattern, receiver)) diff --git a/scripts/after_install.sh b/scripts/after_install.sh old mode 100755 new mode 100644 index 6c56c5b..152ad3a --- a/scripts/after_install.sh +++ b/scripts/after_install.sh @@ -1,65 +1,5 @@ -# #!/bin/bash -# # Log output to a specific file -# LOG_FILE="/home/ec2-user/django-indexer/logs/deploy.log" - -# echo -e "\n\n" >> "$LOG_FILE" -# echo "=========================================" >> "$LOG_FILE" -# echo "Running after_install.sh at $(date '+%Y-%m-%d %H:%M:%S')" >> "$LOG_FILE" -# echo "=========================================" >> "$LOG_FILE" - -# # Load env vars -# source /home/ec2-user/.bashrc - -# # Set correct ownership recursively for project directory -# sudo chown -R ec2-user:nginx /home/ec2-user/django-indexer/ -# echo "$(date '+%Y-%m-%d %H:%M:%S') - Corrected ownership to ec2-user:nginx" >> "$LOG_FILE" - -# # Set the necessary permissions -# sudo chmod -R 775 /home/ec2-user/django-indexer/ -# echo "$(date '+%Y-%m-%d %H:%M:%S') - Set permissions to 775" >> "$LOG_FILE" - -# # Restart nginx to apply any configuration changes -# sudo systemctl restart nginx -# echo "$(date '+%Y-%m-%d %H:%M:%S') - Restarted nginx" >> "$LOG_FILE" - -# # Define the project directory -# PROJECT_DIR="/home/ec2-user/django-indexer" - -# # Navigate to the project directory -# cd "$PROJECT_DIR" - -# # Install dependencies using Poetry -# echo "$(date '+%Y-%m-%d %H:%M:%S') - Installing dependencies with Poetry" >> "$LOG_FILE" -# poetry install >> "$LOG_FILE" -# echo "$(date '+%Y-%m-%d %H:%M:%S') - Dependencies installed" >> "$LOG_FILE" - -# # Log the full output of showmigrations to diagnose -# echo "Checking for pending migrations..." >> "$LOG_FILE" -# poetry run python manage.py showmigrations >> "$LOG_FILE" 2>&1 - -# # Check for unapplied migrations -# PENDING_MIGRATIONS=$(poetry run python manage.py showmigrations | grep "\[ \]" | wc -l) # Count unapplied migrations - -# if [ "$PENDING_MIGRATIONS" -gt 0 ]; then -# echo "Migrations found; stopping services..." >> "$LOG_FILE" -# sudo systemctl stop gunicorn celery-indexer-worker celery-beat-worker celery-beat - -# echo 'Applying migrations...' >> "$LOG_FILE" -# poetry run python manage.py migrate >> "$LOG_FILE" 2>&1 - -# echo 'Starting services...' >> "$LOG_FILE" -# sudo systemctl start gunicorn celery-indexer-worker celery-beat-worker celery-beat -# else -# echo 'No migrations found. Running collectstatic and restarting services...' >> "$LOG_FILE" -# poetry run python manage.py collectstatic --noinput >> "$LOG_FILE" 2>&1 -# sudo systemctl restart gunicorn celery-indexer-worker celery-beat-worker celery-beat -# fi - -# echo "$(date '+%Y-%m-%d %H:%M:%S') - after_install.sh completed" >> "$LOG_FILE" - - - #!/bin/bash +# TODO: deprecate this (move to _dev & _testnet files) # Log output to a specific file LOG_FILE="/home/ec2-user/django-indexer/logs/deploy.log" @@ -124,4 +64,4 @@ else sudo systemctl restart gunicorn celery-indexer-worker celery-beat-worker celery-beat fi -echo "$(date '+%Y-%m-%d %H:%M:%S') - after_install.sh completed" >> "$LOG_FILE" +echo "$(date '+%Y-%m-%d %H:%M:%S') - after_install.sh completed" >> "$LOG_FILE" \ No newline at end of file diff --git a/scripts/after_install_dev.sh b/scripts/after_install_dev.sh new file mode 100755 index 0000000..0cc5a0a --- /dev/null +++ b/scripts/after_install_dev.sh @@ -0,0 +1,140 @@ +#!/bin/bash +# Log output to a specific file +LOG_FILE="/home/ec2-user/django-indexer-dev/logs/deploy.log" + +echo -e "\n\n" >> "$LOG_FILE" +echo "=========================================" >> "$LOG_FILE" +echo "Running after_install_dev.sh at $(date '+%Y-%m-%d %H:%M:%S')" >> "$LOG_FILE" +echo "=========================================" >> "$LOG_FILE" + +# Load env vars +export PL_ENVIRONMENT=dev +source /home/ec2-user/.bashrc + +# Set correct ownership recursively for project directory +sudo chown -R ec2-user:nginx /home/ec2-user/django-indexer-dev/ +echo "$(date '+%Y-%m-%d %H:%M:%S') - Corrected ownership to ec2-user:nginx" >> "$LOG_FILE" + +# Set the necessary permissions +sudo chmod -R 775 /home/ec2-user/django-indexer-dev/ +echo "$(date '+%Y-%m-%d %H:%M:%S') - Set permissions to 775" >> "$LOG_FILE" + +# Restart nginx to apply any configuration changes +sudo systemctl restart nginx +echo "$(date '+%Y-%m-%d %H:%M:%S') - Restarted nginx" >> "$LOG_FILE" + +# Define the project directory +PROJECT_DIR="/home/ec2-user/django-indexer-dev" + +# Navigate to the project directory +cd "$PROJECT_DIR" + +# Source the specific poetry virtual environment +source "/home/ec2-user/.cache/pypoetry/virtualenvs/django-indexer-Y-SQFfhb-py3.11/bin/activate" + +# Install dependencies using Poetry +echo "$(date '+%Y-%m-%d %H:%M:%S') - Installing dependencies with Poetry" >> "$LOG_FILE" +poetry install >> "$LOG_FILE" +echo "$(date '+%Y-%m-%d %H:%M:%S') - Dependencies installed" >> "$LOG_FILE" + +# Check if there are pending migrations and log the output +echo "Checking for pending migrations..." >> "$LOG_FILE" +PENDING_MIGRATIONS=$(poetry run python manage.py showmigrations | grep '\[ \]' 2>&1) # Redirect stderr to stdout +echo "Migration check output: $PENDING_MIGRATIONS" >> "$LOG_FILE" + +# Log the full output of showmigrations +echo "Checking for pending migrations..." >> "$LOG_FILE" +poetry run python manage.py showmigrations >> "$LOG_FILE" 2>&1 # Logging full output to diagnose + +# Check for unapplied migrations +PENDING_MIGRATIONS=$(poetry run python manage.py showmigrations | grep "\[ \]" | wc -l) # Count unapplied migrations + +if [ "$PENDING_MIGRATIONS" -gt 0 ]; then + echo "Migrations found; stopping services..." >> "$LOG_FILE" + sudo systemctl stop gunicorn-dev celery-indexer-worker-dev celery-beat-worker-dev celery-beat-dev + + echo 'Applying migrations...' >> "$LOG_FILE" + poetry run python manage.py migrate >> "$LOG_FILE" 2>&1 + + echo 'Starting services...' >> "$LOG_FILE" + sudo systemctl start gunicorn-dev celery-indexer-worker-dev celery-beat-worker-dev celery-beat-dev +else + echo 'No migrations found. Running collectstatic and restarting services...' >> "$LOG_FILE" + poetry run python manage.py collectstatic --noinput >> "$LOG_FILE" 2>&1 + sudo systemctl restart gunicorn-dev celery-indexer-worker-dev celery-beat-worker-dev celery-beat-dev +fi + +echo "$(date '+%Y-%m-%d %H:%M:%S') - after_install_dev.sh completed" >> "$LOG_FILE" + + + + +# #!/bin/bash +# # Log output to a specific file +# LOG_FILE="/home/ec2-user/django-indexer-dev/logs/deploy.log" + +# # print placeholder +# echo -e "\n THIS IS A PLACEHOLDER \n" >> "$LOG_FILE" + +# echo -e "\n\n" >> "$LOG_FILE" +# echo "=========================================" >> "$LOG_FILE" +# echo "Running after_install_dev.sh at $(date '+%Y-%m-%d %H:%M:%S')" >> "$LOG_FILE" +# echo "=========================================" >> "$LOG_FILE" + +# # Load env vars +# source /home/ec2-user/.bashrc + +# # Set correct ownership recursively for project directory +# sudo chown -R ec2-user:nginx /home/ec2-user/django-indexer/ +# echo "$(date '+%Y-%m-%d %H:%M:%S') - Corrected ownership to ec2-user:nginx" >> "$LOG_FILE" + +# # Set the necessary permissions +# sudo chmod -R 775 /home/ec2-user/django-indexer/ +# echo "$(date '+%Y-%m-%d %H:%M:%S') - Set permissions to 775" >> "$LOG_FILE" + +# # Restart nginx to apply any configuration changes +# sudo systemctl restart nginx +# echo "$(date '+%Y-%m-%d %H:%M:%S') - Restarted nginx" >> "$LOG_FILE" + +# # Define the project directory +# PROJECT_DIR="/home/ec2-user/django-indexer" + +# # Navigate to the project directory +# cd "$PROJECT_DIR" + +# # Source the specific poetry virtual environment +# source "/home/ec2-user/.cache/pypoetry/virtualenvs/django-indexer-Y-SQFfhb-py3.11/bin/activate" # TODO: UPDATE THIS + +# # Install dependencies using Poetry +# echo "$(date '+%Y-%m-%d %H:%M:%S') - Installing dependencies with Poetry" >> "$LOG_FILE" +# poetry install >> "$LOG_FILE" +# echo "$(date '+%Y-%m-%d %H:%M:%S') - Dependencies installed" >> "$LOG_FILE" + +# # Check if there are pending migrations and log the output +# echo "Checking for pending migrations..." >> "$LOG_FILE" +# PENDING_MIGRATIONS=$(poetry run python manage.py showmigrations | grep '\[ \]' 2>&1) # Redirect stderr to stdout +# echo "Migration check output: $PENDING_MIGRATIONS" >> "$LOG_FILE" + +# # Log the full output of showmigrations +# echo "Checking for pending migrations..." >> "$LOG_FILE" +# poetry run python manage.py showmigrations >> "$LOG_FILE" 2>&1 # Logging full output to diagnose + +# # Check for unapplied migrations +# PENDING_MIGRATIONS=$(poetry run python manage.py showmigrations | grep "\[ \]" | wc -l) # Count unapplied migrations + +# if [ "$PENDING_MIGRATIONS" -gt 0 ]; then +# echo "Migrations found; stopping services..." >> "$LOG_FILE" +# sudo systemctl stop gunicorn celery-indexer-worker celery-beat-worker celery-beat + +# echo 'Applying migrations...' >> "$LOG_FILE" +# poetry run python manage.py migrate >> "$LOG_FILE" 2>&1 + +# echo 'Starting services...' >> "$LOG_FILE" +# sudo systemctl start gunicorn celery-indexer-worker celery-beat-worker celery-beat +# else +# echo 'No migrations found. Running collectstatic and restarting services...' >> "$LOG_FILE" +# poetry run python manage.py collectstatic --noinput >> "$LOG_FILE" 2>&1 +# sudo systemctl restart gunicorn celery-indexer-worker celery-beat-worker celery-beat +# fi + +# echo "$(date '+%Y-%m-%d %H:%M:%S') - after_install_dev.sh completed" >> "$LOG_FILE" diff --git a/scripts/after_install_testnet.sh b/scripts/after_install_testnet.sh new file mode 100755 index 0000000..94c517b --- /dev/null +++ b/scripts/after_install_testnet.sh @@ -0,0 +1,67 @@ +#!/bin/bash +# Log output to a specific file +LOG_FILE="/home/ec2-user/django-indexer-testnet/logs/deploy.log" + +echo -e "\n\n" >> "$LOG_FILE" +echo "=========================================" >> "$LOG_FILE" +echo "Running after_install_testnet.sh at $(date '+%Y-%m-%d %H:%M:%S')" >> "$LOG_FILE" +echo "=========================================" >> "$LOG_FILE" + +# Load env vars +export PL_ENVIRONMENT=testnet +source /home/ec2-user/.bashrc + +# Set correct ownership recursively for project directory +sudo chown -R ec2-user:nginx /home/ec2-user/django-indexer-testnet/ +echo "$(date '+%Y-%m-%d %H:%M:%S') - Corrected ownership to ec2-user:nginx" >> "$LOG_FILE" + +# Set the necessary permissions +sudo chmod -R 775 /home/ec2-user/django-indexer-testnet/ +echo "$(date '+%Y-%m-%d %H:%M:%S') - Set permissions to 775" >> "$LOG_FILE" + +# Restart nginx to apply any configuration changes +sudo systemctl restart nginx +echo "$(date '+%Y-%m-%d %H:%M:%S') - Restarted nginx" >> "$LOG_FILE" + +# Define the project directory +PROJECT_DIR="/home/ec2-user/django-indexer-testnet" + +# Navigate to the project directory +cd "$PROJECT_DIR" + +# Source the specific poetry virtual environment +source "/home/ec2-user/.cache/pypoetry/virtualenvs/django-indexer-AhfQkQzj-py3.11/bin/activate" + +# Install dependencies using Poetry +echo "$(date '+%Y-%m-%d %H:%M:%S') - Installing dependencies with Poetry" >> "$LOG_FILE" +poetry install >> "$LOG_FILE" +echo "$(date '+%Y-%m-%d %H:%M:%S') - Dependencies installed" >> "$LOG_FILE" + +# Check if there are pending migrations and log the output +echo "Checking for pending migrations..." >> "$LOG_FILE" +PENDING_MIGRATIONS=$(poetry run python manage.py showmigrations | grep '\[ \]' 2>&1) # Redirect stderr to stdout +echo "Migration check output: $PENDING_MIGRATIONS" >> "$LOG_FILE" + +# Log the full output of showmigrations +echo "Checking for pending migrations..." >> "$LOG_FILE" +poetry run python manage.py showmigrations >> "$LOG_FILE" 2>&1 # Logging full output to diagnose + +# Check for unapplied migrations +PENDING_MIGRATIONS=$(poetry run python manage.py showmigrations | grep "\[ \]" | wc -l) # Count unapplied migrations + +if [ "$PENDING_MIGRATIONS" -gt 0 ]; then + echo "Migrations found; stopping services..." >> "$LOG_FILE" + sudo systemctl stop gunicorn-testnet celery-indexer-worker-testnet celery-beat-worker-testnet celery-beat-testnet + + echo 'Applying migrations...' >> "$LOG_FILE" + poetry run python manage.py migrate >> "$LOG_FILE" 2>&1 + + echo 'Starting services...' >> "$LOG_FILE" + sudo systemctl start gunicorn-testnet celery-indexer-worker-testnet celery-beat-worker-testnet celery-beat-testnet +else + echo 'No migrations found. Running collectstatic and restarting services...' >> "$LOG_FILE" + poetry run python manage.py collectstatic --noinput >> "$LOG_FILE" 2>&1 + sudo systemctl restart gunicorn-testnet celery-indexer-worker-testnet celery-beat-worker-testnet celery-beat-testnet +fi + +echo "$(date '+%Y-%m-%d %H:%M:%S') - after_install_testnet.sh completed" >> "$LOG_FILE" diff --git a/tokens/admin.py b/tokens/admin.py index 0ca45d6..f783399 100644 --- a/tokens/admin.py +++ b/tokens/admin.py @@ -1,18 +1,40 @@ from django.contrib import admin + from .models import Token, TokenHistoricalPrice + @admin.register(Token) class TokenAdmin(admin.ModelAdmin): - list_display = ('id', 'decimals', 'get_most_recent_price') - search_fields = ('id',) + list_display = ("id", "decimals", "get_most_recent_price") + search_fields = ("id",) def get_most_recent_price(self, obj): price = obj.get_most_recent_price() return price.price_usd if price else None - get_most_recent_price.short_description = 'Most Recent Price (USD)' + + get_most_recent_price.short_description = "Most Recent Price (USD)" + + def has_add_permission(self, request): + return False + + def has_change_permission(self, request, obj=None): + return False + + def has_delete_permission(self, request, obj=None): + return False + @admin.register(TokenHistoricalPrice) class TokenHistoricalPriceAdmin(admin.ModelAdmin): - list_display = ('token', 'timestamp', 'price_usd') - search_fields = ('token__id',) - list_filter = ('timestamp',) + list_display = ("token", "timestamp", "price_usd") + search_fields = ("token__id",) + list_filter = ("timestamp",) + + def has_add_permission(self, request): + return False + + def has_change_permission(self, request, obj=None): + return False + + def has_delete_permission(self, request, obj=None): + return False From a95d83e67019d69d1584559b7f859a9e0a8feb5c Mon Sep 17 00:00:00 2001 From: Lachlan Glen <54282009+lachlanglen@users.noreply.github.com> Date: Fri, 31 May 2024 18:30:10 -0400 Subject: [PATCH 2/7] add debug logs --- scripts/after_install_dev.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/after_install_dev.sh b/scripts/after_install_dev.sh index 0cc5a0a..9ba2224 100755 --- a/scripts/after_install_dev.sh +++ b/scripts/after_install_dev.sh @@ -11,6 +11,9 @@ echo "=========================================" >> "$LOG_FILE" export PL_ENVIRONMENT=dev source /home/ec2-user/.bashrc +echo "PL_ENVIRONMENT: $PL_ENVIRONMENT" >> "$LOG_FILE" +echo "PL_POSTGRES_HOST: $PL_POSTGRES_HOST" >> "$LOG_FILE" + # Set correct ownership recursively for project directory sudo chown -R ec2-user:nginx /home/ec2-user/django-indexer-dev/ echo "$(date '+%Y-%m-%d %H:%M:%S') - Corrected ownership to ec2-user:nginx" >> "$LOG_FILE" From cd2f0b246646e9c2d0af64d6692144ee2c599612 Mon Sep 17 00:00:00 2001 From: Lachlan Glen <54282009+lachlanglen@users.noreply.github.com> Date: Fri, 31 May 2024 18:31:23 -0400 Subject: [PATCH 3/7] add logs --- scripts/after_install_dev.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/after_install_dev.sh b/scripts/after_install_dev.sh index 9ba2224..e735389 100755 --- a/scripts/after_install_dev.sh +++ b/scripts/after_install_dev.sh @@ -14,6 +14,9 @@ source /home/ec2-user/.bashrc echo "PL_ENVIRONMENT: $PL_ENVIRONMENT" >> "$LOG_FILE" echo "PL_POSTGRES_HOST: $PL_POSTGRES_HOST" >> "$LOG_FILE" +echo "PL_ENVIRONMENT: $PL_ENVIRONMENT" >> "$LOG_FILE" +echo "PL_POSTGRES_HOST: $PL_POSTGRES_HOST" >> "$LOG_FILE" + # Set correct ownership recursively for project directory sudo chown -R ec2-user:nginx /home/ec2-user/django-indexer-dev/ echo "$(date '+%Y-%m-%d %H:%M:%S') - Corrected ownership to ec2-user:nginx" >> "$LOG_FILE" From 7d770abb819111502acc4ed9884d4eaf22aa70a7 Mon Sep 17 00:00:00 2001 From: Lachlan Glen <54282009+lachlanglen@users.noreply.github.com> Date: Fri, 31 May 2024 18:40:55 -0400 Subject: [PATCH 4/7] fix appspec destination for dev --- appspec-dev.yml | 2 +- scripts/after_install_dev.sh | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/appspec-dev.yml b/appspec-dev.yml index 192e4cf..6cb73af 100644 --- a/appspec-dev.yml +++ b/appspec-dev.yml @@ -2,7 +2,7 @@ version: 0.0 os: linux files: - source: / - destination: /home/ec2-user/django-indexer + destination: /home/ec2-user/django-indexer-dev hooks: # # Install: AfterInstall: diff --git a/scripts/after_install_dev.sh b/scripts/after_install_dev.sh index e735389..0cc5a0a 100755 --- a/scripts/after_install_dev.sh +++ b/scripts/after_install_dev.sh @@ -11,12 +11,6 @@ echo "=========================================" >> "$LOG_FILE" export PL_ENVIRONMENT=dev source /home/ec2-user/.bashrc -echo "PL_ENVIRONMENT: $PL_ENVIRONMENT" >> "$LOG_FILE" -echo "PL_POSTGRES_HOST: $PL_POSTGRES_HOST" >> "$LOG_FILE" - -echo "PL_ENVIRONMENT: $PL_ENVIRONMENT" >> "$LOG_FILE" -echo "PL_POSTGRES_HOST: $PL_POSTGRES_HOST" >> "$LOG_FILE" - # Set correct ownership recursively for project directory sudo chown -R ec2-user:nginx /home/ec2-user/django-indexer-dev/ echo "$(date '+%Y-%m-%d %H:%M:%S') - Corrected ownership to ec2-user:nginx" >> "$LOG_FILE" From 1d81df12587bbddb9a5cc3273c60597b12922452 Mon Sep 17 00:00:00 2001 From: Lachlan Glen <54282009+lachlanglen@users.noreply.github.com> Date: Fri, 31 May 2024 18:47:10 -0400 Subject: [PATCH 5/7] clean up destination directory before installing in deployment (only dev) --- appspec-dev.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/appspec-dev.yml b/appspec-dev.yml index 6cb73af..02a6c66 100644 --- a/appspec-dev.yml +++ b/appspec-dev.yml @@ -4,7 +4,10 @@ files: - source: / destination: /home/ec2-user/django-indexer-dev hooks: - # # Install: + BeforeInstall: + - location: "echo 'Cleaning up destination directory' && rm -rf /home/ec2-user/django-indexer-dev/*" + timeout: 300 + runas: ec2-user AfterInstall: - location: scripts/after_install_dev.sh timeout: 300 From 41217edbfcfd2d8cf6a8f224a363293c72bd6387 Mon Sep 17 00:00:00 2001 From: Lachlan Glen <54282009+lachlanglen@users.noreply.github.com> Date: Fri, 31 May 2024 18:50:52 -0400 Subject: [PATCH 6/7] add clean_destination scripts --- appspec-dev.yml | 2 +- appspec-testnet.yml | 4 ++++ scripts/clean_destination_dev.sh | 8 ++++++++ scripts/clean_destination_testnet.sh | 8 ++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 scripts/clean_destination_dev.sh create mode 100644 scripts/clean_destination_testnet.sh diff --git a/appspec-dev.yml b/appspec-dev.yml index 02a6c66..f83a7fc 100644 --- a/appspec-dev.yml +++ b/appspec-dev.yml @@ -5,7 +5,7 @@ files: destination: /home/ec2-user/django-indexer-dev hooks: BeforeInstall: - - location: "echo 'Cleaning up destination directory' && rm -rf /home/ec2-user/django-indexer-dev/*" + - location: scripts/clean_destination_dev.sh timeout: 300 runas: ec2-user AfterInstall: diff --git a/appspec-testnet.yml b/appspec-testnet.yml index b006f0e..3ed0e62 100644 --- a/appspec-testnet.yml +++ b/appspec-testnet.yml @@ -5,6 +5,10 @@ files: destination: /home/ec2-user/django-indexer-testnet hooks: # # Install: + BeforeInstall: + - location: scripts/clean_destination_testnet.sh + timeout: 300 + runas: ec2-user AfterInstall: - location: scripts/after_install_testnet.sh timeout: 300 diff --git a/scripts/clean_destination_dev.sh b/scripts/clean_destination_dev.sh new file mode 100644 index 0000000..638c035 --- /dev/null +++ b/scripts/clean_destination_dev.sh @@ -0,0 +1,8 @@ +#!/bin/bash +# Directory to clean +DEST_DIR="/home/ec2-user/django-indexer-dev" + +# Delete all contents of the destination directory +if [ -d "$DEST_DIR" ]; then + rm -rf "${DEST_DIR:?}/*" +fi \ No newline at end of file diff --git a/scripts/clean_destination_testnet.sh b/scripts/clean_destination_testnet.sh new file mode 100644 index 0000000..62b020a --- /dev/null +++ b/scripts/clean_destination_testnet.sh @@ -0,0 +1,8 @@ +#!/bin/bash +# Directory to clean +DEST_DIR="/home/ec2-user/django-indexer-testnet" + +# Delete all contents of the destination directory +if [ -d "$DEST_DIR" ]; then + rm -rf "${DEST_DIR:?}/*" +fi \ No newline at end of file From 0bf1a26a9313c8eafb015c1480938d635e41359d Mon Sep 17 00:00:00 2001 From: Lachlan Glen <54282009+lachlanglen@users.noreply.github.com> Date: Sat, 1 Jun 2024 11:15:38 -0400 Subject: [PATCH 7/7] remove BeforeInstall clean destination step --- appspec-dev.yml | 8 ++++---- appspec-testnet.yml | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/appspec-dev.yml b/appspec-dev.yml index f83a7fc..348d01b 100644 --- a/appspec-dev.yml +++ b/appspec-dev.yml @@ -4,10 +4,10 @@ files: - source: / destination: /home/ec2-user/django-indexer-dev hooks: - BeforeInstall: - - location: scripts/clean_destination_dev.sh - timeout: 300 - runas: ec2-user + # BeforeInstall: + # - location: scripts/clean_destination_dev.sh + # timeout: 300 + # runas: ec2-user AfterInstall: - location: scripts/after_install_dev.sh timeout: 300 diff --git a/appspec-testnet.yml b/appspec-testnet.yml index 3ed0e62..dafa210 100644 --- a/appspec-testnet.yml +++ b/appspec-testnet.yml @@ -5,10 +5,10 @@ files: destination: /home/ec2-user/django-indexer-testnet hooks: # # Install: - BeforeInstall: - - location: scripts/clean_destination_testnet.sh - timeout: 300 - runas: ec2-user + # BeforeInstall: + # - location: scripts/clean_destination_testnet.sh + # timeout: 300 + # runas: ec2-user AfterInstall: - location: scripts/after_install_testnet.sh timeout: 300