-
Notifications
You must be signed in to change notification settings - Fork 7
147 lines (131 loc) · 4.46 KB
/
ci.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: Build Docker Images
on:
push:
branches:
- master
- dev
- dev-pl
- dev-v2
- staging
paths-ignore:
- ".github/workflows/**"
- "examples/**"
- "proto/**"
- "tools/**/*.sh"
- "README.md"
- "traefik.yml"
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_TAG: ${{github.ref_name == 'master' && 'latest' || github.ref_name}}
jobs:
prepare:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set target tags
id: set-tags-matrix
run: |
TAGS_JSON=$(ls Dockerfiles | jq -cnR '[inputs | select(length>0)]')
echo "matrix=$TAGS_JSON" >> $GITHUB_OUTPUT
echo "### Discovered Containers :whale:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
for title in $(echo $TAGS_JSON | jq -r '.[]'); do
echo "* $title" | tr '-' ' ' >> $GITHUB_STEP_SUMMARY
done
echo "" >> $GITHUB_STEP_SUMMARY
echo "#### Raw" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```json' >> $GITHUB_STEP_SUMMARY
echo "$TAGS_JSON" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
outputs:
matrix: ${{ steps.set-tags-matrix.outputs.matrix }}
# wait-for-checks:
# runs-on: ubuntu-latest
# steps:
# - name: Wait for tests to succeed
# uses: lewagon/wait-on-check-action@v1.3.4
# with:
# ref: ${{ github.ref }}
# check-name: checks
# repo-token: ${{ secrets.GITHUB_TOKEN }}
# wait-interval: 10
build-and-push-base-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5.5.1
with:
tags: type=raw,value=${{env.IMAGE_TAG}}
images: ${{ env.REGISTRY }}/slntopp/nocloud/base
- name: Log in to the Container registry
uses: docker/login-action@v3.3.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v6.7.0
with:
context: .
file: Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-and-push:
runs-on: ubuntu-latest
needs: [prepare, build-and-push-base-image]
strategy:
matrix:
tag: ${{fromJson(needs.prepare.outputs.matrix)}}
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5.5.1
with:
tags: type=raw,value=${{env.IMAGE_TAG}}
images: ${{ env.REGISTRY }}/slntopp/nocloud/${{matrix.tag}}
- name: Log in to the Container registry
uses: docker/login-action@v3.3.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v6.7.0
id: build
with:
context: .
file: Dockerfiles/${{matrix.tag}}/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: IMAGE_TAG=${{env.IMAGE_TAG}}
- name: Summary
run: |
echo "### :whale: Published new image" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Digest:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "${{ steps.build.outputs.imageid }}" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo 'docker pull ${{ env.REGISTRY }}/slntopp/nocloud/${{matrix.tag}}:${{env.IMAGE_TAG}}' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "> Operator would automatically pull new image, otherwise use the command above" >> $GITHUB_STEP_SUMMARY