Skip to content

Commit 33b4cb4

Browse files
committed
testing ci/cd
1 parent 888a0df commit 33b4cb4

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 /bin/sh -c "python -m isort ./*/*.py --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: salty-fortress-93778
80+
HEROKU_REGISTRY_IMAGE: registry.heroku.com/${HEROKU_APP_NAME}/foo
81+
steps:
82+
- name: Checkout master
83+
uses: actions/checkout@v1
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 ::set-env name=HEROKU_REGISTRY_IMAGE::${{ env.HEROKU_REGISTRY_IMAGE }}
107+
echo ::set-env name=HEROKU_AUTH_TOKEN::${{ secrets.HEROKU_AUTH_TOKEN }}
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
@@ -12,7 +12,7 @@
1212
@router.get("/ping")
1313
async def pong(settings: Settings = Depends(get_settings)):
1414
return {
15-
"ping": "pong!",
15+
"ping": "pong",
1616
"environment": settings.environment,
1717
"testing": settings.testing,
1818
}

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)