-
Notifications
You must be signed in to change notification settings - Fork 1
147 lines (128 loc) · 4.41 KB
/
build.yml
File metadata and controls
147 lines (128 loc) · 4.41 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: Build Docker Image
on:
push:
branches: ["**"]
jobs:
build-amd64:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: audius/api
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }},suffix=-amd64
type=sha,prefix=,suffix=-amd64
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=audius/api:buildcache-amd64
cache-to: type=registry,ref=audius/api:buildcache-amd64,mode=max
build-args: |
GIT_SHA=${{ github.sha }}
platforms: linux/amd64
build-arm64:
runs-on: ubuntu-24.04-arm
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: audius/api
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }},suffix=-arm64
type=sha,prefix=,suffix=-arm64
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=audius/api:buildcache-arm64
cache-to: type=registry,ref=audius/api:buildcache-arm64,mode=max
build-args: |
GIT_SHA=${{ github.sha }}
platforms: linux/arm64
push-manifest:
runs-on: ubuntu-latest
permissions:
contents: write
needs: [build-amd64, build-arm64]
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: audius/api
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=sha,prefix=
- name: Extract arch builds metadata for Docker
id: arch-meta
uses: docker/metadata-action@v5
with:
images: audius/api
tags: |
type=sha,prefix=,suffix=-amd64
type=sha,prefix=,suffix=-arm64
- name: Create and push Docker manifest
run: |
OUTPUT_TAGS="$(echo "${{ steps.meta.outputs.tags }}" | tr '\n' ' ')"
INPUT_TAGS="$(echo "${{ steps.arch-meta.outputs.tags }}" | tr '\n' ' ')"
TAG_ARGS=""
for tag in $OUTPUT_TAGS; do
TAG_ARGS="$TAG_ARGS --tag $tag"
done
echo "docker buildx imagetools create $TAG_ARGS $INPUT_TAGS"
docker buildx imagetools create $TAG_ARGS $INPUT_TAGS
- name: Checkout code
uses: actions/checkout@v4
- name: Get short SHA for release
if: github.ref == 'refs/heads/main'
run: |
echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Create GitHub Release
if: github.ref == 'refs/heads/main'
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.SHORT_SHA }}
name: "Build ${{ env.SHORT_SHA }}"
body: "Automated release generated after Docker image push."
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}