-
Notifications
You must be signed in to change notification settings - Fork 1
131 lines (115 loc) · 4 KB
/
build-backend.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
122
123
124
125
126
127
128
129
130
131
name: Django CI
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
env:
PYTHON_VERSION: "3.11"
POETRY_VERSION: "1.7.1" # Remember to also update in pyproject.toml
IMAGE_NAME: unicorn-backend
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Pre-Commit
run: python -m pip install pre-commit && pre-commit install
- name: Load cached Pre-Commit Dependencies
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pre-commit/
key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: Execute Pre-Commit
run: pre-commit run --show-diff-on-failure --color=always --all-files
test:
runs-on: ubuntu-latest
env:
SECRET_KEY: insecure-key-eSlYXB1jtPbe2ryD283vSJtpb0TQhJrV
REDIS_CONNECTION: redis://cache:6379/1
DATABASE_USER: unicorn
DATABASE_NAME: unicorn
DATABASE_PASSWORD: insecure-password-0sy3wBnJs.#%@h2TrDsy?I*p#wU+MV
POSTGRES_USER: postgres
POSTGRES_PASSWORD: insecure-password-1KUkde2hxN4d3AvxhDsOkdsQTh4LE53c
services:
db:
image: postgres:15
env:
POSTGRES_USER: ${{ env.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
DATABASE_USER: ${{ env.DATABASE_USER }}
DATABASE_NAME: ${{ env.DATABASE_NAME }}
DATABASE_PASSWORD: ${{ env.DATABASE_PASSWORD }}
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
--name test_db
ports:
- 5432:5432
cache:
image: redis:alpine
ports:
- 6379:6379
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Run database initialization script
run: docker exec -i test_db /bin/bash < scripts/dbinit/initialize-database.sh
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: ${{ env.POETRY_VERSION }}
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: v1-venv-${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: poetry install --no-interaction --no-root
- name: Set pythonpath
run: echo "PYTHONPATH=$PWD" >> $GITHUB_ENV
- name: Test
run: DATABASE_HOST=localhost poetry run python unicorn/manage.py test unicorn
build:
needs: [validate, test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build image
run: docker build . -f Dockerfile --tag image
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository }}/$IMAGE_NAME
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "main" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag image $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION