| @@ -1,61 +0,0 @@ | |||
| #!/usr/bin/env bash | |||
| set -eo pipefail | |||
| SHA=$(git rev-parse HEAD) | |||
| REPO_NAME=langgenius/dify | |||
| API_REPO_NAME="${REPO_NAME}-api" | |||
| if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then | |||
| REFSPEC=$(echo "${GITHUB_HEAD_REF}" | sed 's/[^a-zA-Z0-9]/-/g' | head -c 40) | |||
| PR_NUM=$(echo "${GITHUB_REF}" | sed 's:refs/pull/::' | sed 's:/merge::') | |||
| LATEST_TAG="pr-${PR_NUM}" | |||
| CACHE_FROM_TAG="latest" | |||
| elif [[ "${GITHUB_EVENT_NAME}" == "release" ]]; then | |||
| REFSPEC=$(echo "${GITHUB_REF}" | sed 's:refs/tags/::' | head -c 40) | |||
| LATEST_TAG="${REFSPEC}" | |||
| CACHE_FROM_TAG="latest" | |||
| else | |||
| REFSPEC=$(echo "${GITHUB_REF}" | sed 's:refs/heads/::' | sed 's/[^a-zA-Z0-9]/-/g' | head -c 40) | |||
| LATEST_TAG="${REFSPEC}" | |||
| CACHE_FROM_TAG="${REFSPEC}" | |||
| fi | |||
| if [[ "${REFSPEC}" == "main" ]]; then | |||
| LATEST_TAG="latest" | |||
| CACHE_FROM_TAG="latest" | |||
| fi | |||
| echo "Pulling cache image ${API_REPO_NAME}:${CACHE_FROM_TAG}" | |||
| if docker pull "${API_REPO_NAME}:${CACHE_FROM_TAG}"; then | |||
| API_CACHE_FROM_SCRIPT="--cache-from ${API_REPO_NAME}:${CACHE_FROM_TAG}" | |||
| else | |||
| echo "WARNING: Failed to pull ${API_REPO_NAME}:${CACHE_FROM_TAG}, disable build image cache." | |||
| API_CACHE_FROM_SCRIPT="" | |||
| fi | |||
| cat<<EOF | |||
| Rolling with tags: | |||
| - ${API_REPO_NAME}:${SHA} | |||
| - ${API_REPO_NAME}:${REFSPEC} | |||
| - ${API_REPO_NAME}:${LATEST_TAG} | |||
| EOF | |||
| # | |||
| # Build image | |||
| # | |||
| cd api | |||
| docker build \ | |||
| ${API_CACHE_FROM_SCRIPT} \ | |||
| --build-arg COMMIT_SHA=${SHA} \ | |||
| -t "${API_REPO_NAME}:${SHA}" \ | |||
| -t "${API_REPO_NAME}:${REFSPEC}" \ | |||
| -t "${API_REPO_NAME}:${LATEST_TAG}" \ | |||
| --label "sha=${SHA}" \ | |||
| --label "built_at=$(date)" \ | |||
| --label "build_actor=${GITHUB_ACTOR}" \ | |||
| . | |||
| # push | |||
| docker push --all-tags "${API_REPO_NAME}" | |||
| @@ -5,16 +5,19 @@ on: | |||
| branches: | |||
| - 'main' | |||
| - 'deploy/dev' | |||
| release: | |||
| types: [published] | |||
| jobs: | |||
| build-and-push: | |||
| runs-on: ubuntu-latest | |||
| if: github.event.pull_request.draft == false | |||
| steps: | |||
| - name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )" | |||
| uses: actions/checkout@v2 | |||
| with: | |||
| persist-credentials: false | |||
| - name: Set up QEMU | |||
| uses: docker/setup-qemu-action@v2 | |||
| - name: Set up Docker Buildx | |||
| uses: docker/setup-buildx-action@v2 | |||
| - name: Login to Docker Hub | |||
| uses: docker/login-action@v2 | |||
| @@ -22,13 +25,28 @@ jobs: | |||
| username: ${{ secrets.DOCKERHUB_USER }} | |||
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |||
| - name: Build and push Docker image | |||
| shell: bash | |||
| env: | |||
| DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }} | |||
| DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | |||
| run: | | |||
| /bin/bash .github/workflows/build-api-image.sh | |||
| - name: Extract metadata (tags, labels) for Docker | |||
| id: meta | |||
| uses: docker/metadata-action@v4 | |||
| with: | |||
| images: langgenius/dify-api | |||
| tags: | | |||
| type=raw,value=latest,enable={{is_default_branch}} | |||
| type=ref,event=branch | |||
| type=semver,pattern={{major}}.{{minor}}.{{patch}} | |||
| type=semver,pattern={{major}}.{{minor}} | |||
| type=semver,pattern={{major}} | |||
| - name: Build and push | |||
| uses: docker/build-push-action@v4 | |||
| with: | |||
| context: "{{defaultContext}}:api" | |||
| platforms: linux/amd64,linux/arm64 | |||
| build-args: | | |||
| COMMIT_SHA=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} | |||
| push: true | |||
| tags: ${{ steps.meta.outputs.tags }} | |||
| labels: ${{ steps.meta.outputs.labels }} | |||
| - name: Deploy to server | |||
| if: github.ref == 'refs/heads/deploy/dev' | |||
| @@ -1,60 +0,0 @@ | |||
| #!/usr/bin/env bash | |||
| set -eo pipefail | |||
| SHA=$(git rev-parse HEAD) | |||
| REPO_NAME=langgenius/dify | |||
| WEB_REPO_NAME="${REPO_NAME}-web" | |||
| if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then | |||
| REFSPEC=$(echo "${GITHUB_HEAD_REF}" | sed 's/[^a-zA-Z0-9]/-/g' | head -c 40) | |||
| PR_NUM=$(echo "${GITHUB_REF}" | sed 's:refs/pull/::' | sed 's:/merge::') | |||
| LATEST_TAG="pr-${PR_NUM}" | |||
| CACHE_FROM_TAG="latest" | |||
| elif [[ "${GITHUB_EVENT_NAME}" == "release" ]]; then | |||
| REFSPEC=$(echo "${GITHUB_REF}" | sed 's:refs/tags/::' | head -c 40) | |||
| LATEST_TAG="${REFSPEC}" | |||
| CACHE_FROM_TAG="latest" | |||
| else | |||
| REFSPEC=$(echo "${GITHUB_REF}" | sed 's:refs/heads/::' | sed 's/[^a-zA-Z0-9]/-/g' | head -c 40) | |||
| LATEST_TAG="${REFSPEC}" | |||
| CACHE_FROM_TAG="${REFSPEC}" | |||
| fi | |||
| if [[ "${REFSPEC}" == "main" ]]; then | |||
| LATEST_TAG="latest" | |||
| CACHE_FROM_TAG="latest" | |||
| fi | |||
| echo "Pulling cache image ${WEB_REPO_NAME}:${CACHE_FROM_TAG}" | |||
| if docker pull "${WEB_REPO_NAME}:${CACHE_FROM_TAG}"; then | |||
| WEB_CACHE_FROM_SCRIPT="--cache-from ${WEB_REPO_NAME}:${CACHE_FROM_TAG}" | |||
| else | |||
| echo "WARNING: Failed to pull ${WEB_REPO_NAME}:${CACHE_FROM_TAG}, disable build image cache." | |||
| WEB_CACHE_FROM_SCRIPT="" | |||
| fi | |||
| cat<<EOF | |||
| Rolling with tags: | |||
| - ${WEB_REPO_NAME}:${SHA} | |||
| - ${WEB_REPO_NAME}:${REFSPEC} | |||
| - ${WEB_REPO_NAME}:${LATEST_TAG} | |||
| EOF | |||
| # | |||
| # Build image | |||
| # | |||
| cd web | |||
| docker build \ | |||
| ${WEB_CACHE_FROM_SCRIPT} \ | |||
| --build-arg COMMIT_SHA=${SHA} \ | |||
| -t "${WEB_REPO_NAME}:${SHA}" \ | |||
| -t "${WEB_REPO_NAME}:${REFSPEC}" \ | |||
| -t "${WEB_REPO_NAME}:${LATEST_TAG}" \ | |||
| --label "sha=${SHA}" \ | |||
| --label "built_at=$(date)" \ | |||
| --label "build_actor=${GITHUB_ACTOR}" \ | |||
| . | |||
| docker push --all-tags "${WEB_REPO_NAME}" | |||
| @@ -5,16 +5,19 @@ on: | |||
| branches: | |||
| - 'main' | |||
| - 'deploy/dev' | |||
| release: | |||
| types: [published] | |||
| jobs: | |||
| build-and-push: | |||
| runs-on: ubuntu-latest | |||
| if: github.event.pull_request.draft == false | |||
| steps: | |||
| - name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )" | |||
| uses: actions/checkout@v2 | |||
| with: | |||
| persist-credentials: false | |||
| - name: Set up QEMU | |||
| uses: docker/setup-qemu-action@v2 | |||
| - name: Set up Docker Buildx | |||
| uses: docker/setup-buildx-action@v2 | |||
| - name: Login to Docker Hub | |||
| uses: docker/login-action@v2 | |||
| @@ -22,13 +25,28 @@ jobs: | |||
| username: ${{ secrets.DOCKERHUB_USER }} | |||
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |||
| - name: Build and push Docker image | |||
| shell: bash | |||
| env: | |||
| DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }} | |||
| DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | |||
| run: | | |||
| /bin/bash .github/workflows/build-web-image.sh | |||
| - name: Extract metadata (tags, labels) for Docker | |||
| id: meta | |||
| uses: docker/metadata-action@v4 | |||
| with: | |||
| images: langgenius/dify-web | |||
| tags: | | |||
| type=raw,value=latest,enable={{is_default_branch}} | |||
| type=ref,event=branch | |||
| type=semver,pattern={{major}}.{{minor}}.{{patch}} | |||
| type=semver,pattern={{major}}.{{minor}} | |||
| type=semver,pattern={{major}} | |||
| - name: Build and push | |||
| uses: docker/build-push-action@v4 | |||
| with: | |||
| context: "{{defaultContext}}:web" | |||
| platforms: linux/amd64,linux/arm64 | |||
| build-args: | | |||
| COMMIT_SHA=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} | |||
| push: true | |||
| tags: ${{ steps.meta.outputs.tags }} | |||
| labels: ${{ steps.meta.outputs.labels }} | |||
| - name: Deploy to server | |||
| if: github.ref == 'refs/heads/deploy/dev' | |||