-
Notifications
You must be signed in to change notification settings - Fork 6
114 lines (103 loc) · 3.42 KB
/
build-push-agents-images.yaml
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
name: Build and push agents images
on:
push: {}
workflow_dispatch: {}
workflow_call: {}
jobs:
generate-matrix:
name: Generate build matrix
runs-on: ubuntu-22.04
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v3
with:
repository: diambra/agents
fetch-depth: 0
- id: set-matrix
run: echo "::set-output name=matrix::$(./.github/workflows/generate-image-build-matrix basic/* *)"
checkout_and_download_lfs:
name: Checkout and Download LFS
runs-on: ubuntu-22.04
steps:
- name: Checkout selected branch
uses: actions/checkout@v3
with:
repository: diambra/agents
lfs: true
- name: Store repo with LFS files as artifacts
uses: actions/upload-artifact@v3
with:
name: repo-lfs-artifacts
path: . # You can specify the path to the LFS files if they are in a specific directory
build-and-push-images:
needs: [generate-matrix, checkout_and_download_lfs]
runs-on: ubuntu-latest
if: ${{ needs.generate-matrix.outputs.matrix != '[]' }}
strategy:
fail-fast: true
matrix:
include: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
steps:
- name: Restore repo with LFS files from artifacts
uses: actions/download-artifact@v3
with:
name: repo-lfs-artifacts
- name: Login to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
registry: docker.io
username: diambrabot
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to Quay
uses: docker/login-action@v2
with:
registry: quay.io
username: diambra+github
password: ${{ secrets.QUAY_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/diambra/agent-${{ matrix.name }}
docker.io/diambra/agent-${{ matrix.name }}
quay.io/diambra/agent-${{ matrix.name }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable={{is_default_branch}}
- name: Find base tag
id: base-tag
run: |
ref=${{ steps.meta.outputs.version }}
# on release-* branches, use branch as base tag
if [[ $ref == release-* ]]; then
echo "tag=$ref" >> "$GITHUB_OUTPUT"
exit 0
fi
# on any other branch, use main as base tag
if [[ ! $ref =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
echo "tag=main" >> "$GITHUB_OUTPUT"
exit 0
fi
major=${ref%%.*}
minor_and_patch=${ref#*.}
minor=${minor_and_patch%%.*}
echo "tag=v${major}.${minor}" >> "$GITHUB_OUTPUT"
- name: Build and push agent ${{ matrix.dir }}
uses: docker/build-push-action@v3
with:
context: ${{ matrix.dir }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
TAG=${{ steps.base-tag.outputs.tag }}