Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions .github/workflows/docker-backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@

name: Build, Push and Deploy SLRmentor Backend

on:
pull_request:
branches:
- main
types:
- closed

permissions:
contents: read

concurrency:
group: slrmentor-backend-deploy
cancel-in-progress: false

jobs:

# ==========================================
# PHASE 1: Generate Docker Image Version
# ==========================================

version:
name: "1. Generate Version"

if: >-
github.event.pull_request.merged == true &&
github.event.pull_request.head.ref == 'backend'

runs-on: ubuntu-latest

outputs:
version: ${{ steps.generate.outputs.version }}

steps:
- name: Generate version
id: generate
shell: bash
env:
COMMIT_SHA: ${{ github.event.pull_request.merge_commit_sha }}
run: |
TIMESTAMP=$(date -u +"%Y%m%d.%H%M%S")
SHORT_SHA="${COMMIT_SHA:0:7}"
VERSION="v${TIMESTAMP}-${SHORT_SHA}"

echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Generated version: $VERSION"


# ==========================================
# PHASE 2: Build and Push Docker Image
# ==========================================

build-and-push:
name: "2. Build & Push Docker Image"

needs: version
runs-on: ubuntu-latest

steps:
- name: Checkout merged commit
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.merge_commit_sha }}

- name: Exclude environment files
shell: bash
run: |
cat >> backend/.dockerignore <<'EOF'

# Environment files
.env
.env.*
**/.env
**/.env.*

# Local Python environment
.venv/
__pycache__/
*.pyc
EOF

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4

- name: Login to Docker Hub
uses: docker/login-action@v4
with:
username: seallabuofc
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: ./backend
file: ./backend/Dockerfile
platforms: linux/amd64
push: true
tags: |
seallabuofc/slrmentor-backend:${{ needs.version.outputs.version }}
seallabuofc/slrmentor-backend:latest
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Build summary
shell: bash
env:
VERSION: ${{ needs.version.outputs.version }}
run: |
echo "### Docker Image Published" >> "$GITHUB_STEP_SUMMARY"
echo "- Repository: seallabuofc/slrmentor-backend" >> "$GITHUB_STEP_SUMMARY"
echo "- Version: $VERSION" >> "$GITHUB_STEP_SUMMARY"
echo "- Latest: updated" >> "$GITHUB_STEP_SUMMARY"


# ==========================================
# PHASE 3: Deploy Image to Render
# ==========================================

deploy:
name: "3. Deploy to Render"

needs:
- version
- build-and-push

runs-on: ubuntu-latest

steps:
- name: Trigger Render deployment
shell: bash
env:
RENDER_DEPLOY_HOOK: ${{ secrets.RENDER_DEPLOY_HOOK }}
run: |
curl --fail --silent --show-error \
--retry 3 \
--request POST \
"$RENDER_DEPLOY_HOOK"

- name: Deployment summary
shell: bash
env:
VERSION: ${{ needs.version.outputs.version }}
run: |
echo "### SLRmentor Backend Deployment" >> "$GITHUB_STEP_SUMMARY"
echo "- Image: seallabuofc/slrmentor-backend" >> "$GITHUB_STEP_SUMMARY"
echo "- Version: $VERSION" >> "$GITHUB_STEP_SUMMARY"
echo "- Render deployment: triggered" >> "$GITHUB_STEP_SUMMARY"
9 changes: 9 additions & 0 deletions Bruno_SLRmentor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Secrets
.env*

# Dependencies
node_modules

# OS files
.DS_Store
Thumbs.db
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
info:
name: Test Get Chat history
type: http
seq: 4

http:
method: POST
url: https://api.slrmentor.ca/getchathistory
body:
type: json
data: "{\r

\ \"hash_plain_text\": \"2e8b4de7\"\r

}\r

// 1fc49d43"
auth: inherit

runtime:
scripts:
- type: after-response
code: "// Validate that the response code should be 200\r

test(\"Response Code should be 200\", function () {\r

\ expect(res.getStatus()).to.equal(200);\r

});\r

\r

// Run validations on response headers like Content-Type\r

test(\"Content-Type should be JSON\", function () {\r

\ expect(res.getHeader('Content-Type')).to.eql('application/json; charset=utf-8');\r

});\r

\r

const json = res.getBody();\r

\r

// The response body, including individual attributes can be evaluated for correctness\r

test(\"`args` should contain the correct query params\", function () {\r

\ expect(json.args).to.be.an('object');\r

\ expect(json.args.foo).to.eql('bar');\r

\ expect(json.args.baz).to.eql('value');\r

});\r

\r

// Non-trivial data types like Dates can also be tested against\r

test(\"Date in the header should be valid\", function () {\r

\ const parsedDate = new Date(res.getHeader('Date'));\r

\ expect(parsedDate).to.be.a('date');\r

});"

settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5

docs: The tests in the request validate the response code and the data returned in the response is the same as the one being sent.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
info:
name: Test Get Criteria Chat history
type: http
seq: 8

http:
method: POST
url: http://127.0.0.1:5000/getcriteriachathistory
body:
type: json
data: "{\r

\ \"hash_plain_text\": \"2e8b4de7\"\r

}"
auth: inherit

runtime:
scripts:
- type: after-response
code: "// Validate that the response code should be 200\r

test(\"Response Code should be 200\", function () {\r

\ expect(res.getStatus()).to.equal(200);\r

});\r

\r

// Run validations on response headers like Content-Type\r

test(\"Content-Type should be JSON\", function () {\r

\ expect(res.getHeader('Content-Type')).to.eql('application/json; charset=utf-8');\r

});\r

\r

const json = res.getBody();\r

\r

// The response body, including individual attributes can be evaluated for correctness\r

test(\"`args` should contain the correct query params\", function () {\r

\ expect(json.args).to.be.an('object');\r

\ expect(json.args.foo).to.eql('bar');\r

\ expect(json.args.baz).to.eql('value');\r

});\r

\r

// Non-trivial data types like Dates can also be tested against\r

test(\"Date in the header should be valid\", function () {\r

\ const parsedDate = new Date(res.getHeader('Date'));\r

\ expect(parsedDate).to.be.a('date');\r

});"

settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5

docs: The tests in the request validate the response code and the data returned in the response is the same as the one being sent.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
info:
name: Test Get Mentor history
type: http
seq: 7

http:
method: POST
url: https://api.slrmentor.ca/getmentorchathistory
body:
type: json
data: "{\r

\ \"hash_plain_text\": \"2e8b4de7\"\r

}"
auth: inherit

runtime:
scripts:
- type: after-response
code: "// Validate that the response code should be 200\r

test(\"Response Code should be 200\", function () {\r

\ expect(res.getStatus()).to.equal(200);\r

});\r

\r

// Run validations on response headers like Content-Type\r

test(\"Content-Type should be JSON\", function () {\r

\ expect(res.getHeader('Content-Type')).to.eql('application/json; charset=utf-8');\r

});\r

\r

const json = res.getBody();\r

\r

// The response body, including individual attributes can be evaluated for correctness\r

test(\"`args` should contain the correct query params\", function () {\r

\ expect(json.args).to.be.an('object');\r

\ expect(json.args.foo).to.eql('bar');\r

\ expect(json.args.baz).to.eql('value');\r

});\r

\r

// Non-trivial data types like Dates can also be tested against\r

test(\"Date in the header should be valid\", function () {\r

\ const parsedDate = new Date(res.getHeader('Date'));\r

\ expect(parsedDate).to.be.a('date');\r

});"

settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5

docs: The tests in the request validate the response code and the data returned in the response is the same as the one being sent.
Loading