Skip to content

Commit

Permalink
fix: run migration in script (#2)
Browse files Browse the repository at this point in the history
* added compose

* edit commands

* edited commands

* fix exec cmd

* added sleep to await migration

* show logs

* added lazy-indexer

* update

* test fix

* testFIx1

* updated req

* updated req

* Update lazy indexer to run migrations on startup in TypeScript

* fix: remove db steps from docker image publish

---------

Co-authored-by: Gabriel Temtsen <[email protected]>
Co-authored-by: Gabriel Temtsen <[email protected]>
  • Loading branch information
3 people authored Sep 17, 2024
1 parent 3971412 commit ee1b97f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 41 deletions.
40 changes: 2 additions & 38 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build, Test, and Publish Docker Image
name: Build and Publish Docker Image

on:
push:
Expand All @@ -13,53 +13,18 @@ jobs:
runs-on: ubuntu-latest

steps:
# Step 1: Checkout the repository
- name: Checkout repository
uses: actions/checkout@v3

# Step 2: Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

# Step 3: Create a new builder instance
- name: Create builder
run: docker buildx create --use

# Step 4: Set up Docker Compose
- name: Set up Docker Compose
run: sudo apt-get install docker-compose

# Step 5: Build and start services using Docker Compose
- name: Build and Start Docker Compose
run: docker-compose up --build -d

# Step 6: Wait for PostgreSQL to be ready
- name: Wait for PostgreSQL
run: |
until docker-compose exec -T postgres pg_isready -h postgres -U indexer -d indexer; do
echo "Waiting for PostgreSQL...";
sleep 3;
done
# Step 7: Check Lazy Indexer logs (optional for debugging)
- name: Check Lazy Indexer logs
run: docker-compose logs lazy-indexer

# Step 8: Retry migration for Lazy Indexer
- name: Run migration
run: |
for i in {1..10}; do
docker-compose exec -T lazy-indexer yarn migrate && break || (echo "Retrying migration in 5 seconds..." && sleep 5);
done
# Step 9: Log in to Docker Hub using secrets
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

# Step 10: Build and Push multi-platform Docker image
- name: Build and Push Docker image
uses: docker/build-push-action@v5
with:
Expand All @@ -68,6 +33,5 @@ jobs:
platforms: linux/amd64,linux/arm64
tags: ${{ secrets.DOCKER_USERNAME }}/lazy-indexer:latest

# Step 11: Verify the image exists on Docker Hub using the secret username
- name: Image exists on Docker Hub
- name: Verify image on Docker Hub
run: docker pull ${{ secrets.DOCKER_USERNAME }}/lazy-indexer:latest
4 changes: 1 addition & 3 deletions src/db/migrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { fileURLToPath } from 'url'
import { log } from '../lib/logger.js'
import { db } from './kysely.js'

async function migrateToLatest() {
export async function migrateToLatest() {
const migrator = new Migrator({
db,
provider: new FileMigrationProvider({
Expand Down Expand Up @@ -37,5 +37,3 @@ async function migrateToLatest() {

await db.destroy()
}

migrateToLatest()
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { getLatestEvent } from './api/event.js'
import { backfill } from './lib/backfill.js'
import { initExpressApp } from './lib/express.js'
import { subscribe } from './lib/subscriber.js'
import { migrateToLatest } from './db/migrator.js'

migrateToLatest()

if (process.argv[2] === '--backfill') {
initExpressApp()
Expand Down

0 comments on commit ee1b97f

Please sign in to comment.