Skip to content

Commit 2c1a0ba

Browse files
committed
updates
1 parent 4a1ce1c commit 2c1a0ba

File tree

6 files changed

+56
-28
lines changed

6 files changed

+56
-28
lines changed

.github/workflows/main.yml

+44-19
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,27 @@ jobs:
1919
run: echo ${GITHUB_TOKEN} | docker login -u ${GITHUB_ACTOR} --password-stdin ghcr.io
2020
env:
2121
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22-
- name: Pull image
22+
- name: Pull images
2323
run: |
24-
docker pull ${{ env.IMAGE }}:latest || true
25-
- name: Build image
24+
docker pull ${{ env.IMAGE }}-builder:latest || true
25+
docker pull ${{ env.IMAGE }}-final:latest || true
26+
- name: Build images
2627
run: |
2728
docker build \
28-
--cache-from ${{ env.IMAGE }}:latest \
29-
--tag ${{ env.IMAGE }}:latest \
29+
--target builder \
30+
--cache-from ${{ env.IMAGE }}-builder:latest \
31+
--tag ${{ env.IMAGE }}-builder:latest \
32+
--file ./project/Dockerfile.prod \
33+
"./project"
34+
docker build \
35+
--cache-from ${{ env.IMAGE }}-final:latest \
36+
--tag ${{ env.IMAGE }}-final:latest \
3037
--file ./project/Dockerfile.prod \
3138
"./project"
32-
- name: Push image
39+
- name: Push images
3340
run: |
34-
docker push ${{ env.IMAGE }}:latest
41+
docker push ${{ env.IMAGE }}-builder:latest
42+
docker push ${{ env.IMAGE }}-final:latest
3543
3644
test:
3745
name: Test Docker Image
@@ -41,19 +49,26 @@ jobs:
4149
- name: Checkout
4250
uses: actions/checkout@v3
4351
with:
44-
ref: updates
52+
ref: main
4553
- name: Log in to GitHub Packages
4654
run: echo ${GITHUB_TOKEN} | docker login -u ${GITHUB_ACTOR} --password-stdin ghcr.io
4755
env:
4856
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49-
- name: Pull image
57+
- name: Pull images
5058
run: |
51-
docker pull ${{ env.IMAGE }}:latest || true
52-
- name: Build image
59+
docker pull ${{ env.IMAGE }}-builder:latest || true
60+
docker pull ${{ env.IMAGE }}-final:latest || true
61+
- name: Build images
5362
run: |
5463
docker build \
55-
--cache-from ${{ env.IMAGE }}:latest \
56-
--tag ${{ env.IMAGE }}:latest \
64+
--target builder \
65+
--cache-from ${{ env.IMAGE }}-builder:latest \
66+
--tag ${{ env.IMAGE }}-builder:latest \
67+
--file ./project/Dockerfile.prod \
68+
"./project"
69+
docker build \
70+
--cache-from ${{ env.IMAGE }}-final:latest \
71+
--tag ${{ env.IMAGE }}-final:latest \
5772
--file ./project/Dockerfile.prod \
5873
"./project"
5974
- name: Run container
@@ -66,7 +81,9 @@ jobs:
6681
-e DATABASE_URL=sqlite://sqlite.db \
6782
-e DATABASE_TEST_URL=sqlite://sqlite.db \
6883
-p 5003:8765 \
69-
${{ env.IMAGE }}:latest
84+
${{ env.IMAGE }}-final:latest
85+
- name: Install requirements
86+
run: docker exec fastapi-tdd pip install black==25.1.0 flake8==7.2.0 isort==6.0.1 pytest==8.3.5
7087
- name: Pytest
7188
run: docker exec fastapi-tdd python -m pytest .
7289
- name: Flake8
@@ -92,13 +109,21 @@ jobs:
92109
run: echo ${GITHUB_TOKEN} | docker login -u ${GITHUB_ACTOR} --password-stdin ghcr.io
93110
env:
94111
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95-
- name: Pull image
112+
- name: Pull images
96113
run: |
97-
docker pull ${{ env.IMAGE }}:latest || true
98-
- name: Build image
114+
docker pull ${{ env.IMAGE }}-builder:latest || true
115+
docker pull ${{ env.IMAGE }}-final:latest || true
116+
- name: Build images
99117
run: |
100118
docker build \
101-
--cache-from ${{ env.IMAGE }}:latest \
119+
--target builder \
120+
--cache-from ${{ env.IMAGE }}-builder:latest \
121+
--tag ${{ env.IMAGE }}-builder:latest \
122+
--file ./project/Dockerfile.prod \
123+
"./project"
124+
docker build \
125+
--cache-from ${{ env.IMAGE }}-final:latest \
126+
--tag ${{ env.IMAGE }}:latest \
102127
--tag ${{ env.HEROKU_REGISTRY_IMAGE }}:latest \
103128
--file ./project/Dockerfile.prod \
104129
"./project"
@@ -107,7 +132,7 @@ jobs:
107132
env:
108133
HEROKU_AUTH_TOKEN: ${{ secrets.HEROKU_AUTH_TOKEN }}
109134
- name: Push to the registry
110-
run: docker push ${{ env.HEROKU_REGISTRY_IMAGE }}
135+
run: docker push ${{ env.HEROKU_REGISTRY_IMAGE }}:latest
111136
- name: Set environment variables
112137
run: |
113138
echo "HEROKU_REGISTRY_IMAGE=${{ env.HEROKU_REGISTRY_IMAGE }}" >> $GITHUB_ENV

project/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ RUN apt-get update \
1616
# install python dependencies
1717
RUN pip install --upgrade pip
1818
COPY ./requirements.txt .
19-
RUN pip install -r requirements.txt
19+
COPY ./requirements-dev.txt .
20+
RUN pip install -r requirements-dev.txt
2021

2122
# add app
2223
COPY . .

project/app/api/ping.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
@router.get("/ping")
99
async def pong(settings: Settings = Depends(get_settings)):
1010
return {
11-
"ping": "pong",
11+
"ping": "pong!",
1212
"environment": settings.environment,
1313
"testing": settings.testing,
1414
}

project/requirements-dev.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
black==25.1.0
2+
flake8==7.2.0
3+
isort==6.0.1
4+
pytest==8.3.5
5+
pytest-cov==6.1.1
6+
pytest-xdist==3.6.1
7+
8+
-r requirements.txt

project/requirements.txt

-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
aerich[toml]==0.8.2
22
asyncpg==0.30.0
3-
black==25.1.0
43
fastapi==0.115.12
5-
flake8==7.2.0
64
gunicorn==22.0.0
75
httpx==0.28.1
8-
isort==6.0.1
96
lxml-html-clean==0.4.2
107
newspaper3k==0.2.8
118
pydantic-settings==2.8.1
12-
pytest==8.3.5
13-
pytest-cov==6.1.1
14-
pytest-xdist==3.6.1
159
tortoise-orm==0.25.0
1610
uvicorn==0.34.1

project/tests/test_ping.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
def test_ping(test_app):
22
response = test_app.get("/ping")
33
assert response.status_code == 200
4-
assert response.json() == {"environment": "dev", "ping": "pong", "testing": True}
4+
assert response.json() == {"environment": "dev", "ping": "pong!", "testing": True}

0 commit comments

Comments
 (0)