From 6e1777747a58bb2d9da0f45d13c9572bf0061997 Mon Sep 17 00:00:00 2001 From: everyfine Date: Sat, 18 May 2024 16:36:04 +0800 Subject: [PATCH 1/2] Make dev workflow to manually --- .github/workflows/dev.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 7218dde..ddb77b3 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -1,9 +1,10 @@ name: Genius AI Dev Deploy on: - push: - branches: [ "dev" ] - pull_request: - branches: [ "dev" ] + # push: + # branches: [ "dev" ] + # pull_request: + # branches: [ "dev" ] + workflow_dispatch env: REGISTRY: ghcr.io From 619da0ce02027a7da545ddeda171b2cec89b45a9 Mon Sep 17 00:00:00 2001 From: everyfine Date: Sat, 18 May 2024 16:59:17 +0800 Subject: [PATCH 2/2] Add github action for main branch --- .github/workflows/dev.yml | 7 +--- .github/workflows/main.yml | 75 +++++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 2 +- 3 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index ddb77b3..296871f 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -15,7 +15,7 @@ env: TARGET_SSH_PORT: ${{ secrets.TARGET_SSH_PORT }} TARGET_SERVICE_PORT: 13501 OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - TAVILY_API_KEY: ${{ secrets.OPENAI_API_KEY }} + TAVILY_API_KEY: ${{ secrets.TAVILY_API_KEY }} STREAMLIT_CONFIG: ${{ secrets.STREAMLIT_CONFIG }} jobs: @@ -47,10 +47,7 @@ jobs: with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | - type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} + type=sha,prefix={{branch}}- - name: Build and push Docker image id: push diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..e4df783 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,75 @@ +name: Genius AI Main Deploy +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + workflow_dispatch + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }}/geniuschatbots + TARGET_SSH_HOST: ${{ secrets.TARGET_SSH_HOST }} + TARGET_SSH_USER: ${{ secrets.TARGET_SSH_USER }} + TARGET_SSH_PASSWORD: ${{ secrets.TARGET_SSH_PASSWORD }} + TARGET_SSH_PORT: ${{ secrets.TARGET_SSH_PORT }} + TARGET_SERVICE_PORT: 13501 + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + TAVILY_API_KEY: ${{ secrets.TAVILY_API_KEY }} + STREAMLIT_CONFIG: ${{ secrets.STREAMLIT_CONFIG }} + +jobs: + build-and-push-image: + name: Build Docker image and push to repositories + runs-on: ubuntu-latest + environment: main + permissions: + contents: read + packages: write + attestations: write + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Write streamlit config + run: | + mkdir GeniusChatbots/.streamlit + echo "${{ env.STREAMLIT_CONFIG }}" > GeniusChatbots/.streamlit/config.yaml + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=sha,prefix={{branch}}- + + - name: Build and push Docker image + id: push + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: GeniusChatbots + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: deploying + uses: appleboy/ssh-action@v0.1.8 + with: + host: ${{ env.TARGET_SSH_HOST }} + username: ${{ env.TARGET_SSH_USER }} + password: ${{ env.TARGET_SSH_PASSWORD }} + port: ${{ env.TARGET_SSH_PORT }} + script: | + docker image pull ${{ steps.meta.outputs.tags }} + docker container stop geniusmain + docker container rm geniusmain + docker container run -d --name geniusmain -p ${{ env.TARGET_SERVICE_PORT }}:8501 -e OPENAI_API_KEY=${{ env.OPENAI_API_KEY }} -e TAVILY_API_KEY=${{ env.TAVILY_API_KEY }} ${{ steps.meta.outputs.tags }} + + + \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ba85043..5e9f56b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,7 +12,7 @@ env: TARGET_SSH_PORT: ${{ secrets.TARGET_SSH_PORT }} TARGET_SERVICE_PORT: 23501 OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - TAVILY_API_KEY: ${{ secrets.OPENAI_API_KEY }} + TAVILY_API_KEY: ${{ secrets.TAVILY_API_KEY }} STREAMLIT_CONFIG: ${{ secrets.STREAMLIT_CONFIG }} jobs: