Skip to content

Commit 0274549

Browse files
committed
testing ci/cd
1 parent 1c1a967 commit 0274549

4 files changed

Lines changed: 53 additions & 2 deletions

File tree

.github/workflows/main.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,42 @@ jobs:
7070
run: docker exec fastapi-tdd python -m black . --check
7171
- name: isort
7272
run: docker exec fastapi-tdd python -m isort . --check-only
73+
74+
deploy:
75+
name: Deploy to Heroku
76+
runs-on: ubuntu-latest
77+
needs: [build, test]
78+
env:
79+
HEROKU_APP_NAME: thawing-beach-87010
80+
HEROKU_REGISTRY_IMAGE: registry.heroku.com/${HEROKU_APP_NAME}/summarizer
81+
steps:
82+
- name: Checkout master
83+
uses: actions/checkout@v2.3.4
84+
- name: Log in to GitHub Packages
85+
run: echo ${GITHUB_TOKEN} | docker login -u ${GITHUB_ACTOR} --password-stdin docker.pkg.github.com
86+
env:
87+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88+
- name: Pull image
89+
run: |
90+
docker pull ${{ env.IMAGE }}:latest || true
91+
- name: Build image
92+
run: |
93+
docker build \
94+
--cache-from ${{ env.IMAGE }}:latest \
95+
--tag ${{ env.HEROKU_REGISTRY_IMAGE }}:latest \
96+
--file ./project/Dockerfile.prod \
97+
"./project"
98+
- name: Log in to the Heroku Container Registry
99+
run: docker login -u _ -p ${HEROKU_AUTH_TOKEN} registry.heroku.com
100+
env:
101+
HEROKU_AUTH_TOKEN: ${{ secrets.HEROKU_AUTH_TOKEN }}
102+
- name: Push to the registry
103+
run: docker push ${{ env.HEROKU_REGISTRY_IMAGE }}
104+
- name: Set environment variables
105+
run: |
106+
echo "HEROKU_REGISTRY_IMAGE=${{ env.HEROKU_REGISTRY_IMAGE }}" >> $GITHUB_ENV
107+
echo "HEROKU_AUTH_TOKEN=${{ secrets.HEROKU_AUTH_TOKEN }}" >> $GITHUB_ENV
108+
- name: Release
109+
run: |
110+
chmod +x ./release.sh
111+
./release.sh

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
@@ -4,4 +4,4 @@
44
def test_ping(test_app):
55
response = test_app.get("/ping")
66
assert response.status_code == 200
7-
assert response.json() == {"environment": "dev", "ping": "pong!", "testing": True}
7+
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)