-
Notifications
You must be signed in to change notification settings - Fork 7
121 lines (116 loc) · 4.2 KB
/
pr.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
name: PR checks
on: pull_request
env:
ACTIONS_RUNNER_DEBUG: true
SECRET_KEY: test
ENV: ci
FLASK_DIRECTORY: /api/
FLASK_DOMAIN: http://localhost
FRONTEND_DOMAIN: http://localhost
MONGO_AUTH_USERNAME: root
MONGO_AUTH_PASSWORD: rootPassXXX
MONGO_APP_DATABASE: binbot
MONGO_AUTH_DATABASE: admin
MONGO_HOSTNAME: db
MONGO_PORT: 27017
jobs:
push_to_registry:
name: Test and deploy binbot
runs-on: ubuntu-latest
services:
db:
image: mongo
options: >-
--health-cmd mongosh
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
MONGO_INITDB_ROOT_USERNAME: ${{ env.MONGO_AUTH_USERNAME }}
MONGO_INITDB_ROOT_PASSWORD: ${{ env.MONGO_AUTH_PASSWORD }}
ports:
- 27017:27017
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Build image
run: docker build --tag binbot .
- name: Test app
run: |
docker run --network host --name binbot \
-e MONGO_HOSTNAME=${{ env.MONGO_HOSTNAME }} \
-e MONGO_PORT=${{ env.MONGO_PORT }} \
-e MONGO_APP_DATABASE=${{ env.MONGO_APP_DATABASE }} \
-e MONGO_AUTH_USERNAME=${{ env.MONGO_AUTH_USERNAME }} \
-e MONGO_AUTH_PASSWORD=${{ env.MONGO_AUTH_PASSWORD }} \
-e ENV=ci -d binbot
curl --head --fail --retry-delay 5 --retry 3 --retry-connrefused http://localhost
- name: Test api
run: |
docker run --name binbot_api -p 8008:8006 \
-e MONGO_HOSTNAME=${{ env.MONGO_HOSTNAME }} \
-e MONGO_PORT=${{ env.MONGO_PORT }} \
-e MONGO_APP_DATABASE=${{ env.MONGO_APP_DATABASE }} \
-e MONGO_AUTH_USERNAME=${{ env.MONGO_AUTH_USERNAME }} \
-e MONGO_AUTH_PASSWORD=${{ env.MONGO_AUTH_PASSWORD }} \
-e ENV=ci -d binbot
curl --head --fail --retry-delay 10 --retry 3 --retry-all-errors http://localhost:8008
- name: Tag image
if: ${{ github.actor != 'dependabot[bot]' }}
run: |
docker commit binbot_api carloswufei/binbot &
docker tag binbot carloswufei/binbot
- name: Push to Docker Hub
if: ${{ github.actor != 'dependabot[bot]' }}
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker push carloswufei/binbot
deploy_streaming:
name: Deploy streaming
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Build image
run: docker build --tag binbot_streaming -f Dockerfile.streaming .
- name: Test run script
run: |
docker run --network host --name binbot_streaming \
-e MONGO_HOSTNAME=${{ env.MONGO_HOSTNAME }} \
-e MONGO_PORT=${{ env.MONGO_PORT }} \
-e MONGO_APP_DATABASE=${{ env.MONGO_APP_DATABASE }} \
-e MONGO_AUTH_USERNAME=${{ env.MONGO_AUTH_USERNAME }} \
-e MONGO_AUTH_PASSWORD=${{ env.MONGO_AUTH_PASSWORD }} \
-e PYTHONUNBUFFERED=TRUE \
-e ENV=ci -d binbot_streaming
- name: Tag image
if: ${{ github.actor != 'dependabot[bot]' }}
run: |
docker commit binbot_streaming carloswufei/binbot_streaming &
docker tag binbot_streaming carloswufei/binbot_streaming
- name: Push to Docker Hub
if: ${{ github.actor != 'dependabot[bot]' }}
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker push carloswufei/binbot_streaming
python_tests:
name: Python code tests
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
# Setup Python (faster than using Python container)
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.10.8"
- name: Install pipenv
run: |
python3 -m pip install --upgrade pipenv wheel
- name: Install dependencies
run: |
pipenv install --dev --system --deploy --ignore-pipfile --clear
working-directory: api
- name: Run tests
run: pipenv run pytest -v
working-directory: api