Skip to content

Commit ef1388d

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

File tree

4 files changed

+36
-19
lines changed

4 files changed

+36
-19
lines changed

.github/workflows/tests.yaml

+30-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,41 @@ 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+
tags: |
61+
${{ env.REGISTRY }}/${{ env.API_IMAGE_PATH }}:latest
62+
api-development
63+
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.API_IMAGE_PATH }}:latest
64+
65+
# - name: Build API image
66+
# run: |
67+
# docker pull $API_IMAGE
68+
# docker build --target development --tag api-development ./api # TODO: --cache-from $API_IMAGE
69+
70+
- name: Pytest Integration tests
71+
run: docker compose -f docker-compose.yml -f docker-compose.ci.yml run --rm api python -m pytest --integration
5572

5673
- name: BDD Integration tests
5774
if: ${{ false }} # disable for now
5875
run: docker compose -f docker-compose.yml -f docker-compose.ci.yml run api behave
5976

60-
- name: Pytest Integration tests
61-
run: docker compose -f docker-compose.yml -f docker-compose.ci.yml run --rm api pytest --integration
62-
6377
web-tests:
6478
runs-on: ubuntu-latest
6579
steps:
@@ -68,14 +82,14 @@ jobs:
6882
- name: "Login to GitHub Container Registry"
6983
uses: docker/login-action@v3
7084
with:
71-
registry: ${{ env.IMAGE_REGISTRY }}
85+
registry: ${{ env.REGISTRY }}
7286
username: ${{ github.actor }}
7387
password: ${{ secrets.GITHUB_TOKEN }}
7488

7589
- name: Build Web Image
7690
run: |
77-
docker pull $WEB_IMAGE
78-
docker build --cache-from $WEB_IMAGE --target development --tag web-dev ./web
91+
docker pull ${REGISTRY}/${WEB_IMAGE_PATH}
92+
docker build --cache-from ${REGISTRY}/${WEB_IMAGE_PATH} --target development --tag web-dev ./web
7993
8094
- name: Run Web tests
8195
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)