Skip to content
This repository was archived by the owner on May 18, 2025. It is now read-only.

Commit 85bb44f

Browse files
authored
chore(p1c12): Continuous Delivery (#8)
* chore: add cd * fix: miss tab in pipeline * chore: try to upgrade pip during build * fix: ctx typo * fix: poetry v build arg * refactor: remove feature branch from pipeline
1 parent 228f668 commit 85bb44f

File tree

6 files changed

+58
-2
lines changed

6 files changed

+58
-2
lines changed

.github/workflows/ main.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,45 @@ jobs:
8383
run: docker exec fastapi-tdd python -m black . --check
8484
- name: isort
8585
run: docker exec fastapi-tdd python -m isort . --check-only
86+
87+
deploy:
88+
name: Deploy to Heroku
89+
runs-on: ubuntu-latest
90+
needs: [build, test]
91+
env:
92+
HEROKU_APP_NAME: mighty-brook-75156
93+
HEROKU_REGISTRY_IMAGE: registry.heroku.com/${HEROKU_APP_NAME}/summarizer
94+
steps:
95+
- name: Checkout
96+
uses: actions/[email protected]
97+
with:
98+
ref: master
99+
- name: Log in to GitHub Packages
100+
run: echo ${GITHUB_TOKEN} | docker login -u ${GITHUB_ACTOR} --password-stdin docker.pkg.github.com
101+
env:
102+
GITHUB_TOKEN: ${{ secrets.DOC_GH_TOKEN }}
103+
- name: Pull image
104+
run: |
105+
docker pull ${{ env.IMAGE }}:latest || true
106+
- name: Build image
107+
run: |
108+
docker build \
109+
--build-arg POETRY_VERSION=1.1.12 \
110+
--cache-from ${{ env.IMAGE }}:latest \
111+
--tag ${{ env.HEROKU_REGISTRY_IMAGE }}:latest \
112+
--file ./Dockerfile.prod \
113+
"./"
114+
- name: Log in to the Heroku Container Registry
115+
run: docker login -u _ -p ${HEROKU_AUTH_TOKEN} registry.heroku.com
116+
env:
117+
HEROKU_AUTH_TOKEN: ${{ secrets.HEROKU_AUTH_TOKEN }}
118+
- name: Push to the registry
119+
run: docker push ${{ env.HEROKU_REGISTRY_IMAGE }}
120+
- name: Set environment variables
121+
run: |
122+
echo "HEROKU_REGISTRY_IMAGE=${{ env.HEROKU_REGISTRY_IMAGE }}" >> $GITHUB_ENV
123+
echo "HEROKU_AUTH_TOKEN=${{ secrets.HEROKU_AUTH_TOKEN }}" >> $GITHUB_ENV
124+
- name: Release
125+
run: |
126+
chmod +x ./release.sh
127+
./release.sh

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ RUN apk add --no-cache py3-psycopg2~=2.8.6 \
3535
libffi-dev~=3.3 \
3636
musl-dev~=1.2.2 \
3737
make~=4.3 \
38+
&& pip install --upgrade pip \
3839
&& pip install --no-cache-dir poetry==${POETRY_VERSION} \
3940
&& poetry config virtualenvs.create false \
4041
&& poetry install \

Dockerfile.prod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ RUN apk add --no-cache py3-psycopg2~=2.8.6 \
3737
libffi-dev~=3.3 \
3838
musl-dev~=1.2.2 \
3939
make~=4.3 \
40+
&& pip install --upgrade pip \
4041
&& pip install --no-cache-dir poetry==${POETRY_VERSION} \
4142
&& poetry config virtualenvs.create false \
4243
&& poetry install --no-dev \

project/app/api/ping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
@router.get("/ping")
1212
async def pong(settings: Settings = Depends(get_settings)):
1313
return {
14-
"ping": "pong!",
14+
"ping": "pong",
1515
"environment": settings.environment,
1616
"testing": settings.testing,
1717
}

project/tests/test_ping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
def test_ping(test_app):
88
response = test_app.get("/ping")
99
assert response.status_code == 200
10-
assert response.json() == {"environment": "dev", "ping": "pong!", "testing": True}
10+
assert response.json() == {"environment": "dev", "ping": "pong", "testing": True}

release.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
IMAGE_ID=$(docker inspect ${HEROKU_REGISTRY_IMAGE} --format={{.Id}})
6+
PAYLOAD='{"updates": [{"type": "web", "docker_image": "'"$IMAGE_ID"'"}]}'
7+
8+
curl -n -X PATCH https://api.heroku.com/apps/$HEROKU_APP_NAME/formation \
9+
-d "${PAYLOAD}" \
10+
-H "Content-Type: application/json" \
11+
-H "Accept: application/vnd.heroku+json; version=3.docker-releases" \
12+
-H "Authorization: Bearer ${HEROKU_AUTH_TOKEN}"

0 commit comments

Comments
 (0)