Skip to content

gha caching with docker #72

gha caching with docker

gha caching with docker #72

Workflow file for this run

name: CI
on:
pull_request:
workflow_call:
concurrency:
group: ci-${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
PYTHON_VERSION: 3.11
POETRY_VERSION: 1.6.1
jobs:
ci:
name: "Deputy CI"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # check out the repo
- uses: actions/setup-python@v4 # setup python
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: pip
- uses: actions/cache@v3 # load pip cache from previous steps if exists
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: ${{ runner.os }}-pip-${{ env.PYTHON_VERSION }}
- uses: actions/cache@v3 # load poetry cache from previous steps if exists
id: cached-poetry
with:
path: ~/.local
key: ${{ runner.os }}-poetry-${{ env.POETRY_VERSION }}
restore-keys: ${{ runner.os }}-poetry
- uses: snok/install-poetry@v1 # install and configure poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
with:
version: ${{ env.POETRY_VERSION }}
virtualenvs-create: true
virtualenvs-in-project: true
- uses: actions/cache@v3 # load venv if exists
id: cached-venv
with:
path: ${{ github.workspace }}/.venv
key: ${{ runner.os }}-venv-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: ${{ runner.os }}-venv-${{ env.PYTHON_VERSION }}
- name: Install dependencies
if: steps.cached-venv.outputs.cache-hit != 'true'
run: |
poetry config virtualenvs.create true
poetry config virtualenvs.in-project true
poetry install --with=dev --no-interaction
- name: Copy .env file
run: cp .env.example .env
- name: Lint project
uses: chartboost/ruff-action@v1
- name: Format project
run: poetry run black --check .
- name: Type check project
run: poetry run mypy .
- name: Test project
run: poetry run pytest
docker:
name: "Deputy Docker"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # check out the repo
- run: cp .env.example .env # copy .env file
- uses: docker/setup-buildx-action@v2 # setup docker buildx
- uses: docker/build-push-action@v4 # build docker image
with:
context: .
file: ./docker/prod/Dockerfile
push: false # don't push image to docker registry
tags: ${{ secrets.DOCKERHUB_USERNAME }}/deputy:latest
cache-from: type=gha
cache-to: type=gha,mode=max