-
Notifications
You must be signed in to change notification settings - Fork 182
132 lines (119 loc) · 4.29 KB
/
seed-dockers.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
131
132
name: Build seed containers
on:
push:
branches:
- main
- dsinghvi/fix-ir-jsons
workflow_dispatch:
# Cancel previous workflows on previous push
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
DOCKER_BUILDKIT: 1
jobs:
changes:
runs-on: ubuntu-latest
outputs:
packages: ${{ steps.filter.outputs.changes }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
ts:
- 'docker/seed/Dockerfile.ts'
- '.github/workflows/seed-dockers.yml'
java:
- 'docker/seed/Dockerfile.java'
- '.github/workflows/seed-dockers.yml'
python:
- 'docker/seed/Dockerfile.python'
- '.github/workflows/seed-dockers.yml'
csharp:
- 'docker/seed/Dockerfile.csharp'
- '.github/workflows/seed-dockers.yml'
generate-sha:
runs-on: ubuntu-latest
outputs:
sha: ${{ steps.sha.outputs.sha }}
steps:
- uses: actions/checkout@v4
- id: sha
run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
build-container:
if: ${{ needs.changes.outputs.packages != '' && toJSON(fromJSON(needs.changes.outputs.packages)) != '[]' }}
strategy:
matrix:
# Parse JSON array containing names of all filters matching any of changed files
# e.g. ['package1', 'package2'] if both package folders contains changes
package: ${{ fromJSON(needs.changes.outputs.packages) }}
runner: [ubuntu-latest, ubuntu-24.04-arm]
arch: [amd64, arm64]
exclude:
# Avoid building arm64 on amd64 runner and vice versa
- runner: ubuntu-latest
arch: arm64
- runner: ubuntu-24.04-arm
arch: amd64
runs-on: ${{ matrix.runner }}
needs: [changes, generate-sha]
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: fernapi/${{ matrix.package }}-seed
tags: |
type=raw,value=${{ needs.generate-sha.outputs.sha }}-${{ matrix.arch }}
type=raw,value=latest-${{ matrix.arch }}
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: fernapi
password: ${{ secrets.FERN_API_DOCKERHUB_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/seed/Dockerfile.${{ matrix.package }}
platforms: linux/${{ matrix.arch }}
cache-from: type=gha
cache-to: type=gha,mode=min
push: true
# use short SHA if modded, or just use latest if nothing changed
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
outputs:
image_sha: ${{ steps.meta.outputs.version }} # This gets the SHA tag
merge-manifests:
if: ${{ needs.changes.outputs.packages != '' && toJSON(fromJSON(needs.changes.outputs.packages)) != '[]' }}
needs: [changes, build-container, generate-sha]
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: fernapi
password: ${{ secrets.FERN_API_DOCKERHUB_PASSWORD }}
- name: Create and push manifest
run: |
packages='${{ needs.changes.outputs.packages }}'
sha='${{ needs.generate-sha.outputs.sha }}'
for package in $(echo "$packages" | jq -r '.[]'); do
docker buildx imagetools create -t fernapi/${package}-seed:latest \
fernapi/${package}-seed:latest-amd64 \
fernapi/${package}-seed:latest-arm64
docker buildx imagetools create -t fernapi/${package}-seed:${sha} \
fernapi/${package}-seed:${sha}-amd64 \
fernapi/${package}-seed:${sha}-arm64
done