Skip to content

try to run ci in docker #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ jobs:

steps:
- uses: actions/checkout@v4
# submodules: recursive
# fetch-depth: 0

- name: checkout submodules
shell: bash
Expand All @@ -53,46 +55,44 @@ jobs:
git submodule init
git submodule status | cut -d" " -f2 | xargs -n1 -P0 git submodule update

- name: setup Git
shell: bash
- name: warm up docker image
run: |
git config --global user.email "[email protected]"
git config --global user.name "Elspeth See-Eye"
git config --global init.defaultBranch main

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12

- name: Install apt stuff and other dependencies
shell: bash
docker run --rm \
--mount type=volume,source=rootmount,target=/root \
--mount type=bind,source=./,target=/app \
-t hjwp/obeythetestinggoat-book-tester:latest \
bash -c "echo hello world"

- name: uv create virtualenv in mounted /app folder at .venv and install latest/upgraded deps
# todo, replace with make docker-venv?
run: |
sudo add-apt-repository ppa:mozillateam/ppa
sudo apt update -y
sudo apt install -y \
asciidoctor \
language-pack-en \
ruby-coderay \
ruby-pygments.rb \
firefox-esr \
tree
pip install uv
docker run --rm \
--mount type=volume,source=rootmount,target=/root \
--mount type=bind,source=./,target=/app \
-t hjwp/obeythetestinggoat-book-tester:latest \
bash -c "uv venv && uv pip install --upgrade ."

- name: Install Python requirements.txt globally
shell: bash
- name: git mark dirs safe (due to volume mount perms issue)
run: |
uv pip install --system .

- name: Install Python requirements.txt into virtualenv
shell: bash
run: |
make .venv/bin

- name: Run chapter test
shell: bash
docker run --rm \
--mount type=volume,source=rootmount,target=/root \
--mount type=bind,source=./,target=/app \
-t hjwp/obeythetestinggoat-book-tester:latest \
bash -c "git config --global --add safe.directory '*'"
docker run --rm \
--mount type=volume,source=rootmount,target=/root \
--mount type=bind,source=./,target=/app \
-t hjwp/obeythetestinggoat-book-tester:latest \
bash -c "cat ~/.gitconfig"

- name: run chapter tests
# todo, replace with make docker_${{ matrix.test_chapter }} ?
run: |
make ${{ matrix.test_chapter }}
docker run --rm \
--mount type=volume,source=rootmount,target=/root \
--mount type=bind,source=./,target=/app \
-t hjwp/obeythetestinggoat-book-tester:latest \
bash -c "make ${{ matrix.test_chapter }}"

- name: Save tempdir path to an env var
if: always()
Expand Down
46 changes: 19 additions & 27 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,40 +1,32 @@
FROM python:slim
# -- Dockerfile is intended mainly for use in CI --

RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
asciidoctor \
curl \
firefox-esr \
git \
make \
ruby-pygments.rb \
tree \
wget \
&& rm -rf /var/lib/apt/lists/*

# -- WIP --
# this dockerfile is a work in progress,
# the vague intention is to use it for CI.

# RUN add-apt-repository ppa:mozillateam/ppa && \
RUN apt-get update -y

RUN apt-get install -y \
git \
asciidoctor \
# language-pack-en \
ruby-pygments.rb \
firefox-esr \
tree \
locales

RUN apt-get install -y \
make \
curl

RUN locale-gen en_GB.UTF-8
# RUN pip install uv
ADD --chmod=755 https://astral.sh/uv/install.sh /install.sh
RUN /install.sh && rm /install.sh
RUN ln -s $HOME/.cargo/bin/uv /usr/bin/uv
RUN /install.sh && rm /install.sh && \
ln -s $HOME/.cargo/bin/uv /usr/bin/uv

RUN git config --global user.email "[email protected]" && \
git config --global user.name "Elspeth See-Eye" && \
git config --global init.defaultBranch main

WORKDIR /app
RUN uv venv .venv

COPY pyproject.toml pyproject.toml
RUN uv pip install .

# install python deps into a venv at /app/.venv,
# as a form of cache. even when we mount over it with --volume,
# the content is copied in.
RUN uv venv .venv && uv pip install .

CMD bash
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,30 @@ unit-test: chapter_01.html $(VENV)/bin
clean:
rm -rf $(TMPDIR)
rm -v $(HTML_PAGES)

.PHONY: docker-build
docker-build:
docker build --platform=linux/amd64 -t hjwp/obeythetestinggoat-book-tester:latest .

.PHONY: docker-push
docker-push:
docker push hjwp/obeythetestinggoat-book-tester:latest

.PHONY: docker-venv
docker-venv:
docker run --rm \
--mount type=volume,source=rootmount,target=/root \
--mount type=bind,source=./,target=/app \
--mount type=volume,source=venvmount,target=/app/.venv \
-t hjwp/obeythetestinggoat-book-tester:latest \
bash -c "uv venv .venv && uv pip install --upgrade ."

.PHONY: docker-test_%
docker-test_%: docker-venv %.html $(TMPDIR)
docker run --rm \
--mount type=volume,source=rootmount,target=/root \
--mount type=bind,source=./,target=/app \
--mount type=volume,source=venvmount,target=/app/.venv \
-t hjwp/obeythetestinggoat-book-tester:latest \
bash -c "make $(subst docker-,,$@)"

2 changes: 1 addition & 1 deletion chapter_01.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ $ *ls*
db.sqlite3 functional_tests.py manage.py superlists

$ *git init .*
Initialised empty Git repository in ...goat-book/.git/
Initialized empty Git repository in ...goat-book/.git/
----

// CSANAD: maybe we could mention that Git also provides hints about the default branch name
Expand Down
2 changes: 1 addition & 1 deletion chapter_08_prettification.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ static/
├── [...]
└── bootstrap.min.js.map

16 directories, 169 files
17 directories, 169 files
----

`collectstatic` has also picked up all the CSS for the admin site.
Expand Down
2 changes: 1 addition & 1 deletion chapter_16_javascript.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ src/lists/static/tests
├── jasmine.js
└── jasmine_favicon.png

2 directories, 9 files
3 directories, 9 files
----

We need to go edit the _SpecRunner.html_ file
Expand Down
2 changes: 1 addition & 1 deletion chapter_CI.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ lists/static/tests/
├── runner.js
└── tests.html

0 directories, 4 files
1 directories, 4 files
----

Let's try it out:
Expand Down
2 changes: 1 addition & 1 deletion tests/update_source_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def update_sources_for_chapter(chapter, previous_chapter=None):
# make sure branch for previous chapter is available to start tests
subprocess.check_output(["git", "checkout", previous_chapter], cwd=source_dir)
subprocess.check_output(
["git", "reset", "--hard", "{}/{}".format(REMOTE, previous_chapter)],
["git", "reset", "--hard", f"{REMOTE}/{previous_chapter}"],
cwd=source_dir,
)

Expand Down
Loading