-
Notifications
You must be signed in to change notification settings - Fork 40
171 lines (168 loc) · 5.54 KB
/
ci.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
name: Build, Test & Deploy
"on":
pull_request:
push:
branches:
- master
tags:
- "v*"
workflow_dispatch:
inputs:
pytest_addopts:
description:
Extra options for pytest; use -vv for full details; see
https://docs.pytest.org/en/latest/example/simple.html#how-to-change-command-line-options-defaults
required: false
env:
LANG: "en_US.utf-8"
LC_ALL: "en_US.utf-8"
PIP_CACHE_DIR: ${{ github.workspace }}/.cache.~/pip
PIPX_HOME: ${{ github.workspace }}/.cache.~/pipx
POETRY_CACHE_DIR: ${{ github.workspace }}/.cache.~/pypoetry
POETRY_VIRTUALENVS_IN_PROJECT: "true"
PYTEST_ADDOPTS: ${{ github.event.inputs.pytest_addopts }}
PYTHONIOENCODING: "UTF-8"
jobs:
build-test:
runs-on: ubuntu-20.04
strategy:
matrix:
python:
- 3.9
steps:
# Prepare environment
- uses: actions/checkout@v3
# Set up and run tests
- name: Install python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Generate cache key CACHE
run:
echo "CACHE=${{ secrets.CACHE_DATE }} ${{ runner.os }} $(python -VV |
sha256sum | cut -d' ' -f1) ${{ hashFiles('pyproject.toml') }} ${{
hashFiles('poetry.lock') }}" >> $GITHUB_ENV
- uses: actions/cache@v3
with:
path: |
.cache.~
.venv
~/.local/bin
key: venv ${{ env.CACHE }}
- run: pip install poetry
- name: Patch $PATH
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
- run: poetry run python -m pip install --upgrade pip
- run: poetry install
# Run tests
- run: poetry run pytest --prebuild
build-push:
runs-on: ubuntu-20.04
services:
registry:
image: registry:2
ports:
- 5000:5000
env:
DOCKER_IMAGE_NAME: ${{ github.repository }}
PUSH: ${{ toJSON(github.event_name != 'pull_request') }}
strategy:
matrix:
target:
- base
- docker
- docker-s3
- postgres
- postgres-s3
- postgres-multi
- s3
steps:
# Set up Docker Environment
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
/tmp/.buildx-cache
key: buildx|${{ secrets.CACHE_DATE }}|${{ runner.os }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host
install: true
# Build and push
- name: Compute image name
id: image_name_compute
run: |
if [ "${{ matrix.target }}" = "base" ]; then
echo "::set-output name=image_name::${{ env.DOCKER_IMAGE_NAME }}"
else
echo "::set-output name=image_name::${{ env.DOCKER_IMAGE_NAME }}-${{ matrix.target }}"
fi
- name: Docker meta for local images
id: docker_meta_local
uses: docker/metadata-action@v4
with:
images: localhost:5000/${{ steps.image_name_compute.outputs.image_name }}
tags: |
type=edge
type=semver,pattern={{version}},enable=true
type=schedule,pattern=nightly,enable=true,priority=1000
type=ref,event=branch,enable=true,priority=600
type=ref,event=tag,enable=true,priority=600
type=ref,event=pr,prefix=pr-,enable=true,priority=600
- name: Build and push to local (test) registry
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
platforms: |
linux/amd64
linux/arm64/v8
load: false
push: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
labels: ${{ steps.docker_meta_local.outputs.labels }}
tags: ${{ steps.docker_meta_local.outputs.tags }}
target: ${{ matrix.target }}
# Next jobs only happen outside of pull requests and on main branches
- name: Login to GitHub Container Registry
if: ${{ fromJSON(env.PUSH) }}
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ secrets.BOT_LOGIN }}
password: ${{ secrets.BOT_TOKEN }}
- name: Docker meta for public images
if: ${{ fromJSON(env.PUSH) }}
id: docker_meta_public
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/${{ steps.image_name_compute.outputs.image_name }}
tags: |
type=edge
type=semver,pattern={{version}}
type=schedule,pattern=nightly,enable=true,priority=1000
type=ref,event=branch,enable=true,priority=600
type=ref,event=tag,enable=true,priority=600
type=ref,event=pr,prefix=pr-,enable=true,priority=600
- name: Build and push to public registry(s)
if: ${{ fromJSON(env.PUSH) }}
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
platforms: |
linux/amd64
linux/arm64/v8
load: false
push: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
labels: ${{ steps.docker_meta_public.outputs.labels }}
tags: ${{ steps.docker_meta_public.outputs.tags }}
target: ${{ matrix.target }}