2024-03-17 14:20:34 +08:00
|
|
|
name: Build and Push API & Web
|
2023-05-15 08:51:32 +08:00
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
2024-03-17 14:20:34 +08:00
|
|
|
- "main"
|
|
|
|
- "deploy/dev"
|
2023-05-25 20:17:17 +08:00
|
|
|
release:
|
2024-03-17 14:20:34 +08:00
|
|
|
types: [published]
|
|
|
|
|
|
|
|
env:
|
|
|
|
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
|
|
|
|
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
DIFY_WEB_IMAGE_NAME: ${{ vars.DIFY_WEB_IMAGE_NAME || 'langgenius/dify-web' }}
|
|
|
|
DIFY_API_IMAGE_NAME: ${{ vars.DIFY_API_IMAGE_NAME || 'langgenius/dify-api' }}
|
2023-05-15 08:51:32 +08:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
build-and-push:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
if: github.event.pull_request.draft == false
|
2024-03-17 14:20:34 +08:00
|
|
|
strategy:
|
|
|
|
matrix:
|
|
|
|
include:
|
|
|
|
- service_name: "web"
|
|
|
|
image_name_env: "DIFY_WEB_IMAGE_NAME"
|
|
|
|
context: "web"
|
|
|
|
- service_name: "api"
|
|
|
|
image_name_env: "DIFY_API_IMAGE_NAME"
|
|
|
|
context: "api"
|
2023-05-15 08:51:32 +08:00
|
|
|
steps:
|
2024-01-09 18:15:25 +08:00
|
|
|
- name: Set up QEMU
|
|
|
|
uses: docker/setup-qemu-action@v3
|
2023-05-25 20:17:17 +08:00
|
|
|
|
2024-01-09 18:15:25 +08:00
|
|
|
- name: Set up Docker Buildx
|
|
|
|
uses: docker/setup-buildx-action@v3
|
2023-05-15 08:51:32 +08:00
|
|
|
|
2024-01-09 18:15:25 +08:00
|
|
|
- name: Login to Docker Hub
|
|
|
|
uses: docker/login-action@v2
|
|
|
|
with:
|
2024-03-17 14:20:34 +08:00
|
|
|
username: ${{ env.DOCKERHUB_USER }}
|
|
|
|
password: ${{ env.DOCKERHUB_TOKEN }}
|
2023-05-15 08:51:32 +08:00
|
|
|
|
2024-01-09 18:15:25 +08:00
|
|
|
- name: Extract metadata (tags, labels) for Docker
|
|
|
|
id: meta
|
|
|
|
uses: docker/metadata-action@v5
|
|
|
|
with:
|
2024-03-17 14:20:34 +08:00
|
|
|
images: ${{ env[matrix.image_name_env] }}
|
2024-01-09 18:15:25 +08:00
|
|
|
tags: |
|
2024-04-08 18:51:46 +08:00
|
|
|
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' && startsWith(github.ref, 'refs/tags/') }}
|
2024-01-09 18:15:25 +08:00
|
|
|
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/') }}
|
2023-05-25 20:17:17 +08:00
|
|
|
|
2024-01-09 18:15:25 +08:00
|
|
|
- name: Build and push
|
|
|
|
uses: docker/build-push-action@v5
|
|
|
|
with:
|
2024-03-17 14:20:34 +08:00
|
|
|
context: "{{defaultContext}}:${{ matrix.context }}"
|
2024-01-09 18:15:25 +08:00
|
|
|
platforms: ${{ startsWith(github.ref, 'refs/tags/') && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
|
2024-03-17 14:20:34 +08:00
|
|
|
build-args: COMMIT_SHA=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
|
2024-01-09 18:15:25 +08:00
|
|
|
push: true
|
|
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
|
|
cache-from: type=gha
|
|
|
|
cache-to: type=gha,mode=max
|