-
Notifications
You must be signed in to change notification settings - Fork 2
124 lines (106 loc) · 4.17 KB
/
docker-publish.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
name: Publish on Github container registry
on:
release:
type: [published]
push:
branches: [main]
pull_request:
paths:
- 'pyproject.toml'
- './docker/**'
- '.github/workflows/**'
env:
REGISTRY: ghcr.io
jobs:
build-image:
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/main'
permissions:
contents: read
packages: write
steps:
# https://github.com/actions/checkout
- name: checkout repository
uses: actions/checkout@v4
- name: lowercase image name
run: |
echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}
# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/[email protected]
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
id: buildx
uses: docker/[email protected]
- name: Get current release version
id: release-version
run: |
version=$(grep -E '^version += +' pyproject.toml | sed -E 's/.*= +//' | sed "s/['\"]//g")
echo "version=${version}" >> $GITHUB_OUTPUT
echo "version_build=${version}_"$(git rev-parse --short "$GITHUB_SHA") >> $GITHUB_OUTPUT
# https://github.com/docker/build-push-action
- name: Build Docker image
uses: docker/[email protected]
with:
context: .
platforms: linux/amd64,linux/arm64
file: .docker/Dockerfile
push: false
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.release-version.outputs.version_build }}
build-args: VERSION_BUILD=${{ steps.release-version.outputs.version_build }}
outputs: type=image,annotation-index.org.opencontainers.image.description=Extract linked metadata from repositories.
push-image:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
permissions:
contents: read
packages: write
steps:
# https://github.com/actions/checkout
- name: checkout repository
uses: actions/checkout@v4
- name: lowercase image name
run: |
echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}
# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/[email protected]
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
id: buildx
uses: docker/[email protected]
- name: Get current release version
id: release-version
run: |
version=$(grep -E '^version += +' pyproject.toml | sed -E 's/.*= +//' | sed "s/['\"]//g")
echo "version=${version}" >> $GITHUB_OUTPUT
echo "version_build=${version}_"$(git rev-parse --short "$GITHUB_SHA") >> $GITHUB_OUTPUT
# https://github.com/docker/login-action
- name: Log in to the Container registry
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# https://github.com/docker/metadata-action
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/[email protected]
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ github.event_name == 'push' }}
type=raw,value=${{ needs.build-image.outputs.version_build }},enable=${{ github.event_name == 'push' }}
type=raw,value=${{ needs.build-image.outputs.version }},enable=${{ github.event_name == 'release' }}
# https://github.com/docker/build-push-action
- name: Push Docker image
uses: docker/[email protected]
with:
context: .
platforms: linux/amd64,linux/arm64
file: .docker/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: VERSION_BUILD=${{ needs.build-image.outputs.version_build }}
outputs: type=image,annotation-index.org.opencontainers.image.description=Extract linked metadata from repositories.