-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (149 loc) · 4.85 KB
/
build-docker.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
148
149
150
151
name: Build docker image
on:
push:
branches: ["main"]
pull_request:
# The branches below must be a subset of the branches above
branches: ["main"]
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.finding-files.outputs.FILELIST }}
branch: ${{ steps.extract_branch.outputs.branch }}
repository: ${{ steps.extract_repo.outputs.repository }}
steps:
- uses: actions/checkout@v4
- name: Finding files and store to output
id: finding-files
run: |
echo "FILELIST=$(find . -name 'Containerfile' -print | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
- name: Show files
run: echo "${{ steps.finding-files.outputs.FILELIST }}"
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Extract repo name
shell: bash
run: echo "repository=${GITHUB_REPOSITORY@L}" >> $GITHUB_OUTPUT
id: extract_repo
build-min:
runs-on: ubuntu-latest
needs:
- prepare
strategy:
matrix:
manifest:
- ./che-min/Containerfile
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Setup Go environment
uses: actions/[email protected]
- name: Run prepare
run: |
cd src-template
go run main.go
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract folder name
shell: bash
run: IFS="/" read -ra strarr <<<"${{ matrix.manifest }}" && echo "folder=${strarr[1]}" >> $GITHUB_OUTPUT
id: extract_folder
- name: Build and push
uses: docker/build-push-action@v5
with:
context: ${{steps.extract_folder.outputs.folder}}
file: ${{ matrix.manifest}}
push: true
tags: |
ghcr.io/${{ needs.prepare.outputs.repository }}/${{steps.extract_folder.outputs.folder}}:${{ needs.prepare.outputs.branch }}
build-base:
runs-on: ubuntu-latest
needs:
- prepare
- build-min
strategy:
matrix:
manifest:
- ./che-base/Containerfile
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Setup Go environment
uses: actions/[email protected]
- name: Run prepare
run: |
cd src-template
go run main.go
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract folder name
shell: bash
run: IFS="/" read -ra strarr <<<"${{ matrix.manifest }}" && echo "folder=${strarr[1]}" >> $GITHUB_OUTPUT
id: extract_folder
- name: Build and push
uses: docker/build-push-action@v5
with:
context: ${{steps.extract_folder.outputs.folder}}
file: ${{ matrix.manifest}}
push: true
tags: |
ghcr.io/${{ needs.prepare.outputs.repository }}/${{steps.extract_folder.outputs.folder}}:${{ needs.prepare.outputs.branch }}
build-image:
runs-on: ubuntu-latest
needs:
- prepare
- build-min
- build-base
strategy:
matrix:
manifest: ${{ fromJson(needs.prepare.outputs.matrix) }}
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Setup Go environment
uses: actions/[email protected]
- name: Run prepare
run: |
cd src-template
go run main.go
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract folder name
shell: bash
run: IFS="/" read -ra strarr <<<"${{ matrix.manifest }}" && echo "folder=${strarr[1]}" >> $GITHUB_OUTPUT
id: extract_folder
- name: Build and push
uses: docker/build-push-action@v5
with:
context: ${{steps.extract_folder.outputs.folder}}
file: ${{ matrix.manifest}}
push: true
tags: |
ghcr.io/${{ needs.prepare.outputs.repository }}/${{steps.extract_folder.outputs.folder}}:${{ needs.prepare.outputs.branch }}