Spaces:
No application file
No application file
Upload .github\workflows\build-push.yml with huggingface_hub
Browse files
.github//workflows//build-push.yml
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Build and Push API & Web
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
branches:
|
| 6 |
+
- "main"
|
| 7 |
+
- "deploy/dev"
|
| 8 |
+
release:
|
| 9 |
+
types: [published]
|
| 10 |
+
|
| 11 |
+
concurrency:
|
| 12 |
+
group: build-push-${{ github.head_ref || github.run_id }}
|
| 13 |
+
cancel-in-progress: true
|
| 14 |
+
|
| 15 |
+
env:
|
| 16 |
+
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
|
| 17 |
+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
|
| 18 |
+
DIFY_WEB_IMAGE_NAME: ${{ vars.DIFY_WEB_IMAGE_NAME || 'langgenius/dify-web' }}
|
| 19 |
+
DIFY_API_IMAGE_NAME: ${{ vars.DIFY_API_IMAGE_NAME || 'langgenius/dify-api' }}
|
| 20 |
+
|
| 21 |
+
jobs:
|
| 22 |
+
build:
|
| 23 |
+
runs-on: ${{ matrix.platform == 'linux/arm64' && 'arm64_runner' || 'ubuntu-latest' }}
|
| 24 |
+
if: github.repository == 'langgenius/dify'
|
| 25 |
+
strategy:
|
| 26 |
+
matrix:
|
| 27 |
+
include:
|
| 28 |
+
- service_name: "build-api-amd64"
|
| 29 |
+
image_name_env: "DIFY_API_IMAGE_NAME"
|
| 30 |
+
context: "api"
|
| 31 |
+
platform: linux/amd64
|
| 32 |
+
- service_name: "build-api-arm64"
|
| 33 |
+
image_name_env: "DIFY_API_IMAGE_NAME"
|
| 34 |
+
context: "api"
|
| 35 |
+
platform: linux/arm64
|
| 36 |
+
- service_name: "build-web-amd64"
|
| 37 |
+
image_name_env: "DIFY_WEB_IMAGE_NAME"
|
| 38 |
+
context: "web"
|
| 39 |
+
platform: linux/amd64
|
| 40 |
+
- service_name: "build-web-arm64"
|
| 41 |
+
image_name_env: "DIFY_WEB_IMAGE_NAME"
|
| 42 |
+
context: "web"
|
| 43 |
+
platform: linux/arm64
|
| 44 |
+
|
| 45 |
+
steps:
|
| 46 |
+
- name: Prepare
|
| 47 |
+
run: |
|
| 48 |
+
platform=${{ matrix.platform }}
|
| 49 |
+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
|
| 50 |
+
|
| 51 |
+
- name: Login to Docker Hub
|
| 52 |
+
uses: docker/login-action@v3
|
| 53 |
+
with:
|
| 54 |
+
username: ${{ env.DOCKERHUB_USER }}
|
| 55 |
+
password: ${{ env.DOCKERHUB_TOKEN }}
|
| 56 |
+
|
| 57 |
+
- name: Set up QEMU
|
| 58 |
+
uses: docker/setup-qemu-action@v3
|
| 59 |
+
|
| 60 |
+
- name: Set up Docker Buildx
|
| 61 |
+
uses: docker/setup-buildx-action@v3
|
| 62 |
+
|
| 63 |
+
- name: Extract metadata for Docker
|
| 64 |
+
id: meta
|
| 65 |
+
uses: docker/metadata-action@v5
|
| 66 |
+
with:
|
| 67 |
+
images: ${{ env[matrix.image_name_env] }}
|
| 68 |
+
|
| 69 |
+
- name: Build Docker image
|
| 70 |
+
id: build
|
| 71 |
+
uses: docker/build-push-action@v6
|
| 72 |
+
with:
|
| 73 |
+
context: "{{defaultContext}}:${{ matrix.context }}"
|
| 74 |
+
platforms: ${{ matrix.platform }}
|
| 75 |
+
build-args: COMMIT_SHA=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
|
| 76 |
+
labels: ${{ steps.meta.outputs.labels }}
|
| 77 |
+
outputs: type=image,name=${{ env[matrix.image_name_env] }},push-by-digest=true,name-canonical=true,push=true
|
| 78 |
+
cache-from: type=gha,scope=${{ matrix.service_name }}
|
| 79 |
+
cache-to: type=gha,mode=max,scope=${{ matrix.service_name }}
|
| 80 |
+
|
| 81 |
+
- name: Export digest
|
| 82 |
+
env:
|
| 83 |
+
DIGEST: ${{ steps.build.outputs.digest }}
|
| 84 |
+
run: |
|
| 85 |
+
mkdir -p /tmp/digests
|
| 86 |
+
sanitized_digest=${DIGEST#sha256:}
|
| 87 |
+
touch "/tmp/digests/${sanitized_digest}"
|
| 88 |
+
|
| 89 |
+
- name: Upload digest
|
| 90 |
+
uses: actions/upload-artifact@v4
|
| 91 |
+
with:
|
| 92 |
+
name: digests-${{ matrix.context }}-${{ env.PLATFORM_PAIR }}
|
| 93 |
+
path: /tmp/digests/*
|
| 94 |
+
if-no-files-found: error
|
| 95 |
+
retention-days: 1
|
| 96 |
+
|
| 97 |
+
create-manifest:
|
| 98 |
+
needs: build
|
| 99 |
+
runs-on: ubuntu-latest
|
| 100 |
+
if: github.repository == 'langgenius/dify'
|
| 101 |
+
strategy:
|
| 102 |
+
matrix:
|
| 103 |
+
include:
|
| 104 |
+
- service_name: "merge-api-images"
|
| 105 |
+
image_name_env: "DIFY_API_IMAGE_NAME"
|
| 106 |
+
context: "api"
|
| 107 |
+
- service_name: "merge-web-images"
|
| 108 |
+
image_name_env: "DIFY_WEB_IMAGE_NAME"
|
| 109 |
+
context: "web"
|
| 110 |
+
steps:
|
| 111 |
+
- name: Download digests
|
| 112 |
+
uses: actions/download-artifact@v4
|
| 113 |
+
with:
|
| 114 |
+
path: /tmp/digests
|
| 115 |
+
pattern: digests-${{ matrix.context }}-*
|
| 116 |
+
merge-multiple: true
|
| 117 |
+
|
| 118 |
+
- name: Login to Docker Hub
|
| 119 |
+
uses: docker/login-action@v3
|
| 120 |
+
with:
|
| 121 |
+
username: ${{ env.DOCKERHUB_USER }}
|
| 122 |
+
password: ${{ env.DOCKERHUB_TOKEN }}
|
| 123 |
+
|
| 124 |
+
- name: Extract metadata for Docker
|
| 125 |
+
id: meta
|
| 126 |
+
uses: docker/metadata-action@v5
|
| 127 |
+
with:
|
| 128 |
+
images: ${{ env[matrix.image_name_env] }}
|
| 129 |
+
tags: |
|
| 130 |
+
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') && !contains(github.ref, '-') }}
|
| 131 |
+
type=ref,event=branch
|
| 132 |
+
type=sha,enable=true,priority=100,prefix=,suffix=,format=long
|
| 133 |
+
type=raw,value=${{ github.ref_name }},enable=${{ startsWith(github.ref, 'refs/tags/') }}
|
| 134 |
+
|
| 135 |
+
- name: Create manifest list and push
|
| 136 |
+
working-directory: /tmp/digests
|
| 137 |
+
env:
|
| 138 |
+
IMAGE_NAME: ${{ env[matrix.image_name_env] }}
|
| 139 |
+
run: |
|
| 140 |
+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
|
| 141 |
+
$(printf "$IMAGE_NAME@sha256:%s " *)
|
| 142 |
+
|
| 143 |
+
- name: Inspect image
|
| 144 |
+
env:
|
| 145 |
+
IMAGE_NAME: ${{ env[matrix.image_name_env] }}
|
| 146 |
+
IMAGE_VERSION: ${{ steps.meta.outputs.version }}
|
| 147 |
+
run: |
|
| 148 |
+
docker buildx imagetools inspect "$IMAGE_NAME:$IMAGE_VERSION"
|