Skip to content

Commit

Permalink
feat: reworked docker setup and migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbrusegard committed Jan 23, 2025
1 parent a865bed commit 0cb9563
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 25 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/deploy-script.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ jobs:
cd ${{ inputs.path }}
git checkout ${{ inputs.branch }}
git pull
docker compose build app &
docker compose up db s3 -d
sleep 5
wait
docker compose run --rm app bun run db:migrate
docker compose up -d app
docker compose build
docker compose down
docker compose up -d
8 changes: 1 addition & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,7 @@ bun run dev:stop
> [!TIP]
> In the future we may add a way to SSH tunnel and use the database and storage server for the staging solution locally. This is only beneficial if you are only working on the frontend and do not need to modify the database.
For running with the inspect flag to allow debugging you can run:
```bash
bun run dev:debug
```
Now for a more indept guide on all the scripts for the database and storage server. First the basics that they both have in common. Now remember that you in theory only need the fancy command above if you are not doing any debugging. It just runs these other scripts for you under the hood.
Now for a more in depth guide on all the scripts for the database and storage server. First the basics that they both have in common. Now remember that you in theory only need the fancy command above if you are not doing any debugging. It just runs these other scripts for you under the hood.
To start the database and storage server you can run:
Expand Down
31 changes: 28 additions & 3 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
services:
app:
build: .
build:
context: .
depends_on:
- db
- s3
db:
condition: service_healthy
s3:
condition: service_healthy
restart: unless-stopped
networks:
- nginx_default
migrator:
build:
context: .
dockerfile: migrations.dockerfile
depends_on:
db:
condition: service_healthy
s3:
condition: service_healthy
restart: no
networks:
- nginx_default
db:
image: postgres:16
restart: unless-stopped
Expand All @@ -16,6 +31,11 @@ services:
POSTGRES_DB: ${DB_NAME}
volumes:
- ./data/db:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"]
interval: 5s
timeout: 5s
retries: 5
networks:
- nginx_default
s3:
Expand All @@ -27,6 +47,11 @@ services:
MINIO_DEFAULT_BUCKETS: ${S3_NAME}
volumes:
- ./data/s3:/bitnami/minio/data
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 5s
timeout: 5s
retries: 5
networks:
- nginx_default
networks:
Expand Down
4 changes: 0 additions & 4 deletions dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ RUN mkdir .next && chown nextjs:nodejs .next
# Copy necessary files for build
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# Copy necessary files for migrations
COPY --from=builder --chown=nextjs:nodejs /app/drizzle.config.ts ./
COPY --from=builder --chown=nextjs:nodejs /app/src/server ./src/server
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./

USER nextjs

Expand Down
13 changes: 13 additions & 0 deletions migrations.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM imbios/bun-node:22-slim

WORKDIR /app

COPY package.json bun.lock tsconfig.json ./
RUN bun install --frozen-lockfile

COPY drizzle.config.ts ./
COPY src/server/db ./src/server/db
COPY src/env.ts ./src/env.ts
COPY .env ./.env

CMD ["bun", "run", "db:migrate"]
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"scripts": {
"prepare": "bun -e \"process.env.NODE_ENV !== 'production' && require('child_process').spawnSync('lefthook', ['install'], {stdio: 'inherit', shell: true})\"",
"dev": "next dev",
"dev:debug": "NODE_OPTIONS='--inspect' next dev",
"dev:setup": "set -e && bun run db:stop && bun run s3:stop && bun run db:delete && bun run s3:delete && bun run db:start && bun run s3:start && sleep 5 && docker compose -f compose.local.yml exec -T db pg_isready && bun run db:push && bun run db:seed",
"dev:stop": "docker compose -f compose.local.yml down",
"lint": "biome check --write",
Expand All @@ -18,10 +17,10 @@
"db:stop": "docker compose -f compose.local.yml down db",
"db:delete": "bun -e \"require('fs').rmSync('data/db', { recursive: true, force: true })\"",
"db:logs": "docker compose -f compose.local.yml logs -f db",
"db:generate": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate",
"db:push": "drizzle-kit push",
"db:studio": "drizzle-kit studio",
"db:generate": "bunx drizzle-kit generate",
"db:migrate": "bunx drizzle-kit migrate",
"db:push": "bunx drizzle-kit push",
"db:studio": "bunx drizzle-kit studio",
"db:seed": "bun run src/server/db/seed.ts",
"s3:start": "docker compose -f compose.local.yml up s3 -d",
"s3:stop": "docker compose -f compose.local.yml down s3",
Expand Down

0 comments on commit 0cb9563

Please sign in to comment.