From 5b96afc8c1f0e1f3275d5ff1a0a36f8ddb39eef2 Mon Sep 17 00:00:00 2001 From: Ivan Mikheykin Date: Thu, 4 May 2023 15:01:53 +0300 Subject: [PATCH] feat(dev): tasks for local development (#5607) * feat(dev): tasks for local development - Run jekyll serve as en and ru by default (task compose:up). - Use werf/website for accessing documentation via shared docker network. - Run nginx with proxying to werf.io as compose:up:standalone. - Remove 'slow' configuration. - Use map to unify nginx configuration for en and ru sites. Signed-off-by: Ivan Mikheykin --- Taskfile.dist.yaml | 49 +++++++++++++ docs/.werf/nginx-dev-slow.conf | 122 --------------------------------- docs/.werf/nginx-dev.conf | 58 ++++------------ docs/DEVELOPMENT.md | 21 +++--- docs/docker-compose-slow.yml | 15 ---- docs/docker-compose.yml | 16 +++++ 6 files changed, 92 insertions(+), 189 deletions(-) delete mode 100644 docs/.werf/nginx-dev-slow.conf delete mode 100644 docs/docker-compose-slow.yml diff --git a/Taskfile.dist.yaml b/Taskfile.dist.yaml index c3f5449514..e7f0dbc556 100644 --- a/Taskfile.dist.yaml +++ b/Taskfile.dist.yaml @@ -528,3 +528,52 @@ tasks: git signatures show {{.CLI_ARGS}} $ref done - git signatures push {{.CLI_ARGS}} + + docker:network:create: + desc: "Create shared docker network werfio-dev to use with werf/website" + vars: + NETWORK_NAME: werfio-dev + cmds: + - docker network create -d=bridge {{.NETWORK_NAME}} + status: + - docker network inspect {{.NETWORK_NAME}} + + _compose:up: + deps: + - docker:network:create + cmds: + - | + services="{{ .lang }}" + services=${services:-"en ru"} + if [[ "yes" == "{{.standalone}}" ]] ; then + services="${services} front" + fi + + # Run compose up in docs directory. + cd docs + which werf >/dev/null || source $(trdl use werf 1.2 beta) + werf compose up jekyll_base --dev --docker-compose-command-options="$services" --platform=linux/amd64 || true + + compose:up:standalone: + desc: "Run jekyll in werf compose for content editing without werf/website (scripts/styles/images are proxied from werf.io). Use lang=en or lang=ru to run only specified lang." + cmds: + - task: _compose:up + vars: + standalone: "yes" + + compose:up: + desc: "Run jekyll in werf compose for local development. Use lang=en or lang=ru to run only specified lang. Run task compose:up in werf/website repository to access documentation." + cmds: + - task: _compose:up + vars: + standalone: "no" + + compose:down: + desc: "Stop and clean after werf compose" + cmds: + - | + cd docs + which werf >/dev/null || source $(trdl use werf 1.2 beta) + # Workaround: set image variable to stub image. + WERF_JEKYLL_BASE_DOCKER_IMAGE_NAME=nginx:latest \ + werf compose down diff --git a/docs/.werf/nginx-dev-slow.conf b/docs/.werf/nginx-dev-slow.conf deleted file mode 100644 index 9febb589a6..0000000000 --- a/docs/.werf/nginx-dev-slow.conf +++ /dev/null @@ -1,122 +0,0 @@ -user nginx; -worker_processes auto; -pid /run/nginx.pid; - -events { - worker_connections 500; - multi_accept on; - use epoll; -} - -http { - log_format json_combined escape=json '{ "time_local": "$time_local", ' - '"host": "$host", ' - '"remote_addr": "$remote_addr", ' - '"remote_user": "$remote_user", ' - '"request": "$request", ' - '"status": "$status", ' - '"body_bytes_sent": "$body_bytes_sent", ' - '"request_time": "$request_time", ' - '"http_referrer": "$http_referer", ' - '"http_user_agent": "$http_user_agent" }'; - - server_tokens off; - sendfile on; - tcp_nopush on; - tcp_nodelay on; - keepalive_timeout 65; - types_hash_max_size 2048; - client_max_body_size 100M; - server_names_hash_bucket_size 64; - - include /etc/nginx/mime.types; - default_type application/octet-stream; - - error_log /dev/stderr info; - - gzip off; - ssi on; - - server { - charset utf-8; - listen 80; - server_name _; - expires 1h; - - index index.html; - - set_real_ip_from 0.0.0.0/0; - access_log /dev/stdout json_combined; - error_log /dev/stderr info; - - location = /healthz { - access_log off; - add_header Content-Type text/plain; - return 200; - } - - location /documentation/ { - proxy_redirect off; - proxy_set_header Host localhost; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Original-URI $request_uri; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - - proxy_pass http://documentation; - } - - location / { - proxy_redirect off; - proxy_set_header Host werf.io; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Original-URI $request_uri; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - - proxy_pass https://werf.io; - } - - error_page 404 /404.html; - } - - # ru.werf.io - server { - charset utf-8; - listen 80; - server_name ~^ru\..+$; - expires 1h; - - index index.html; - - set_real_ip_from 0.0.0.0/0; - access_log /dev/stdout json_combined; - error_log /dev/stderr info; - - location = /healthz { - access_log off; - add_header Content-Type text/plain; - return 200; - } - - location /documentation { - proxy_redirect off; - proxy_set_header Host ru.localhost; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Original-URI $request_uri; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - - proxy_pass http://documentation; - } - - location / { - proxy_redirect off; - proxy_set_header Host ru.werf.io; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Original-URI $request_uri; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - - proxy_pass https://ru.werf.io; - } - - error_page 404 /404.html; - } -} diff --git a/docs/.werf/nginx-dev.conf b/docs/.werf/nginx-dev.conf index b651701a42..4332e9eb78 100644 --- a/docs/.werf/nginx-dev.conf +++ b/docs/.werf/nginx-dev.conf @@ -37,53 +37,25 @@ http { gzip off; ssi on; - server { - charset utf-8; - listen 80; - server_name _; - expires 1h; - - root /app/main; - index index.html; - - set_real_ip_from 0.0.0.0/0; - access_log /dev/stdout json_combined; - error_log /dev/stderr info; - - location = /healthz { - access_log off; - add_header Content-Type text/plain; - return 200; - } - - rewrite ^/documentation/(v[\d]+\.[\d]+[^\/]*)$ /documentation/$1/; - - location /documentation/ { - rewrite ^/documentation(/v[\d]+\.[^\/]+)?/(.*) /$2 break; - proxy_pass http://en; - } - - location / { - proxy_redirect off; - proxy_set_header Host werf.io; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Original-URI $request_uri; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + # It is required to resolve domains in variables. (Error 'no resolver defined to resolve SOMENAME' occurs if no resolver defined). + resolver 127.0.0.11 valid=1s; - proxy_pass https://werf.io; - } + map $http_host $lang { + default "en"; + ~^ru\..+$ "ru"; + } - error_page 403 404 /404.html; + map $lang $werfio_host { + default "werf.io"; + "ru" "ru.werf.io"; } - # ru.werf.io server { charset utf-8; listen 80; - server_name ~^ru\..+$; + server_name _; expires 1h; - root /app/ru; index index.html; set_real_ip_from 0.0.0.0/0; @@ -98,19 +70,19 @@ http { rewrite ^/documentation/(v[\d]+\.[\d]+[^\/]*)$ /documentation/$1/; - location /documentation { + location /documentation/ { rewrite ^/documentation(/v[\d]+\.[^\/]+)?/(.*) /$2 break; - proxy_pass http://ru; - } + proxy_pass http://$lang; + } location / { proxy_redirect off; - proxy_set_header Host ru.werf.io; + proxy_set_header Host $werfio_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Original-URI $request_uri; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_pass https://ru.werf.io; + proxy_pass https://$werfio_host; } error_page 403 404 /404.html; diff --git a/docs/DEVELOPMENT.md b/docs/DEVELOPMENT.md index a443895a5a..3590508d74 100644 --- a/docs/DEVELOPMENT.md +++ b/docs/DEVELOPMENT.md @@ -7,29 +7,32 @@ ___ ### Run the documentation part of the site locally -#### Variant 1 +#### Variant 1 (full) -Run `jekyll serve` with --watch option to test changes in "real time". +Run `jekyll serve` with --watch option to test changes in "real time". Requires to run werf compose in werf/website to access documentation in browser. - Install [werf](http://werf.io/installation.html). +- Install [task](https://taskfile.dev/installation/). - Run: ```shell - werf compose up jekyll_base --dev + task compose:up ``` -- Or run with specific architecture (e.g. ARM-based Macbooks): +- Wait (approximately 60 seconds) for the message "done in X.XXX seconds" from the `docs-en-1` and `docs-ru-1` containers. +- Run werf/website: ```shell - werf compose up jekyll_base --dev --platform='linux/amd64' + cd ../website + task compose:up ``` -- Wait (approximately 60 seconds) for the message "done in X.XXX seconds" from the `docs-en-1` and `docs-ru-1` containers. - Check the English version is available on [https://localhost](http://localhost), and the Russian version on [http://ru.localhost](https://ru.localhost) (add `ru.localhost` record in your `/etc/hosts` to access the Russian version of the site). -#### Variant 2 (slower) +#### Variant 2 (standalone) -Run fully built 'web' image. +Run `jekyll serve` with --watch option to test changes in "real time". Use scripts/styles/images from werf.io site. - Install [werf](http://werf.io/installation.html). +- Install [task](https://taskfile.dev/installation/) - Run (add `--follow --docker-compose-command-options="-d"` if necessary): ```shell - werf compose up --docker-compose-options="-f docker-compose-slow.yml" --dev + task compose:up:standalone ``` - Check the English version is available on [https://localhost](http://localhost), and the Russian version on [http://ru.localhost](https://ru.localhost) (add `ru.localhost` record in your `/etc/hosts` to access the Russian version of the site). diff --git a/docs/docker-compose-slow.yml b/docs/docker-compose-slow.yml deleted file mode 100644 index c758716bb0..0000000000 --- a/docs/docker-compose-slow.yml +++ /dev/null @@ -1,15 +0,0 @@ -version: "3.9" - -services: - documentation: - image: $WERF_WEB_DOCKER_IMAGE_NAME - command: ["nginx", "-g", "daemon off;"] - - front: - image: nginx:latest - volumes: - - ".werf/nginx-dev-slow.conf:/etc/nginx/nginx.conf:ro" - ports: - - "80:80" - depends_on: - - documentation diff --git a/docs/docker-compose.yml b/docs/docker-compose.yml index ce3278d770..be257e797f 100644 --- a/docs/docker-compose.yml +++ b/docs/docker-compose.yml @@ -11,6 +11,11 @@ services: jekyll serve --disable-disk-cache --config _config.yml --destination /tmp/_site -P 80 --profile --trace --watch" volumes: - "./:/app/:cached" + networks: + default: + aliases: + - docs-en + ru: image: $WERF_JEKYLL_BASE_DOCKER_IMAGE_NAME working_dir: "/app" @@ -23,6 +28,10 @@ services: - "./:/app/:cached" depends_on: - en + networks: + default: + aliases: + - docs-ru front: image: nginx:latest @@ -33,3 +42,10 @@ services: depends_on: - ru - en + profiles: + - quick + +networks: + default: + name: werfio-dev + external: true