Skip to content

Commit

Permalink
Merge pull request #91 from PotLock/dev
Browse files Browse the repository at this point in the history
dev - prod
  • Loading branch information
Prometheo authored Oct 21, 2024
2 parents 87c8282 + 672e55e commit 0f36647
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 14 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Prod deploy to EC2 on Push

on:
push:
branches: [prod]

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/[email protected]
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 prod
run: cp appspec.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-${DATETIME}.zip" >> $GITHUB_ENV
echo "S3_BUCKET=django-indexer" >> $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-prod \
--deployment-config-name CodeDeployDefault.AllAtOnce \
--s3-location bucket=${{ env.S3_BUCKET }},bundleType=zip,key=${{ env.FILENAME }}
13 changes: 7 additions & 6 deletions base/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@

# SECURITY WARNING: keep the secret key used in production secret!
# TODO: update before prod release
SECRET_KEY = "django-insecure-=r_v_es6w6rxv42^#kc2hca6p%=fe_*cog_5!t%19zea!enlju"
SECRET_KEY = os.environ.get("PL_DJANGO_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",
"dev.potlock.io",
"test-dev.potlock.io",
"api.potlock.io"
# "alpha.potlock.io",
]

Expand All @@ -59,11 +60,11 @@
SENTRY_DSN = os.environ.get("PL_SENTRY_DSN")

# POTLOCK_TLA = "potlock.testnet" if ENVIRONMENT == "testnet" else "potlock.near"
POTLOCK_TLA = "potlock.testnet" if ENVIRONMENT == "testnet" else ("staging.potlock.near" if ENVIRONMENT == "staging" else "potlock.near")
POTLOCK_TLA = "potlock.testnet" if ENVIRONMENT == "testnet" else ("staging.potlock.near" if ENVIRONMENT == "dev" else "potlock.near")
# NADABOT_TLA = "nadabot.testnet" if ENVIRONMENT == "testnet" else "nadabot.near"
NADABOT_TLA = "nadabot.testnet" if ENVIRONMENT == "testnet" else ("staging.nadabot.near" if ENVIRONMENT == "staging" else "nadabot.near")
STELLAR_CONTRACT_ID = "CBP5F3C5SPPJRNRJSOOQQKUGX2CE2G6BRV34MOEBHNFGBRQ5ZSXNGWAB" if ENVIRONMENT == "testnet" else "CBP5F3C5SPPJRNRJSOOQQKUGX2CE2G6BRV34MOEBHNFGBRQ5ZSXNGWAB"
STELLAR_PROJECTS_REGISTRY_CONTRACT = "CBYUL5Y4GTIZAST3W2LVYKFTYNJA3EUG3MN4W2TTFONV6VXEACMRLBEP"
NADABOT_TLA = "nadabot.testnet" if ENVIRONMENT == "testnet" else ("staging.nadabot.near" if ENVIRONMENT == "dev" else "nadabot.near")
STELLAR_CONTRACT_ID = "CCVVNTUD6CFPKZ2C4JAZIQGCAK2S6D6KPP5IELGHTHHJPYV2B62GPJTK" if ENVIRONMENT == "testnet" else ("" if ENVIRONMENT == "dev" else "")
STELLAR_PROJECTS_REGISTRY_CONTRACT = "CAUINLSA42RCTY35UFGOM2NLKMSRM6FW6NP7AR4GTUZHUQZZWB6CRBSJ" if ENVIRONMENT == "testnet" else ("" if ENVIRONMENT == "dev" else "")
NEAR_SOCIAL_CONTRACT_ADDRESS = (
"v1.social08.testnet" if ENVIRONMENT == "testnet" else "social.near"
)
Expand All @@ -72,7 +73,7 @@
if ENVIRONMENT == "testnet":
POTLOCK_PATTERN = r'\.potlock\.testnet$'
NADABOT_PATTERN = r'\.nadabot\.testnet$'
elif ENVIRONMENT == "staging":
elif ENVIRONMENT == "dev":
POTLOCK_PATTERN = r'\.staging\.potlock\.near$'
NADABOT_PATTERN = r'\.staging\.nadabot\.near$'
else: # mainnet/prod
Expand Down
2 changes: 1 addition & 1 deletion indexer_app/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def stellar_event_indexer():
start_sequence = get_ledger_sequence()
# start_sequence = 12169
if not start_sequence:
start_sequence = 12169
start_sequence = 552451
jobs_logger.info(f"Ingesting Stellar events from ledger {start_sequence}... contracts: {contract_ids}")
try:
# Fetch events for the current sequence
Expand Down
1 change: 1 addition & 0 deletions indexer_app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,7 @@ def get_block_height() -> int:
record = BlockHeight.objects.filter(id=1).first()
if record:
return record.block_height
return 130852956



Expand Down
26 changes: 19 additions & 7 deletions scripts/after_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,30 @@ poetry run python manage.py showmigrations >> "$LOG_FILE" 2>&1 # Logging full o
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 "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
# 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
echo 'No migrations found.' >> "$LOG_FILE"
# 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

# Collect static
echo 'Running collectstatic...' >> "$LOG_FILE"
poetry run python manage.py collectstatic --noinput >> "$LOG_FILE" 2>&1

# Gracefully reload Gunicorn to apply the changes without downtime
echo 'Reloading Gunicorn...' >> "$LOG_FILE"
sudo systemctl kill --signal=HUP gunicorn

echo 'Restarting services...' >> "$LOG_FILE"
sudo systemctl restart celery-indexer-worker celery-beat-worker celery-beat

echo "$(date '+%Y-%m-%d %H:%M:%S') - after_install.sh completed" >> "$LOG_FILE"

0 comments on commit 0f36647

Please sign in to comment.