This repository was archived by the owner on Sep 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (103 loc) · 3.98 KB
/
prod.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
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Production Server Check and Build
on:
workflow_dispatch:
push:
branches:
- production
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Load cached Poetry installation
id: cached-poetry
uses: actions/cache@v3
with:
path: ~/.local # the path depends on the OS
key: poetry-1 # increment to reset cache
- name: Install Poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: ~/.cache
key: venv-${{ runner.os }}-{% raw %}${{ hashFiles('**/poetry.lock') }}
restore-keys: |
venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
venv-${{ runner.os }}-
- name: Install dependencies
run: |
poetry export --with test --without dev --output requirements.txt --without-urls
poetry run pip install -r requirements.txt
- name: Style check
run: |
poetry run black --check server
poetry run flake8 server --count --statistics
poetry run isort --check-only server
- name: Pytest
run: poetry run pytest --cov-config=tests/.coveragerc --cov server --cov-report xml -n logical
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
fail_ci_if_error: true
- name: Override Coverage Source Path for Sonar
run: sed -i 's/\/home\/runner\/work\/teamup_backend\/teamup_backend\//\/github\/workspace\//g' ./coverage.xml
- name: SonarQube scan
uses: sonarsource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
build:
runs-on: ubuntu-latest
needs:
- test
strategy:
matrix:
image: [ 'django' ]
steps:
- name: checkout code
uses: actions/checkout@v3
- name: using cache
uses: satackey/[email protected]
# Ignore the failure of a step and avoid terminating the job.
continue-on-error: true
with:
key: docker-layer-caching-${{ github.workflow }}-${{ matrix.image }}-{hash}
restore-keys: |
docker-layer-caching-${{ github.workflow }}-${{ matrix.image }}-
- name: build and push docker image ${{ matrix.image }}
run: |
docker login registry.cn-hangzhou.aliyuncs.com --username=${{ secrets.DOCKER_USERNAME }} --password=${{ secrets.DOCKER_PASSWORD }}
docker build -f docker/${{ matrix.image }}/Dockerfile -t registry.cn-hangzhou.aliyuncs.com/ziqiang_studio/teamup-pub:${{ matrix.image }} .
docker push registry.cn-hangzhou.aliyuncs.com/ziqiang_studio/teamup-pub:${{ matrix.image }}
deploy:
runs-on: ubuntu-latest
needs:
- build
steps:
- name: deploy docker image
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
script: |
cd ~/backend
docker login registry.cn-hangzhou.aliyuncs.com --username=${{ secrets.DOCKER_USERNAME }} --password=${{ secrets.DOCKER_PASSWORD }}
docker compose pull