# Brings up the full stack with one command: the Go API, MySQL, and Redis. # # Usage: # cp .env.example .env # fill in real values, especially Google OAuth # docker compose up --build # # docker compose automatically loads a file literally named ".env" sitting # next to this file, and substitutes ${VAR} references below from it. services: app: build: . ports: - "8070:8080" depends_on: - mysql - redis environment: PORT: 8080 ENV: development # NOTE: these hostnames are NOT "127.0.0.1" - inside the compose # network, each service's NAME becomes its hostname. Compose runs an # internal DNS that resolves "mysql" and "redis" to the correct # container's IP address automatically. This is exactly why # internal/config reads these from environment variables instead of # hardcoding 127.0.0.1 - the same compiled binary works unchanged # both locally and inside Docker, just by changing env vars. DB_HOST: mysql DB_PORT: 3306 DB_USER: root DB_PASSWORD: devpass DB_NAME: go_simple_api REDIS_ADDR: redis:6379 GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID} GOOGLE_CLIENT_SECRET: ${GOOGLE_CLIENT_SECRET} GOOGLE_REDIRECT_URL: http://localhost:8080/auth/google/callback ALLOWED_ORIGINS: http://localhost:3000 mysql: image: mysql:9 environment: MYSQL_ROOT_PASSWORD: devpass MYSQL_DATABASE: go_simple_api ports: - "13306:3306" volumes: # Named volume: MySQL's data directory is persisted on the host, # independent of the container's lifecycle. Without this, all data # would be lost every time you run `docker compose down`. - mysql_data:/var/lib/mysql redis: image: redis:8 ports: - "16379:6379" volumes: mysql_data: