-
Notifications
You must be signed in to change notification settings - Fork 2
135 lines (125 loc) · 3.99 KB
/
docker_build.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
name: Workflow to build Docker image
on:
workflow_call:
outputs:
docker_tags:
description: "docker image full name"
value: ${{ jobs.build.outputs.docker_tags }}
runner:
description: "build runner name"
value: ${{ jobs.build.outputs.runner }}
inputs:
project:
required: true
type: string
component:
# not required now
required: false
type: string
node_env:
required: false
type: string
default: "production"
load:
required: false
type: boolean
default: true
push:
required: false
type: boolean
default: true
docker_context:
description: "the path where docker build execute."
required: false
default: "./"
type: string
docker_file:
description: "the Dockerfile to build"
required: false
default: "./Dockerfile"
type: string
runner:
## ['cn', 'us', 'cn1', 'cn2', 'cn3', 'us1', 'us2', 'us3']
type: string
default: "cn"
required: false
secrets:
REGISTRY_USERNAME:
required: true
REGISTRY_PASSWORD:
required: true
NPM_TOKEN:
required: false
jobs:
build:
name: build docker image
runs-on: ${{ inputs.runner }}
timeout-minutes: 20
env:
COMPONENT_NAME: "${{ inputs.component || github.event.repository.name }}"
REGISTRY: "registry.wiredcraft.cn"
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: "0"
# Add support for more platforms with QEMU (optional)
# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ inputs.project }}/${{ env.COMPONENT_NAME }}
tags: |
type=ref,event=pr
type=ref,event=branch
type=ref,event=tag
- name: Login to PrivateRegistry
# https://github.com/actions/runner/issues/1483
if: ${{ inputs.push }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD}}
- name: Load to local registry
uses: docker/build-push-action@v5
if: ${{ inputs.load }}
with:
context: ${{ inputs.docker_context }}
file: ${{ inputs.docker_file }}
builder: ${{ steps.buildx.outputs.name }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
load: ${{ inputs.load }}
build-args: |
OMNI_COMPONENT=${{ env.COMPONENT_NAME }}
NODE_ENV=${{ inputs.node_env }}
NPM_TOKEN=${{ secrets.NPM_TOKEN }}
OMNI_COMPONENT_COMMIT=${{ github.sha }}
OMNI_COMPONENT_VERSION=${{ steps.meta.outputs.version }}
- name: Build
uses: docker/build-push-action@v5
with:
context: ${{ inputs.docker_context }}
file: ${{ inputs.docker_file }}
builder: ${{ steps.buildx.outputs.name }}
push: ${{ inputs.push }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
OMNI_COMPONENT=${{ env.COMPONENT_NAME }}
NODE_ENV=${{ inputs.node_env }}
NPM_TOKEN=${{ secrets.NPM_TOKEN }}
OMNI_COMPONENT_COMMIT=${{ github.sha }}
OMNI_COMPONENT_VERSION=${{ steps.meta.outputs.version }}
outputs:
docker_tags: ${{ steps.meta.outputs.tags }}
runner: ${{ runner.name }}