Skip to content

Commit 87cd6be

Browse files
committed
refactor: use docker build action
1 parent 2024a88 commit 87cd6be

File tree

4 files changed

+35
-19
lines changed

4 files changed

+35
-19
lines changed

.github/workflows/tests.yaml

+29-16
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ on:
1010
required: false
1111

1212
env:
13-
IMAGE_REGISTRY: ghcr.io
14-
API_IMAGE: ghcr.io/equinor/template-fastapi-react/api
15-
WEB_IMAGE: ghcr.io/equinor/template-fastapi-react/web
13+
REGISTRY: ghcr.io
14+
API_IMAGE_PATH: ${{ github.repository }}/api
15+
WEB_IMAGE_PATH: ${{ github.repository }}/web
1616

1717
jobs:
1818
api-unit-tests:
@@ -39,27 +39,40 @@ jobs:
3939
api-integration-tests:
4040
runs-on: ubuntu-latest
4141
steps:
42-
- uses: actions/checkout@v4
42+
- name: "Setup: checkout repository"
43+
uses: actions/checkout@v4
4344

44-
- name: "Login to GitHub Container Registry"
45+
- name: "Setup: Login to GitHub Container Registry"
4546
uses: docker/login-action@v3
4647
with:
47-
registry: ${{ env.IMAGE_REGISTRY }}
48+
registry: ${{ env.REGISTRY }}
4849
username: ${{ github.actor }}
4950
password: ${{ secrets.GITHUB_TOKEN }}
5051

51-
- name: Build API image
52-
run: |
53-
docker pull $API_IMAGE
54-
docker build --target development --tag api-development ./api # TODO: --cache-from $API_IMAGE
52+
- name: "Setup: Docker Buildx"
53+
uses: docker/setup-buildx-action@v3
54+
55+
- name: "Setup: Build API image"
56+
uses: docker/build-push-action@v6
57+
with:
58+
context: ./api
59+
target: development
60+
load: true
61+
tags: api-development
62+
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.API_IMAGE_PATH }}:latest
63+
64+
# - name: Build API image
65+
# run: |
66+
# docker pull $API_IMAGE
67+
# docker build --target development --tag api-development ./api # TODO: --cache-from $API_IMAGE
68+
69+
- name: Pytest Integration tests
70+
run: docker compose -f docker-compose.yml -f docker-compose.ci.yml run --rm api python -m pytest --integration
5571

5672
- name: BDD Integration tests
5773
if: ${{ false }} # disable for now
5874
run: docker compose -f docker-compose.yml -f docker-compose.ci.yml run api behave
5975

60-
- name: Pytest Integration tests
61-
run: docker compose -f docker-compose.yml -f docker-compose.ci.yml run --rm api pytest --integration
62-
6376
web-tests:
6477
runs-on: ubuntu-latest
6578
steps:
@@ -68,14 +81,14 @@ jobs:
6881
- name: "Login to GitHub Container Registry"
6982
uses: docker/login-action@v3
7083
with:
71-
registry: ${{ env.IMAGE_REGISTRY }}
84+
registry: ${{ env.REGISTRY }}
7285
username: ${{ github.actor }}
7386
password: ${{ secrets.GITHUB_TOKEN }}
7487

7588
- name: Build Web Image
7689
run: |
77-
docker pull $WEB_IMAGE
78-
docker build --cache-from $WEB_IMAGE --target development --tag web-dev ./web
90+
docker pull ${REGISTRY}/${WEB_IMAGE_PATH}
91+
docker build --cache-from ${REGISTRY}/${WEB_IMAGE_PATH} --target development --tag web-dev ./web
7992
8093
- name: Run Web tests
8194
if: ${{ false }} # disable for now as they do not currently work

docker-compose.ci.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
services:
22
api:
3-
image: development
3+
# image: ghcr.io/equinor/template-fastapi-react/api:buildcache
4+
image: api-development
45
build:
56
target: development
67
environment:

docker-compose.override.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
services:
22
api:
3+
image: template-api-dev
34
build:
45
target: development
5-
image: template-api-dev
66
platform: linux/amd64
77
volumes:
88
- ./api/src/:/code/src

docker-compose.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ services:
1212

1313
api:
1414
image: ghcr.io/equinor/template-fastapi-react/api
15-
build: ./api
15+
build:
16+
target: prod
17+
context: ./api
1618
restart: unless-stopped
1719
depends_on:
1820
- db

0 commit comments

Comments
 (0)