Skip to content

Commit d265a72

Browse files
committed
rewrite readmes and fix docker compose
1 parent 649bda9 commit d265a72

20 files changed

Lines changed: 613 additions & 108 deletions

.github/workflows/deploy-backend.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ jobs:
4949
run: |
5050
DOCKER_BUILDKIT=0 docker build \
5151
--platform linux/amd64 \
52+
--target production \
5253
-t registry.heroku.com/${HEROKU_BACKEND_APP}/web \
5354
-f backend/Dockerfile backend
5455

Makefile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Docker Compose Commands for Different Environments
2+
3+
# Development - with hot reload and dev tools
4+
dev:
5+
docker compose -f docker-compose.dev.yml up --build
6+
7+
dev-detached:
8+
docker compose -f docker-compose.dev.yml up --build -d
9+
10+
# Production - optimized builds
11+
prod:
12+
docker compose -f docker-compose.prod.yml up --build
13+
14+
prod-detached:
15+
docker compose -f docker-compose.prod.yml up --build -d
16+
17+
# Testing - run tests in containers
18+
test:
19+
docker compose -f docker-compose.test.yml up --build --abort-on-container-exit
20+
21+
# Database only - just PostgreSQL
22+
db:
23+
docker compose -f docker-compose.db-only.yml up -d
24+
25+
# Clean up
26+
clean:
27+
docker compose -f docker-compose.dev.yml down -v
28+
docker compose -f docker-compose.prod.yml down -v
29+
docker compose -f docker-compose.test.yml down -v
30+
docker compose -f docker-compose.db-only.yml down -v
31+
32+
# Stop all services
33+
stop:
34+
docker compose -f docker-compose.dev.yml down
35+
docker compose -f docker-compose.prod.yml down
36+
docker compose -f docker-compose.test.yml down
37+
docker compose -f docker-compose.db-only.yml down
38+
39+
# View logs
40+
logs-dev:
41+
docker compose -f docker-compose.dev.yml logs -f
42+
43+
logs-prod:
44+
docker compose -f docker-compose.prod.yml logs -f
45+
46+
# Shell access
47+
shell-backend-dev:
48+
docker compose -f docker-compose.dev.yml exec backend bash
49+
50+
shell-backend-prod:
51+
docker compose -f docker-compose.prod.yml exec backend bash
52+
53+
# Database access
54+
db-shell:
55+
docker compose -f docker-compose.db-only.yml exec postgres psql -U guild_user -d guild_genesis

README.md

Lines changed: 87 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,107 @@ This is a monorepo containing:
3939

