You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
3.2 KiB

  1. Example Web Server/Site Template
  2. ================================
  3. -------------------------------------------------
  4. Project Layout
  5. -------------------------------------------------
  6. ### Project Working Copy
  7. ```
  8. ~/Projects/Web/example.com/ # git repo (git ignore www)
  9. |
  10. |-- docker-compose.yml
  11. |
  12. |-- service/
  13. | |
  14. | |-- docker-compose.yml
  15. |
  16. |-- www/ # git repo (git ignore build)
  17. | |
  18. | |-- Makefile
  19. | |
  20. | |-- index.pug
  21. | |
  22. | |-- build/ # git repo (if not building target on server, e.g. static GitHub pages)
  23. | | |
  24. | | |-- index.html
  25. | |
  26. | |-- config/
  27. ```
  28. ### Hosted Project Collaboration
  29. ```
  30. git@examplecodehost.com:organization/example.com.git # server config repo
  31. git@examplecodehost.com:organization/www.example.com.git # site source repo
  32. ```
  33. ### Server Deployment
  34. ```
  35. /usr/local/src/web/example.com/
  36. |
  37. |-- server/ # bare git repo for server config
  38. |
  39. |-- www/ # bare git repo for site build files (or optionally site source files if server builds project)
  40. |
  41. |-- build/ # optional bare git repo for build files if server builds project automatically
  42. ```
  43. Git branches are checked out to different worktrees to be served:
  44. ```
  45. /srv/dev/example.com/ # dev branch server config
  46. |
  47. |-- docker-compose.yml
  48. |
  49. |-- www/ # dev branch built site
  50. /srv/beta/example.com/ # release branch server config
  51. |
  52. |-- docker-compose.yml
  53. |
  54. |-- www/ # release branch built site
  55. /srv/prod/example.com/ # master branch server config
  56. |
  57. |-- docker-compose.yml
  58. |
  59. |-- www/ # master branch built site
  60. ```
  61. Dev, beta, and prod could all be on different servers if appropriate.
  62. -------------------------------------------------
  63. Server Groups and Directory Permissions
  64. -------------------------------------------------
  65. Add your user (on the server) to the srv group. Set directory permissions
  66. ```
  67. # chown root:srv .
  68. # chmod g+ws .
  69. # setfacl -d -m g::rwx .
  70. ```
  71. for all relevant directories (newly created subdirectories should inherit permissions):
  72. ```
  73. /usr/local/src/web/example.com/
  74. /usr/local/src/web/example.com/server/
  75. /usr/local/src/web/example.com/www/
  76. /usr/local/src/web/example.com/build/
  77. /srv/dev/example.com/
  78. /srv/dev/example.com/www/
  79. /srv/beta/example.com/
  80. /srv/beta/example.com/www/
  81. /srv/prod/example.com/
  82. /srv/prod/example.com/www/
  83. ```
  84. In upstream bare repo directories (e.g. `webserver:/usr/local/src/web/example.com/www/`), run:
  85. ```
  86. # git init --bare --shared=group
  87. # git config receive.denyCurrentBranch updateInstead
  88. # git config receive.denyNonFastForwards false
  89. # git config core.sharedRepository true # if needed because of missing init option
  90. ```
  91. In working copy repos, set upstream and push branches to new bare repos, then in
  92. the bare repos run:
  93. ```
  94. # git worktree add /srv/prod/example.com/www master
  95. # git worktree add /srv/beta/example.com/www release
  96. # git worktree add /srv/dev/example.com/www dev
  97. ```
  98. Maybe needed if above permissions weren't set correctly:
  99. ```
  100. # chmod -R g+w .
  101. # chmod g+w /srv/*/example.com/www
  102. # chown -R root:srv .
  103. # chmod -R g+swX .
  104. # chown root:srv /srv/prod/example.com/www
  105. # chmod g+swX /srv/prod/example.com/www
  106. # chown root:srv /srv/beta/example.com/www
  107. # chmod g+swX /srv/beta/example.com/www
  108. # chown root:srv /srv/dev/example.com/www
  109. # chmod g+swX /srv/dev/example.com/www
  110. ```