Skip to content

Commit

Permalink
feat(dev): tasks for local development (#5607)
Browse files Browse the repository at this point in the history
* 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 <ivan.mikheykin@flant.com>
  • Loading branch information
diafour committed May 4, 2023
1 parent b1f78c1 commit 5b96afc
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 189 deletions.
49 changes: 49 additions & 0 deletions Taskfile.dist.yaml
Expand Up @@ -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
122 changes: 0 additions & 122 deletions docs/.werf/nginx-dev-slow.conf

This file was deleted.

58 changes: 15 additions & 43 deletions docs/.werf/nginx-dev.conf
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
21 changes: 12 additions & 9 deletions docs/DEVELOPMENT.md
Expand Up @@ -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).
15 changes: 0 additions & 15 deletions docs/docker-compose-slow.yml

This file was deleted.

16 changes: 16 additions & 0 deletions docs/docker-compose.yml
Expand Up @@ -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"
Expand All @@ -23,6 +28,10 @@ services:
- "./:/app/:cached"
depends_on:
- en
networks:
default:
aliases:
- docs-ru

front:
image: nginx:latest
Expand All @@ -33,3 +42,10 @@ services:
depends_on:
- ru
- en
profiles:
- quick

networks:
default:
name: werfio-dev
external: true

0 comments on commit 5b96afc

Please sign in to comment.