Skip to content

Commit 15a6d94

Browse files
authored
Refactor: Streamline the build-push and deploy-dev workflow (langgenius#2852)
1 parent 0563319 commit 15a6d94

File tree

4 files changed

+91
-80
lines changed

4 files changed

+91
-80
lines changed

.github/workflows/build-api-image.yml .github/workflows/build-push.yml

+24-20
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
1-
name: Build and Push API Image
1+
name: Build and Push API & Web
22

33
on:
44
push:
55
branches:
6-
- 'main'
7-
- 'deploy/dev'
6+
- "main"
7+
- "deploy/dev"
88
release:
9-
types: [ published ]
9+
types: [published]
10+
11+
env:
12+
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
13+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
14+
DIFY_WEB_IMAGE_NAME: ${{ vars.DIFY_WEB_IMAGE_NAME || 'langgenius/dify-web' }}
15+
DIFY_API_IMAGE_NAME: ${{ vars.DIFY_API_IMAGE_NAME || 'langgenius/dify-api' }}
1016

1117
jobs:
1218
build-and-push:
1319
runs-on: ubuntu-latest
1420
if: github.event.pull_request.draft == false
21+
strategy:
22+
matrix:
23+
include:
24+
- service_name: "web"
25+
image_name_env: "DIFY_WEB_IMAGE_NAME"
26+
context: "web"
27+
- service_name: "api"
28+
image_name_env: "DIFY_API_IMAGE_NAME"
29+
context: "api"
1530
steps:
1631
- name: Set up QEMU
1732
uses: docker/setup-qemu-action@v3
@@ -22,14 +37,14 @@ jobs:
2237
- name: Login to Docker Hub
2338
uses: docker/login-action@v2
2439
with:
25-
username: ${{ secrets.DOCKERHUB_USER }}
26-
password: ${{ secrets.DOCKERHUB_TOKEN }}
40+
username: ${{ env.DOCKERHUB_USER }}
41+
password: ${{ env.DOCKERHUB_TOKEN }}
2742

2843
- name: Extract metadata (tags, labels) for Docker
2944
id: meta
3045
uses: docker/metadata-action@v5
3146
with:
32-
images: langgenius/dify-api
47+
images: ${{ env[matrix.image_name_env] }}
3348
tags: |
3449
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }}
3550
type=ref,event=branch
@@ -39,22 +54,11 @@ jobs:
3954
- name: Build and push
4055
uses: docker/build-push-action@v5
4156
with:
42-
context: "{{defaultContext}}:api"
57+
context: "{{defaultContext}}:${{ matrix.context }}"
4358
platforms: ${{ startsWith(github.ref, 'refs/tags/') && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
44-
build-args: |
45-
COMMIT_SHA=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
59+
build-args: COMMIT_SHA=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
4660
push: true
4761
tags: ${{ steps.meta.outputs.tags }}
4862
labels: ${{ steps.meta.outputs.labels }}
4963
cache-from: type=gha
5064
cache-to: type=gha,mode=max
51-
52-
- name: Deploy to server
53-
if: github.ref == 'refs/heads/deploy/dev'
54-
uses: appleboy/[email protected]
55-
with:
56-
host: ${{ secrets.SSH_HOST }}
57-
username: ${{ secrets.SSH_USER }}
58-
key: ${{ secrets.SSH_PRIVATE_KEY }}
59-
script: |
60-
${{ secrets.SSH_SCRIPT }}

.github/workflows/build-web-image.yml

-60
This file was deleted.

.github/workflows/deploy-dev.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Deploy Dev
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Build and Push API & Web"]
6+
branches:
7+
- "deploy/dev"
8+
types:
9+
- completed
10+
11+
jobs:
12+
deploy:
13+
runs-on: ubuntu-latest
14+
if: |
15+
github.event.workflow_run.conclusion == 'success'
16+
steps:
17+
- name: Deploy to server
18+
uses: appleboy/[email protected]
19+
with:
20+
host: ${{ secrets.SSH_HOST }}
21+
username: ${{ secrets.SSH_USER }}
22+
key: ${{ secrets.SSH_PRIVATE_KEY }}
23+
script: |
24+
${{ vars.SSH_SCRIPT || secrets.SSH_SCRIPT }}

Makefile

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Variables
2+
DOCKER_REGISTRY=langgenius
3+
WEB_IMAGE=$(DOCKER_REGISTRY)/dify-web
4+
API_IMAGE=$(DOCKER_REGISTRY)/dify-api
5+
VERSION=latest
6+
7+
# Build Docker images
8+
build-web:
9+
@echo "Building web Docker image: $(WEB_IMAGE):$(VERSION)..."
10+
docker build -t $(WEB_IMAGE):$(VERSION) ./web
11+
@echo "Web Docker image built successfully: $(WEB_IMAGE):$(VERSION)"
12+
13+
build-api:
14+
@echo "Building API Docker image: $(API_IMAGE):$(VERSION)..."
15+
docker build -t $(API_IMAGE):$(VERSION) ./api
16+
@echo "API Docker image built successfully: $(API_IMAGE):$(VERSION)"
17+
18+
# Push Docker images
19+
push-web:
20+
@echo "Pushing web Docker image: $(WEB_IMAGE):$(VERSION)..."
21+
docker push $(WEB_IMAGE):$(VERSION)
22+
@echo "Web Docker image pushed successfully: $(WEB_IMAGE):$(VERSION)"
23+
24+
push-api:
25+
@echo "Pushing API Docker image: $(API_IMAGE):$(VERSION)..."
26+
docker push $(API_IMAGE):$(VERSION)
27+
@echo "API Docker image pushed successfully: $(API_IMAGE):$(VERSION)"
28+
29+
# Build all images
30+
build-all: build-web build-api
31+
32+
# Push all images
33+
push-all: push-web push-api
34+
35+
build-push-api: build-api push-api
36+
build-push-web: build-web push-web
37+
38+
# Build and push all images
39+
build-push-all: build-all push-all
40+
@echo "All Docker images have been built and pushed."
41+
42+
# Phony targets
43+
.PHONY: build-web build-api push-web push-api build-all push-all build-push-all

0 commit comments

Comments
 (0)