-
Notifications
You must be signed in to change notification settings - Fork 39
130 lines (111 loc) · 3.66 KB
/
build.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
name: TradingBot CI
on:
push:
branches:
- master # Prevent building other branches to speed up PRs
pull_request:
branches:
- master
schedule:
- cron: '0 0 * * *' # nightly build
env:
poetry-version: '1.2.2'
docker-image-name: ilcardella/tradingbot
push-docker-image: ${{ startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master' }}
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10']
name: Python ${{ matrix.python-version }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- name: Pip cache
uses: actions/cache@v3
with:
# This path is specific to Ubuntu
path: ~/.cache/pip
# Look to see if there is a cache hit for the corresponding poetry.lock
key: ${{ runner.os }}-pip-${{ env.poetry-version }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install 'poetry==${{ env.poetry-version }}'
- name: Poetry cache
uses: actions/cache@v3
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-
- name: Run tests
run: make ci
docker:
needs: build
runs-on: ubuntu-latest
name: Docker build and push
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Prepare
id: prepare
run: |
DOCKER_IMAGE=${{ env.docker-image-name }}
VERSION=latest
PLATFORMS=linux/amd64,linux/arm64
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
elif [[ $GITHUB_REF != refs/heads/master ]]; then
VERSION=${GITHUB_REF#refs/heads/}
VERSION=${VERSION##*/}
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:latest"
fi
echo ::set-output name=platforms::${PLATFORMS}
echo ::set-output name=tags::${TAGS}
- name: Set up QEMU
uses: docker/setup-qemu-action@master
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@master
- name: Cache Docker layers
uses: actions/cache@v3
id: cache
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
if: ${{ env.push-docker-image }}
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v3
with:
context: .
file: docker/Dockerfile
platforms: ${{ steps.prepare.outputs.platforms }}
build-args: POETRY_VERSION=${{ env.poetry-version }}
push: ${{ env.push-docker-image }}
tags: ${{ steps.prepare.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Clear
if: always()
run: |
rm -f ${HOME}/.docker/config.json