Skip to content

Commit 291707f

Browse files
authored
Merge pull request #22 from LeanderCS/15
15 | Add caching to workflow
2 parents 89959ef + 4c4625f commit 291707f

File tree

2 files changed

+69
-10
lines changed

2 files changed

+69
-10
lines changed

.github/workflows/test.yaml

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,55 @@ permissions:
77
contents: read
88

99
jobs:
10-
test:
10+
build:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- name: Checkout code
15-
uses: actions/checkout@v4
14+
- uses: actions/checkout@v4
1615

17-
- name: Build Docker image
18-
run: docker build . -t flask-inputfilter
16+
- name: Cache Docker layers
17+
uses: actions/cache@v4
18+
with:
19+
path: /tmp/.buildx-cache
20+
key: ${{ runner.os }}-docker-flask-inputfilter-${{ hashFiles('Dockerfile') }}
21+
restore-keys: |
22+
${{ runner.os }}-docker-flask-inputfilter-
23+
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v2
26+
with:
27+
driver-opts: image=moby/buildkit:latest
28+
29+
- name: Build flask-inputfilter image with cache
30+
run: |
31+
docker buildx build \
32+
--cache-from=type=local,src=/tmp/.buildx-cache \
33+
--cache-to=type=local,dest=/tmp/.buildx-cache,mode=max \
34+
-t flask-inputfilter . --load
35+
36+
# - name: Save flask-inputfilter image
37+
# run: docker save -o flask-inputfilter.tar flask-inputfilter
38+
#
39+
# - name: Upload flask-inputfilter artifact
40+
# uses: actions/upload-artifact@v4
41+
# with:
42+
# name: flask-inputfilter-image
43+
# path: flask-inputfilter.tar
44+
#
45+
# test:
46+
# runs-on: ubuntu-latest
47+
#
48+
# steps:
49+
# - name: Checkout code
50+
# uses: actions/checkout@v4
51+
#
52+
# - name: Download flask-inputfilter artifact
53+
# uses: actions/download-artifact@v4
54+
# with:
55+
# name: flask-inputfilter-image
56+
#
57+
# - name: Load flask-inputfilter image
58+
# run: docker load -i flask-inputfilter.tar
1959

2060
- name: Run tests in Docker and upload coverage to Coveralls
2161
env:
@@ -25,12 +65,12 @@ jobs:
2565
set -e # Exit immediately if a command exits with a non-zero status.
2666
set -u # Exit immediately if a variable is not defined.
2767
28-
docker run -e COVERALLS_REPO_TOKEN=${{ secrets.COVERALLS_REPO_TOKEN }} flask-inputfilter sh -c "coverage run --source=flask_inputfilter -m pytest test/ && coveralls"
68+
docker run --rm -e COVERALLS_REPO_TOKEN=${{ secrets.COVERALLS_REPO_TOKEN }} flask-inputfilter sh -c "coverage run --source=flask_inputfilter -m pytest test/ && coveralls"
2969
3070
- name: Run code style checks
3171
run: |
3272
set -x # Print commands and their arguments as they are executed
3373
set -e # Exit immediately if a command exits with a non-zero status
3474
set -u # Exit immediately if a variable is not defined
3575
36-
docker run flask-inputfilter flake8
76+
docker run --rm flask-inputfilter flake8

.github/workflows/test_env.yaml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,32 @@ jobs:
1414
- name: Checkout code
1515
uses: actions/checkout@v4
1616

17-
- name: Build Docker image
18-
run: docker build -f env_configs/Dockerfile . -t flask-inputfilter-env
17+
- name: Cache Docker layers
18+
uses: actions/cache@v4
19+
with:
20+
path: /tmp/.buildx-cache
21+
key: ${{ runner.os }}-docker-flask-inputfilter-env-${{ hashFiles('Dockerfile') }}
22+
restore-keys: |
23+
${{ runner.os }}-docker-flask-inputfilter-env-
24+
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v2
27+
with:
28+
driver-opts: image=moby/buildkit:latest
29+
30+
- name: Build flask-inputfilter-env image with cache
31+
run: |
32+
docker buildx build \
33+
--cache-from=type=local,src=/tmp/.buildx-cache \
34+
--cache-to=type=local,dest=/tmp/.buildx-cache,mode=max \
35+
-t flask-inputfilter-env \
36+
-f env_configs/Dockerfile \
37+
. --load
1938
2039
- name: Run tests in Docker
2140
run: |
2241
set -x # Print commands and their arguments as they are executed.
2342
set -e # Exit immediately if a command exits with a non-zero status.
2443
set -u # Exit immediately if a variable is not defined.
2544
26-
docker run flask-inputfilter-env tox
45+
docker run --rm flask-inputfilter-env tox

0 commit comments

Comments
 (0)