-
Notifications
You must be signed in to change notification settings - Fork 1
91 lines (79 loc) · 2.68 KB
/
container.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
name: Container
on:
push:
branches:
- main
tags:
- '@lagoss/serverless@*'
- '@lagoss/dashboard@*'
pull_request:
jobs:
define-matrix:
name: Define matrix
runs-on: ubuntu-latest
outputs:
images: ${{ steps.set-matrix.outputs.result }}
steps:
- name: Set matrix
uses: actions/github-script@v7
id: set-matrix
with:
script: |
const images = []
if (context.eventName === 'pull_request') {
images.push('serverless', 'dashboard')
}
if (context.eventName === 'push' && context.ref.startsWith('refs/tags/')) {
const match = context.ref.match(/@lagoss\/(\w+)@(\d+\.\d+\.\d+)/)
if (match) {
images.push(match[1])
}
}
console.log(images)
return images
create-container-image:
name: Create "${{matrix.image}}" container image
needs: define-matrix
runs-on: ubuntu-latest
if: ${{needs.define-matrix.outputs.images != '[]'}}
strategy:
matrix:
image: ${{fromJson(needs.define-matrix.outputs.images)}}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/${{ github.repository_owner }}/${{matrix.image}}
tags: |
type=match,pattern=@lagoss\/${{matrix.image}}@(\d+\.\d+\.\d+),enable=${{startsWith(github.ref, 'refs/tags/')}},group=1
type=ref,event=pr
# type=raw,value=next,enable={{is_default_branch}}
- name: Login to ghcr.io registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
if: "!startsWith(github.ref, 'refs/tags/') || contains(github.ref, matrix.image)"
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: docker/Dockerfile.${{matrix.image}}
platforms: ${{ github.event_name == 'pull_request' && 'linux/amd64' || 'linux/amd64,linux/arm64' }} # only build for amd64 on PRs to speed up CI job
cache-from: type=gha
cache-to: type=gha,mode=max