forked from mindee/doctr
-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (78 loc) · 2.98 KB
/
public_docker_images.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
# https://docs.github.com/en/actions/publishing-packages/publishing-docker-images#publishing-images-to-github-packages
#
name: Docker image on ghcr.io
on:
push:
tags:
- 'v*'
pull_request:
branches: main
schedule:
- cron: '0 2 29 * *' # At 02:00 on day-of-month 29
env:
REGISTRY: ghcr.io
jobs:
build-and-push-image:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# Must match version at https://www.python.org/ftp/python/
python: ["3.10.13", "3.11.8", "3.12.7"]
framework: ["tf", "torch", "tf,viz,html,contrib", "torch,viz,html,contrib"]
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Sanitize docker tag
run: |
PREFIX_DOCKER_TAG="${{ matrix.framework }}-py${{ matrix.python }}-"
PREFIX_DOCKER_TAG=$(echo ${PREFIX_DOCKER_TAG}|sed 's/,/-/g')
echo PREFIX_DOCKER_TAG=${PREFIX_DOCKER_TAG} >> $GITHUB_ENV
echo $PREFIX_DOCKER_TAG
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ github.repository }}
tags: |
# used only on schedule event
type=schedule,pattern={{date 'YYYY-MM'}},prefix=${{ env.PREFIX_DOCKER_TAG }}
# used only if a tag following semver is published
type=semver,pattern={{raw}},prefix=${{ env.PREFIX_DOCKER_TAG }}
- name: Build Docker image
id: build
uses: docker/build-push-action@v6
with:
context: .
build-args: |
FRAMEWORK=${{ matrix.framework }}
PYTHON_VERSION=${{ matrix.python }}
DOCTR_REPO=${{ github.repository }}
DOCTR_VERSION=${{ github.sha }}
push: false # push only if `import doctr` works
tags: ${{ steps.meta.outputs.tags }}
- name: Check if `import doctr` works
run: docker run ${{ steps.build.outputs.imageid }} python3 -c 'import doctr'
- name: Push Docker image
# Push only if the CI is not triggered by "PR on main"
if: ${{ (github.ref == 'refs/heads/main' && github.event_name != 'pull_request') || (startsWith(github.ref, 'refs/tags') && github.event_name == 'push') }}
uses: docker/build-push-action@v6
with:
context: .
build-args: |
FRAMEWORK=${{ matrix.framework }}
PYTHON_VERSION=${{ matrix.python }}
DOCTR_REPO=${{ github.repository }}
DOCTR_VERSION=${{ github.sha }}
push: true
tags: ${{ steps.meta.outputs.tags }}