Skip to content

Commit

Permalink
feature(package): Added caches to actions.
Browse files Browse the repository at this point in the history
Moved ci dependency installs into ``dockerfile``.
Added/corrected image labels in ``compose.yaml`` files and ``pyproject.toml``.
  • Loading branch information
acederberg committed Aug 19, 2024
1 parent 65cb645 commit a91de1a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 31 deletions.
60 changes: 33 additions & 27 deletions .github/workflows/commit_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ jobs:
with:
python-version: '3.11'

- name: Cache Pip
uses: actions/cache@v3
id: venv
with:
path: .venv
key: ${{ runner.os }}-venv-${{ hashFiles('poetry.lock') }}

- name: Venv and Setup
run: |
echo -e "## Python Info\n" >> $GITHUB_STEP_SUMMARY
Expand Down Expand Up @@ -125,31 +132,29 @@ jobs:
echo "CAPTURA_CONFIG_APP=$docker_config_path" >> .env
echo "CAPTURA_FLAKEY=/home/captura/flakey.yaml" >> .env
# https://github.com/docker/build-push-action?tab=readme-ov-file#usage
- name: Build Server Image.
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/dockerfile
target: ci
tags: acederberg/captura-ci # should match tags in `./docker/compose.ci.yaml`.

pull: false
push: false

cache-from: type=gha,ref=acederberg/captura-ci
cache-to: type=gha,mode=max

- name: Start Docker Compose Project.
run: |
docker compose \
--file docker/compose.ci.yaml \
--env-file .env \
up --detach --quiet-pull
docker compose \
--file docker/compose.ci.yaml \
exec server \
bash -c ' \
mkdir --parents ~/app/.venv \
&& python -m venv ~/app/.venv'
up --detach --build --quiet-pull
# NOTE: ``act.yaml`` defined everything necessary for the client and server.
- name: Install Dependencies In Server.
run: |
docker compose \
--file docker/compose.ci.yaml \
exec server \
bash -c ' \
source ~/app/.venv/bin/activate \
&& pip install --quiet poetry \
&& poetry install --with test'
- name: Generate Dummy Data In Server.
run: |
version=$( \
Expand All @@ -166,15 +171,15 @@ jobs:
&& poetry run simulatus initialize \
&& poetry run simulatus apply'
echo -e "# Dummy Data Report\n\n~~~" >> $GITHUB_STEP_SUMMARY
docker compose \
--file docker/compose.ci.yaml \
exec server \
bash -c ' \
source ~/app/.venv/bin/activate \
&& poetry run simulatus --loud reports aggregate' \
>> $GITHUB_STEP_SUMMARY
echo -e "~~~\n" >> $GITHUB_STEP_SUMMARY
# echo -e "# Dummy Data Report\n\n~~~" >> $GITHUB_STEP_SUMMARY
# docker compose \
# --file docker/compose.ci.yaml \
# exec server \
# bash -c ' \
# source ~/app/.venv/bin/activate \
# && poetry run simulatus --loud reports aggregate' \
# >> $GITHUB_STEP_SUMMARY
# echo -e "~~~\n" >> $GITHUB_STEP_SUMMARY
- name: Run Tests.
run: |
Expand All @@ -195,6 +200,7 @@ jobs:
bash -c ' \
source ~/app/.venv/bin/activate \
&& poetry run coverage html'
continue-on-error: true

- name: Stop Compose Project.
if: always()
Expand Down
1 change: 1 addition & 0 deletions docker/compose.ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
extends:
file: ./compose.base.yaml
service: server
image: acederberg/captura-ci:0.1.5
networks:
captura: {}
db:
Expand Down
2 changes: 1 addition & 1 deletion docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
extends:
file: ./compose.base.yaml
service: server
image: acederberg/captura-ci:0.1.5
image: acederberg/captura-development:0.1.5
networks:
captura: {}
volumes:
Expand Down
14 changes: 12 additions & 2 deletions docker/dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,25 @@ COPY ./docker/docker.sh /home/captura/.bashrc

# --------------------------------------------------------------------------- #

FROM base AS ci
FROM base AS base_w_repo

# NOTE: Assumes that build is occuring at the project root.
COPY --chown=captura:captura ./ /home/captura/app


# --------------------------------------------------------------------------- #

FROM ci AS production
FROM base_w_repo AS ci

RUN mkdir --parents /home/captura/app/.venv \
&& python -m venv /home/captura/app/.venv \
&& .venv/bin/python3 -m pip install --quiet poetry \
&& .venv/bin/python3 -m poetry install --with test


# --------------------------------------------------------------------------- #

FROM base_w_repo AS production

RUN mkdir /home/captura/.captura /home/captura/.captura/logs
COPY ./docker/logging.yaml /home/captura/.captura
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ push = false
[tool.bumpver.file_patterns]
"pyproject.toml" = ['current_version = "{version}"', 'version = "{version}"']
"src/app/__init__.py" = ["{version}"]
"docker/docker-compose.yaml" = ["image: acederberg/captura-development:{version}"]
"docker/compose.yaml" = ["image: acederberg/captura-development:{version}"]
"docker/compose.ci.yaml" = ["image: acederberg/captura-ci:{version}"]


[tool.setuptools_scm]
Expand Down

0 comments on commit a91de1a

Please sign in to comment.