-
Notifications
You must be signed in to change notification settings - Fork 0
67 lines (65 loc) · 2.18 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
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-image:
runs-on: ubuntu-latest
needs: prepare
strategy:
matrix:
manifest: ${{ fromJson(needs.prepare.outputs.matrix) }}
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: read -ra strarr <<<"${{ matrix.manifest }}" && echo "folder=$($strarr[1])" >> $GITHUB_OUTPUT
env:
IFS: "/"
id: extract_folder
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
ghcr.io/${{ needs.prepare.outputs.repository }}/${{steps.extract_folder.outputs.folder}}:${{ needs.prepare.outputs.branch }}