From 9a088722c09a1a5b5815a37779d3b8b601a19d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Mon, 30 Dec 2024 15:32:09 +0100 Subject: [PATCH 1/3] Add Docker Compose with watch mode --- .github/workflows/ci.yml | 7 ++++++- .gitignore | 1 - Dockerfile | 22 ++++++++++++++++++++++ Makefile | 20 +++++--------------- README.md | 20 +++++++++++++------- compose.yaml | 34 ++++++++++++++++++++++++++++++++++ 6 files changed, 80 insertions(+), 24 deletions(-) create mode 100644 Dockerfile create mode 100644 compose.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d73b148..7b5f69e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,9 +19,14 @@ jobs: php-version: ${{ matrix.php }} coverage: none - run: make - - run: make served + - run: docker compose build + - run: docker compose up -d - run: bash tests/await.bash http://clue.localhost/ - run: make test + - run: docker compose stop -t 60 + timeout-minutes: 0.5 + - run: docker compose logs + if: ${{ always() }} - run: git config --global user.name "GitHub Actions" && git config --global user.email "actions@github.com" - run: git config --global url."https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/".insteadOf "https://github.com/" - run: make deploy diff --git a/.gitignore b/.gitignore index 05a7198..a4a031f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ /vendor/ /build/ -/tailwindcss diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0f70256 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +# syntax=docker/dockerfile:1 +FROM composer:2 AS composer +WORKDIR /app/ +COPY composer.json composer.lock ./ +RUN composer install --ignore-platform-reqs --optimize-autoloader + +FROM scratch AS tailwind +WORKDIR /app/ +ADD --checksum=sha256:cd52e757cb0bd15238f0207a215198d924811234028d056b7be39fde70491296 --chmod=0755 \ + https://github.com/tailwindlabs/tailwindcss/releases/download/v3.2.4/tailwindcss-linux-x64 /usr/local/bin/tailwindcss +ENTRYPOINT ["tailwindcss"] + +FROM php:8.1-apache AS build +WORKDIR /app/ +COPY --from=composer /app/vendor/ vendor/ +COPY app/ app/ +COPY www/ www/ +RUN vendor/bin/sculpin generate + +FROM php:8.1-apache +RUN ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled +COPY --from=build /app/build/ /var/www/html/ diff --git a/Makefile b/Makefile index f0c5c1e..e5812e4 100644 --- a/Makefile +++ b/Makefile @@ -5,21 +5,10 @@ vendor: composer.json composer.lock composer install touch $@ -www/src/tailwind.min.css: www/_layouts/* www/_posts/* www/_talks/* www/*.html www/*.html.twig tailwindcss tailwind.config.js - ./tailwindcss -o $@ --minify +www/src/tailwind.min.css: www/_layouts/* www/_posts/* www/_talks/* www/*.html www/*.html.twig tailwind.config.js + docker compose run --rm --build tailwind -o $@ --minify touch $@ -tailwindcss: - test -x tailwindcss || curl -L https://github.com/tailwindlabs/tailwindcss/releases/download/v3.2.4/tailwindcss-linux-x64 > tailwindcss && chmod +x tailwindcss - -serve: build - docker run -it --rm -p 80:80 -v "$$PWD"/build/:/var/www/html/ php:8.1-apache sh -c "ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled; apache2-foreground" - -served: build - docker run -d --rm -p 80:80 -v "$$PWD"/build/:/var/www/html/ php:8.1-apache sh -c "ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled; apache2-foreground" - @sleep 2 - @echo Container running. Use \"docker rm -f {containerId}\" to stop container. - test: bash tests/integration.bash http://clue.localhost/ test -z "$$(git status --porcelain)" || (echo Directory is dirty && git status && exit 1) @@ -33,6 +22,7 @@ deploy: git -C build/ push origin live -f clean: - rm -rf build/ vendor/ tailwindcss + rm -rf build/ vendor/ + docker compose down --remove-orphans --rmi local -.PHONY: build serve served test deploy clean +.PHONY: build test deploy clean diff --git a/README.md b/README.md index f562eeb..eafbecb 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,9 @@ Source code for the https://clue.engineering/ website. -## Build +## Development + +### Build You can build the website like this: @@ -13,19 +15,21 @@ You can build the website like this: make ``` +### Run + Once built, you can manually browse the `build/` directory or run the web server container (Apache) in the foreground like this: ```bash -make serve +docker compose up --build --watch ``` -Alternatively, you may also run the web server container (Apache) as a -background daemon like this: +> Once running, you can now access http://clue.localhost/ in your web browser. +> If you want to run this on a different port, you may pass the `PORT` +> environment variable like `PORT=8080 docker compose up`. +> To run the container in the background, you may use the `docker compose up -d` command. -```bash -make served -``` +### Tests Once running, you can run some integration tests that check correct paths etc. like this: @@ -41,6 +45,8 @@ make test > tests/integration.bash http://clue.localhost/ > ``` +### Cleanup + Once done, you can clean up like this: ```bash diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..e191eec --- /dev/null +++ b/compose.yaml @@ -0,0 +1,34 @@ +services: + # main apache service running the full website + apache: + build: . + ports: + - ${PORT:-80}:80 + restart: unless-stopped + develop: + watch: + - path: app/ + action: rebuild + - path: www/ + action: rebuild + - path: composer.lock + action: rebuild + - path: Dockerfile + action: rebuild + + # tailwind dev sidecar to watch and recompile CSS on demand + tailwind: + build: + context: . + target: tailwind + command: --watch -o www/src/tailwind.min.css --minify + restart: unless-stopped + stdin_open: true + stop_signal: SIGKILL + volumes: + - ./tailwind.config.js:/app/tailwind.config.js:ro + - ./www:/app/www:rw + develop: + watch: + - path: Dockerfile + action: rebuild From d8d89b612b780bc151fb8b325c7fb33333a7501f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sat, 13 Sep 2025 22:46:49 +0200 Subject: [PATCH 2/3] Use Docker healthcheck to await container start --- .github/workflows/ci.yml | 3 +-- Dockerfile | 2 ++ tests/await.bash | 16 ---------------- 3 files changed, 3 insertions(+), 18 deletions(-) delete mode 100755 tests/await.bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7b5f69e..e98fac5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,8 +20,7 @@ jobs: coverage: none - run: make - run: docker compose build - - run: docker compose up -d - - run: bash tests/await.bash http://clue.localhost/ + - run: docker compose up -d --wait - run: make test - run: docker compose stop -t 60 timeout-minutes: 0.5 diff --git a/Dockerfile b/Dockerfile index 0f70256..2e02778 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,3 +20,5 @@ RUN vendor/bin/sculpin generate FROM php:8.1-apache RUN ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled COPY --from=build /app/build/ /var/www/html/ +HEALTHCHECK --start-period=1m --start-interval=0.1s --interval=1h \ + CMD ["curl", "-I", "--no-progress-meter", "http://localhost/"] diff --git a/tests/await.bash b/tests/await.bash deleted file mode 100755 index 7b098b6..0000000 --- a/tests/await.bash +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -# @copyright Copyright (c) 2024 Christian Lück, taken from https://github.com/clue/framework-x/pull/3 with permission - -base=${1:-http://clue.localhost/} -base=${base%/} - -for i in {1..600} -do - out=$(curl -v -X PROBE $base/ 2>&1) && exit 0 || echo -n . - sleep 0.1 -done - -echo -echo "$out" -exit 1 From e339925df90c58138f49a91783033cef5d1d1fc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sat, 13 Sep 2025 23:49:57 +0200 Subject: [PATCH 3/3] Update test suite to print logs sorted by timestamp across all services --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e98fac5..0c0ed9d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: - run: make test - run: docker compose stop -t 60 timeout-minutes: 0.5 - - run: docker compose logs + - run: docker compose logs --timestamps | sort -k3 if: ${{ always() }} - run: git config --global user.name "GitHub Actions" && git config --global user.email "actions@github.com" - run: git config --global url."https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/".insteadOf "https://github.com/"