|
1 | | -COMPOSE_PULL = docker compose pull |
2 | | -COMPOSE_RUN_NODE = docker compose run --rm node |
3 | | -COMPOSE_UP_NODE = docker compose up -d node |
4 | | -COMPOSE_UP_NODE_DEV = docker compose up node_dev |
| 1 | +noTargetGuard: |
| 2 | + $(error Target is missing) |
| 3 | + |
| 4 | +COMPOSE_PULL_BUSYBOX = docker compose pull busybox |
| 5 | +COMPOSE_RUN_BUSYBOX = docker compose run --rm busybox |
| 6 | +COMPOSE_BUILD_BASE = docker compose build base |
| 7 | +# COMPOSE_RUN_CI = COMPOSE_ENVFILE=$(ENVFILE) docker compose run --rm ci |
| 8 | +COMPOSE_RUN_CI = COMPOSE_ENVFILE=.env docker compose run --rm ci |
| 9 | +COMPOSE_UP_CI = COMPOSE_ENVFILE=.env docker compose up ci -d |
| 10 | +COMPOSE_RUN_DEV = COMPOSE_ENVFILE=.env docker compose run --service-ports --rm dev |
| 11 | +COMPOSE_UP_DEV = COMPOSE_ENVFILE=$(ENVFILE) docker compose up dev |
| 12 | + |
| 13 | +ASTRO_URL ?= http://ci:4321 |
| 14 | +# ENVFILE ?= $(if $(wildcard .env),.env,env.template) |
5 | 15 | ENVFILE ?= env.template |
6 | | -SERVE_BASE_URL ?= http://node:5173 |
7 | 16 |
|
8 | | -all: |
9 | | - ENVFILE=env.example $(MAKE) ciTest |
10 | | - |
11 | | -ciTest: envfile pruneDocker deps build serve test prune |
12 | | - |
13 | | -ciDeploy: envfile pruneDocker deps build serve test deploy prune |
| 17 | +ciTest: clean envfile deps check build preview testPreview clean |
| 18 | +ciDeploy: clean envfile deps check build preview testPreview deploy clean |
14 | 19 |
|
15 | 20 | envfile: |
16 | | - cp -f $(ENVFILE) .env |
| 21 | + $(COMPOSE_RUN_BUSYBOX) sh -c "cp -f $(ENVFILE) .env" |
17 | 22 |
|
| 23 | +# deps creates the base image used by other compose services |
| 24 | +# It installs dependencies |
18 | 25 | deps: |
19 | | - $(COMPOSE_PULL) node |
20 | | - $(COMPOSE_RUN_NODE) npm install |
21 | | - |
22 | | -depsUpgrade: |
23 | | - $(COMPOSE_PULL) |
24 | | - $(COMPOSE_RUN_NODE) npm upgrade |
25 | | - |
26 | | -depsAudit: |
27 | | - -$(COMPOSE_RUN_NODE) npm outdated |
28 | | - $(COMPOSE_RUN_NODE) npm audit |
29 | | - |
30 | | -depsCopy: |
31 | | - rm -fr node_modules |
32 | | - docker compose create deps |
33 | | - docker compose cp deps:/opt/deps/node_modules . |
34 | | - docker compose rm -f deps |
35 | | - |
36 | | -shell: |
37 | | - $(COMPOSE_RUN_NODE) bash |
| 26 | + $(COMPOSE_BUILD_BASE) |
| 27 | + $(COMPOSE_RUN_CI) deno task install |
| 28 | + |
| 29 | +# It copies deps from Docker volumes to the host. This is handy for auto-completion from IDE among other things. |
| 30 | +# If there is a docker running and using the Docker volumes, it will fail deleting node_modules and vendor. Run command `docker compose down` to mitigate the issue |
| 31 | +# TODO: I could potentially look into [dev containers](https://docs.github.com/en/codespaces/setting-up-your-project-for-codespaces/adding-a-dev-container-configuration/introduction-to-dev-containers) |
| 32 | +copyDepsToHost: |
| 33 | + $(COMPOSE_RUN_BUSYBOX) sh -c "rm -fr node_modules vendor" |
| 34 | + docker compose create ci |
| 35 | + docker compose cp ci:/opt/app/node_modules . |
| 36 | + docker compose cp ci:/opt/app/vendor . |
| 37 | + docker compose rm -f ci |
| 38 | + |
| 39 | +fmt \ |
| 40 | +check \ |
| 41 | +build \ |
| 42 | +deploy \ |
| 43 | +toc \ |
| 44 | +update: |
| 45 | + $(COMPOSE_RUN_CI) deno task $@ |
38 | 46 |
|
39 | 47 | dev: |
40 | | - COMPOSE_COMMAND="make _dev" $(COMPOSE_UP_NODE_DEV) |
41 | | -_dev: |
42 | | - npx vitepress dev --host 0.0.0.0 docs |
| 48 | + COMPOSE_COMMAND="deno task $@" $(COMPOSE_UP_DEV) |
| 49 | + |
| 50 | +# TODO: |
| 51 | +# - Instead of `sleep` Could potentially look at compose service health_check |
| 52 | +# - https://docs.docker.com/reference/compose-file/services/#healthcheck |
| 53 | +preview: |
| 54 | + $(info Target `preview` will sleep 5 seconds to make sure the server is up) |
| 55 | + COMPOSE_COMMAND="deno task preview" $(COMPOSE_UP_CI) |
| 56 | + $(COMPOSE_RUN_CI) sleep 5 |
| 57 | + |
| 58 | +previewDev: |
| 59 | + COMPOSE_COMMAND="deno task preview" $(COMPOSE_UP_DEV) |
| 60 | + |
| 61 | +# testPreview test against a running preview in ci container |
| 62 | +# If preview is running in dev container, run the following: |
| 63 | +# `make testPreview ASTRO_URL=http://dev:4321 |
| 64 | +testPreview: |
| 65 | + $(COMPOSE_RUN_CI) make _testPreview ASTRO_URL=$(ASTRO_URL) |
| 66 | + |
| 67 | +_testPreview: |
| 68 | + $(info Test home page) |
| 69 | + curl $(ASTRO_URL) | grep "Get started" > /dev/null |
| 70 | + $(info Test Getting started) |
| 71 | + curl $(ASTRO_URL)/guides/getting-started/ | grep "Getting Started" > /dev/null |
| 72 | + |
| 73 | +# clean removes everything that has been created |
| 74 | +# It also deletes the deps folders, that could've been copied to the host (`make copyDepsToHost`), with `busybox` service as it does not mount them with volumens. |
| 75 | +# There is no need to call `deno clean` as `"vendor": true` is used in `deno.jsonc` |
| 76 | +clean: |
| 77 | + docker compose down |
| 78 | + $(COMPOSE_RUN_BUSYBOX) sh -c "rm -fr dist .env node_modules vendor .astro" |
| 79 | + docker compose down --rmi "all" --remove-orphans --volumes |
43 | 80 |
|
44 | | -build: |
45 | | - $(COMPOSE_RUN_NODE) make _build |
46 | | -_build: |
47 | | - npx vitepress build docs |
48 | | - |
49 | | -serve: |
50 | | - $(info serve will sleep 5 seconds to make sure the server is up) |
51 | | - COMPOSE_COMMAND="make _serve" $(COMPOSE_UP_NODE) |
52 | | - $(COMPOSE_RUN_NODE) sleep 5 |
53 | | -_serve: |
54 | | - npx vitepress serve docs --port 5173 |
55 | | - |
56 | | -serveDev: |
57 | | - COMPOSE_COMMAND="make _serve" $(COMPOSE_UP_NODE_DEV) |
58 | | - |
59 | | -test: |
60 | | - $(COMPOSE_RUN_NODE) make _test SERVE_BASE_URL=$(SERVE_BASE_URL) |
61 | | -_test: |
62 | | - echo "Test home page" |
63 | | - curl $(SERVE_BASE_URL) | grep "Get started" > /dev/null |
64 | | - echo "Test docs page" |
65 | | - curl $(SERVE_BASE_URL)/guide/getting-started.html | grep "Hello, World!" > /dev/null |
66 | | - |
67 | | -deploy: |
68 | | - $(COMPOSE_RUN_NODE) make _deploy |
69 | | -_deploy: |
70 | | - npx wrangler pages deploy docs/.vitepress/dist \ |
71 | | - --project-name=$(ENV_CLOUDFLARE_PROJECT_NAME) \ |
72 | | - --branch=$(ENV_CLOUDFLARE_BRANCH_NAME) \ |
73 | | - --commit-message="Deploy!" |
74 | | - |
75 | | -pruneDocker: |
76 | | - docker compose down --remove-orphans --volumes |
77 | | - |
78 | | -prune: |
79 | | - $(COMPOSE_RUN_NODE) bash -c "rm -fr docs/.vitepress/dist docs/.vitepress/.cache" |
80 | | - $(MAKE) pruneDocker |
81 | | - rm -fr .env node_modules |
| 81 | +shell: |
| 82 | + $(COMPOSE_RUN_CI) bash |
82 | 83 |
|
83 | | -toc: |
84 | | - $(COMPOSE_RUN_NODE) make _toc |
85 | | -_toc: |
86 | | - npx doctoc README.md --notitle |
| 84 | +shellDev: |
| 85 | + $(COMPOSE_RUN_DEV) bash |
0 commit comments