Repository navigation
147 lines (125 loc) · 4.21 KB
/
Copy pathdocker.yml
File metadata and controls
147 lines (125 loc) · 4.21 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
141
142
143
144
145
146
147
name: Docker
on:
workflow_dispatch:
workflow_run:
workflows: ["Publish to PyPI"]
types: [completed]
permissions:
contents: read
concurrency:
group: docker-publish
cancel-in-progress: false
env:
IMAGE: sidequery/sqlctx
jobs:
source:
name: Resolve source and version
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
outputs:
sha: ${{ steps.source.outputs.sha }}
version: ${{ steps.source.outputs.version }}
steps:
# Publish to PyPI commits the version bump to main, so build main rather
# than the commit that triggered the publish run.
- uses: actions/checkout@v4
with:
ref: main
- name: Resolve commit and version
id: source
run: |
VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
SHA=$(git rev-parse HEAD)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "sha=$SHA" >> "$GITHUB_OUTPUT"
echo "Building $VERSION from $SHA"
build:
name: Build and test (${{ matrix.platform }})
needs: source
# Native runners per architecture: riffq builds from source with Rust, which
# is impractically slow under QEMU emulation.
runs-on: ${{ matrix.runner }}
strategy:
matrix:
include:
- platform: linux/amd64
arch: amd64
runner: ubuntu-24.04
- platform: linux/arm64
arch: arm64
runner: ubuntu-24.04-arm
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.source.outputs.sha }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build image
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ matrix.platform }}
load: true
tags: ${{ env.IMAGE }}:test
cache-from: type=gha,scope=docker-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=docker-${{ matrix.arch }}
- name: Smoke test API, MCP, and PostgreSQL modes
run: python3 scripts/docker_smoke_test.py "$IMAGE:test"
- name: Push image by digest
id: push
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ matrix.platform }}
outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha,scope=docker-${{ matrix.arch }}
- name: Export digest
env:
DIGEST: ${{ steps.push.outputs.digest }}
run: |
mkdir -p "$RUNNER_TEMP/digests"
touch "$RUNNER_TEMP/digests/${DIGEST#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ matrix.arch }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1
publish:
name: Publish multi-arch image
needs: [source, build]
runs-on: ubuntu-latest
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}/digests
pattern: digests-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push manifest list
working-directory: ${{ runner.temp }}/digests
env:
VERSION: ${{ needs.source.outputs.version }}
run: |
refs=()
for digest in *; do
refs+=("$IMAGE@sha256:$digest")
done
docker buildx imagetools create --tag "$IMAGE:latest" --tag "$IMAGE:$VERSION" "${refs[@]}"
- name: Inspect image
env:
VERSION: ${{ needs.source.outputs.version }}
run: docker buildx imagetools inspect "$IMAGE:$VERSION"