docker-compose.yml 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # Docker Compose file for Vapor
  2. #
  3. # Install Docker on your system to run and test
  4. # your Vapor app in a production-like environment.
  5. #
  6. # Note: This file is intended for testing and does not
  7. # implement best practices for a production deployment.
  8. #
  9. # Learn more: https://docs.docker.com/compose/reference/
  10. #
  11. # Build images: docker-compose build
  12. # Start app: docker-compose up app
  13. # Start database: docker-compose up db
  14. # Run migrations: docker-compose run migrate
  15. # Stop all: docker-compose down (add -v to wipe db)
  16. #
  17. version: '3.7'
  18. volumes:
  19. db_data:
  20. x-shared_environment: &shared_environment
  21. LOG_LEVEL: ${LOG_LEVEL:-debug}
  22. DATABASE_HOST: db
  23. DATABASE_NAME: vapor_database
  24. DATABASE_USERNAME: vapor_username
  25. DATABASE_PASSWORD: vapor_password
  26. services:
  27. app:
  28. image: api:latest
  29. build:
  30. context: .
  31. environment:
  32. <<: *shared_environment
  33. depends_on:
  34. - db
  35. ports:
  36. - '8080:8080'
  37. # user: '0' # uncomment to run as root for testing purposes even though Dockerfile defines 'vapor' user.
  38. command: ["serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"]
  39. migrate:
  40. image: api:latest
  41. build:
  42. context: .
  43. environment:
  44. <<: *shared_environment
  45. depends_on:
  46. - db
  47. command: ["migrate", "--yes"]
  48. deploy:
  49. replicas: 0
  50. revert:
  51. image: api:latest
  52. build:
  53. context: .
  54. environment:
  55. <<: *shared_environment
  56. depends_on:
  57. - db
  58. command: ["migrate", "--revert", "--yes"]
  59. deploy:
  60. replicas: 0
  61. db:
  62. image: postgres:16-alpine
  63. volumes:
  64. - db_data:/var/lib/postgresql/data/pgdata
  65. environment:
  66. PGDATA: /var/lib/postgresql/data/pgdata
  67. POSTGRES_USER: vapor_username
  68. POSTGRES_PASSWORD: vapor_password
  69. POSTGRES_DB: vapor_database
  70. ports:
  71. - '5432:5432'