-
Notifications
You must be signed in to change notification settings - Fork 283
128 lines (112 loc) · 5.15 KB
/
build-push.yml
File metadata and controls
128 lines (112 loc) · 5.15 KB
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
name: Build and Push Daemon
on:
push:
branches:
- "main"
- "deploy/dev"
- "build/**"
pull_request:
branches:
- "main"
release:
types: [published]
concurrency:
group: build-push-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
DIFY_DAEMON_IMAGE_NAME: ${{ vars.DIFY_DAEMON_IMAGE_NAME || 'langgenius/dify-plugin-daemon' }}
jobs:
matrix_prepare:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set matrix
id: set-matrix
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
# Skip arm64 builds on PR
echo "matrix={\"include\":[{\"service_name\":\"build-serverless-daemon-amd64\",\"image_name_env\":\"DIFY_DAEMON_IMAGE_NAME\",\"platform\":\"linux/amd64\",\"scope\":\"serverless\"},{\"service_name\":\"build-local-daemon-amd64\",\"image_name_env\":\"DIFY_DAEMON_IMAGE_NAME\",\"platform\":\"linux/amd64\",\"scope\":\"local\"}]}" >> $GITHUB_OUTPUT
else
# Include all builds for other events
echo "matrix={\"include\":[{\"service_name\":\"build-serverless-daemon-amd64\",\"image_name_env\":\"DIFY_DAEMON_IMAGE_NAME\",\"platform\":\"linux/amd64\",\"scope\":\"serverless\"},{\"service_name\":\"build-serverless-daemon-arm64\",\"image_name_env\":\"DIFY_DAEMON_IMAGE_NAME\",\"platform\":\"linux/arm64\",\"scope\":\"serverless\"},{\"service_name\":\"build-local-daemon-amd64\",\"image_name_env\":\"DIFY_DAEMON_IMAGE_NAME\",\"platform\":\"linux/amd64\",\"scope\":\"local\"},{\"service_name\":\"build-local-daemon-arm64\",\"image_name_env\":\"DIFY_DAEMON_IMAGE_NAME\",\"platform\":\"linux/arm64\",\"scope\":\"local\"}]}" >> $GITHUB_OUTPUT
fi
build:
needs: matrix_prepare
runs-on: ${{ matrix.platform == 'linux/arm64' && 'arm64_runner' || 'ubuntu-latest' }}
if: github.repository == 'langgenius/dify-plugin-daemon'
strategy:
matrix: ${{ fromJson(needs.matrix_prepare.outputs.matrix) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
- name: Login to Docker Hub
uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
username: ${{ env.DOCKERHUB_USER }}
password: ${{ env.DOCKERHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DIFY_DAEMON_IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }}
type=ref,event=branch
type=sha,enable=true,priority=100,prefix=,suffix=,format=long
type=raw,value=${{ github.ref_name }},enable=${{ startsWith(github.ref, 'refs/tags/') }}
- name: Run Build Docker Image
run: docker build --build-arg PLATFORM=${{ matrix.scope }} --build-arg VERSION=${{ github.sha }} -t dify-plugin-daemon -f ./docker/${{ matrix.scope }}.dockerfile .
- name: Tag Docker Images
if: github.event_name != 'pull_request'
run: for tag in $(echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n');
do
docker tag dify-plugin-daemon "$tag-${{ matrix.scope }}-${{ env.PLATFORM_PAIR }}";
done
- name: Push Docker Image
if: github.event_name != 'pull_request'
run: for tag in $(echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n');
do
docker push $tag-${{ matrix.scope }}-${{ env.PLATFORM_PAIR }};
done
create-manifest:
if: github.event_name != 'pull_request'
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
scope: [serverless, local]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKERHUB_USER }}
password: ${{ env.DOCKERHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ vars.DIFY_DAEMON_IMAGE_NAME || 'langgenius/dify-plugin-daemon' }}
tags: |
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }}
type=ref,event=branch
type=sha,enable=true,priority=100,prefix=,suffix=,format=long
type=raw,value=${{ github.ref_name }},enable=${{ startsWith(github.ref, 'refs/tags/') }}
- name: Build Universal Docker Images
run: for tag in $(echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n');
do
docker manifest create $tag-${{ matrix.scope }} $tag-${{ matrix.scope }}-linux-amd64 $tag-${{ matrix.scope }}-linux-arm64;
docker manifest push $tag-${{ matrix.scope }};
done