4040
### Prerequisites
4141
- [Docker](https://www.docker.com/)
42+
- [Node.js](https://nodejs.org/) (for frontend development)
43+
- [Astro CLI](https://docs.astro.build/en/getting-started/) (for frontend development)
4244
- [Foundry](https://book.getfoundry.sh/getting-started/installation) (for smart contracts)
4345

46+
### Environment Setup
47+
48+
Create a `.env` file in the project root with the following variables:
49+
50+
```bash
51+
# Database
52+
DATABASE_URL=postgresql://guild_user:guild_password@localhost:5433/guild_genesis
53+
54+
# Frontend Environment Variables
55+
PUBLIC_WALLET_CONNECT_PROJECT_ID=your_wallet_connect_project_id
56+
PUBLIC_API_URL=http://localhost:3001
57+
PUBLIC_BADGE_REGISTRY_ADDRESS=0x...
58+
PUBLIC_EAS_CONTRACT_ADDRESS=0x...
59+
PUBLIC_ACTIVITY_TOKEN_ADDRESS=0x...
60+
PUBLIC_SCHEMA_ID=0x...
61+
62+
# Discord Bot (if using)
63+
DISCORD_TOKEN=your_discord_bot_token
64+
DISCORD_CLIENT_ID=your_discord_client_id
65+
DISCORD_GUILD_ID=your_discord_guild_id
66+
67+
# Optional: Skip migrations in development
68+
SKIP_MIGRATIONS=1
69+
70+
# Optional: Disable SQLx compile-time validation
71+
SQLX_OFFLINE=true
72+
```
73+
74+
**Required for Production:**
75+
- `DATABASE_URL` - PostgreSQL connection string
76+
- `PUBLIC_WALLET_CONNECT_PROJECT_ID` - Get from [WalletConnect Cloud](https://cloud.walletconnect.com/)
77+
- Contract addresses - Deploy smart contracts first
78+
79+
**Optional for Development:**
80+
- `SKIP_MIGRATIONS=1` - Skip automatic migrations (run manually)
81+
- `SQLX_OFFLINE=true` - Disable SQLx compile-time validation
82+
4483
### Development Workflow
4584

46-
#### Quick Start
85+
#### Option 1: Docker Compose (Recommended)
86+
87+
We provide multiple Docker Compose configurations for different environments:
4788

89+
```bash
90+
# Development with hot reload
91+
make dev
92+
93+
# Production build
94+
make prod
95+
96+
# Run tests
97+
make test
98+
99+
# Database only
100+
make db
101+
102+
# Stop all services
103+
make stop
104+
```
105+
106+
#### Option 2: Local Development
107+
108+
**Backend:**
48109
```bash
49110
cd backend
50111
cargo install sqlx-cli --no-default-features --features rustls,postgres
51112
cargo sqlx prepare -- --bin guild-backend
52113
```
53114

115+
**Frontend:**
116+
```bash
117+
cd frontend
118+
npm install
119+
npm run dev
120+
```
121+
122+
**Database:**
123+
```bash
124+
docker compose up -d postgres
125+
```
126+
127+
### Docker Compose Environments
128+
129+
- **`docker-compose.dev.yml`** - Development with hot reload, volume mounts, and dev tools
130+
- **`docker-compose.prod.yml`** - Production with optimized builds and restart policies
131+
- **`docker-compose.test.yml`** - Testing environment with test-specific configurations
132+
- **`docker-compose.db-only.yml`** - Just PostgreSQL for local development
133+
134+
Use `make` commands or specify files directly:
54135
```bash
55-
docker-compose up -d
136+
docker compose -f docker-compose.dev.yml up --build
56137
```
57138

58139
**Access the applications:**
59-
- Frontend: http://localhost:4321
140+
- Frontend: http://localhost:3000
60141
- Backend API: http://localhost:3001
61-
- PostgreSQL: localhost:5432
142+
- PostgreSQL: localhost:5433
62143

63144
#### Smart Contracts Development
64145

@@ -131,9 +212,9 @@ event BadgeCreated(bytes32 indexed name, bytes32 description, address indexed cr
131212
- [x] Web3 wallet integration
132213
- [x] Basic profile and badge system
133214
- [x] Smart contracts for on-chain badges
134-
- [ ] SIWE authentication
215+
- [x] SIWE authentication
135216
- [ ] Database models and migrations
136-
- [ ] API endpoints for profiles and badges
217+
- [x] API endpoints for profiles and badges
137218

138219
### V1+ (Future)
139220
- [ ] Gasless transactions

backend/.dockerignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Rust build artifacts
2+
target/
3+
Cargo.lock
4+
5+
# IDE files
6+
.vscode/
7+
.idea/
8+
*.swp
9+
*.swo
10+
11+
# OS files
12+
.DS_Store
13+
Thumbs.db
14+
15+
# Git
16+
.git/
17+
.gitignore
18+
19+
# Documentation
20+
README.md
21+
*.md
22+
23+
# Environment files
24+
.env
25+
.env.local
26+
.env.*.local
27+
28+
# Logs
29+
*.log
30+
logs/
31+
32+
# Temporary files
33+
tmp/
34+
temp/

backend/Dockerfile

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
1-
FROM rust:latest AS build
1+
FROM rust:latest AS base
2+
WORKDIR /app
3+
4+
# Development stage
5+
FROM base AS dev
6+
RUN cargo install cargo-watch
7+
COPY . .
8+
ENV RUST_LOG=debug RUST_BACKTRACE=1
9+
CMD ["cargo", "watch", "-x", "run --bin guild-backend"]
10+
11+
# Test stage
12+
FROM base AS test
13+
COPY . .
14+
CMD ["cargo", "test", "--", "--test-threads=1"]
15+
16+
# Build stage
17+
FROM base AS build
218
WORKDIR /app
319
ENV SQLX_OFFLINE=true
420
COPY . .
521
RUN cargo build --release
622

7-
FROM debian:bookworm-slim
23+
# Production stage
24+
FROM debian:bookworm-slim AS production
825
RUN apt-get update && apt-get install -y --no-install-recommends \
926
netcat-openbsd \
1027
&& rm -rf /var/lib/apt/lists/*
1128
RUN useradd -m appuser
1229
WORKDIR /app
13-
COPY --from=build /app/target/release/guild-backend /app/app
30+
COPY --from=build /app/target/release/guild-backend /app/guild-backend
1431
ENV RUST_LOG=info PORT=3001
1532
EXPOSE 3001
1633
USER appuser
17-
CMD ["/app/app"]
34+
CMD ["/app/guild-backend"]
1835

0 commit comments

Comments
 (0)