-
Notifications
You must be signed in to change notification settings - Fork 13
140 lines (124 loc) · 4.44 KB
/
docker.yml
File metadata and controls
140 lines (124 loc) · 4.44 KB
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
name: Build and Push Docker Images
on:
workflow_dispatch:
push:
branches: [main]
pull_request:
branches: [main]
release:
types: [released]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
packages: write
jobs:
configure:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.get-versions.outputs.result }}
steps:
- name: Checkout to repository
uses: actions/checkout@v6
- name: Get dependency versions
uses: mikefarah/yq@v4.52.4
id: get-versions
with:
cmd: yq eval -o=json -I=0 versions.yaml
build_and_push:
runs-on: ubuntu-latest
needs: configure
strategy:
# Prevent a failure in one image from stopping the other builds
fail-fast: false
matrix: ${{ fromJson(needs.configure.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v4.0.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.12.0
- name: Login to GitHub Container Registry
uses: docker/login-action@v4.0.0
if: ${{ !github.event.pull_request.head.repo.fork }}
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker Hub
uses: docker/login-action@v4
if: ${{ !github.event.pull_request.head.repo.fork }}
with:
username: ${{ secrets.DOCKERIO_USERNAME }}
password: ${{ secrets.DOCKERIO_TOKEN }}
- name: Determine version change
id: changed-version
run: |
BASE=${{ github.event_name == 'pull_request' && format('origin/{0}', github.base_ref) || 'HEAD~1' }}
CHANGED_FILES=$(git diff --name-only $BASE...HEAD)
echo $CHANGED_FILES
# Looking for:
# versions.yaml
# Dockerfile
if echo "$CHANGED_FILES" | grep -q -e "^versions.yaml$" -e "^Dockerfile$"; then
echo "any_changed=true" >> $GITHUB_OUTPUT
else
echo "any_changed=false" >> $GITHUB_OUTPUT
fi
- name: Determine image push
uses: actions/github-script@v8
id: should-release
with:
script: |
if (context.eventName == "pull_request") return false;
if (context.eventName == "workflow_dispatch") return true;
return "${{ steps.changed-version.outputs.any_changed }}" == "true";
- name: Set major postgres version
id: version
run: |
pg_major=$(echo ${{ matrix.cnpg }} | cut -d'.' -f1)
echo "pg_major=$pg_major" >> "$GITHUB_OUTPUT"
- name: Generate docker image tags
id: metadata
uses: docker/metadata-action@v5
with:
flavor: |
# Disable latest tag
latest=false
images: |
name=ghcr.io/${{ github.repository }}
name=tensorchord/cloudnative-vectorchord
tags: |
type=raw,value=${{ matrix.cnpg }}-${{ matrix.vectorchord }},enable=${{ steps.should-release.outputs.result }}
type=raw,value=${{ steps.version.outputs.pg_major }}-${{ matrix.vectorchord }},enable=${{ steps.should-release.outputs.result }}
type=raw,value=${{ matrix.cnpg }},enable=${{ steps.should-release.outputs.result }}
type=raw,value=${{ steps.version.outputs.pg_major }},enable=${{ steps.should-release.outputs.result }}
- name: Build and push image
uses: docker/build-push-action@v6.19.2
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ !github.event.pull_request.head.repo.fork && steps.metadata.outputs.tags != '' }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
build-args: |
CNPG_TAG=${{ matrix.cnpg }}
VECTORCHORD_TAG=${{ matrix.vectorchord }}
results:
if: ${{ always() }}
runs-on: ubuntu-latest
name: Build results
needs: [build_and_push]
steps:
- run: |
result="${{ needs.build_and_push.result }}"
if [[ $result == "success" || $result == "skipped" ]]; then
exit 0
else
exit 1
fi