-
-
Notifications
You must be signed in to change notification settings - Fork 1
111 lines (99 loc) · 3.55 KB
/
build-image.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
---
on: # yamllint disable-line rule:truthy
workflow_call:
inputs:
os:
description: The operating system to run the workflow on
required: false
type: string
default: ubuntu-latest
push-to-hub:
description: Push the image to Docker Hub
required: false
type: boolean
default: false
image-namespace:
description: 'The namespace of the image, example: wayofdev/php-base'
required: true
type: string
image-template-path:
description: 'The path to the template of the image, example: ./dist/base'
required: true
type: string
image-template:
description: 'The template of the image, example: 8.2-fpm-alpine'
required: true
type: string
image-version:
description: 'The version of the image, example: latest'
required: true
type: string
image-platform:
description: The platform of the image
required: false
type: string
default: linux/amd64,linux/arm64
secrets:
docker-username:
description: Docker Hub username
required: true
docker-password:
description: Docker Hub password
required: true
name: 🚀 Build docker images
jobs:
build:
runs-on: ${{ inputs.os }}
steps:
- name: 📦 Check out the codebase
uses: actions/[email protected]
- name: 🛠️ Install goss and dgoss
uses: e1himself/[email protected]
with:
version: v0.4.6
- name: 🤖 Generate dist files
run: make generate
- name: 🐳 Extract docker meta data
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ inputs.image-namespace }}
tags: |
type=raw,event=branch,value=latest
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
flavor: |
latest=false
prefix=${{ inputs.image-template }}-
- name: 🔑 Login to docker-hub
uses: docker/login-action@v3
with:
username: ${{ secrets.docker-username }}
password: ${{ secrets.docker-password }}
- name: 🖥️ Setup QEMU for "${{ inputs.image-platform }}"
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ inputs.image-platform }}
- name: 🛠️ Setup docker BuildX for "${{ inputs.image-platform }}"
uses: docker/setup-buildx-action@v3
with:
install: true
platforms: ${{ inputs.image-platform }}
- name: 🚀 Build image and push to docker-hub for "${{ inputs.image-platform }}"
uses: docker/build-push-action@v6
with:
context: '${{ inputs.image-template-path }}/${{ inputs.image-template }}'
platforms: ${{ inputs.image-platform }}
push: ${{ inputs.push-to-hub == true }}
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=registry,ref=${{ inputs.image-namespace }}:${{ inputs.image-template }}-cache
cache-to: type=registry,ref=${{ inputs.image-namespace }}:${{ inputs.image-template }}-cache,mode=max
labels: ${{ steps.meta.outputs.labels }}
- name: 🧪 Test Docker image
if: ${{ inputs.image-platform == 'linux/amd64' }}
run: |
export IMAGE_TEMPLATE=${{ inputs.image-template }}
export IMAGE_TAG=${{ inputs.image-namespace }}:${{ inputs.image-template }}-${{ inputs.image-version }}
make test
...