This repository was archived by the owner on Apr 9, 2026. It is now read-only.
Repository navigation
170 lines (147 loc) · 6.42 KB
/
Copy pathdocker-image.yml
File metadata and controls
170 lines (147 loc) · 6.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: CI/CD Pipeline
# Trigger workflow on push to any branch and PRs to main
on:
push:
branches: ['*']
tags: ['v*.*.*']
pull_request:
branches: ['main']
jobs:
# Add a flag parameter to control whether to run tests
check-tests:
runs-on: ubuntu-latest
outputs:
run-tests: 'true' # Set to false to skip tests
steps:
- run: echo "Checking if tests should run"
test:
runs-on: ubuntu-latest
needs: check-tests
if: needs.check-tests.outputs.run-tests == 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install dependencies using setup script
run: |
cd backend
chmod +x setup-ci.sh
./setup-ci.sh
# same shell/job so tests can use the same venv
- name: Run tests
run: |
cd backend
source .venv/bin/activate
which pytest
python -m pytest --maxfail=2
env:
EMAIL_ACCOUNT: ${{ secrets.TEST_EMAIL_ACCOUNT }}
GOOGLE_CLIENT_ID: ${{ secrets.TEST_GOOGLE_CLIENT_ID }}
GOOGLE_CLIENT_SECRET: ${{ secrets.TEST_GOOGLE_CLIENT_SECRET }}
MONGO_URI: ${{ secrets.TEST_MONGO_URI }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }}
GOOGLE_API_KEY: ${{ secrets.GEMINI_API_KEY }}
SUMMARIZER_PROVIDER: ${{ secrets.SUMMARIZER_PROVIDER || 'openrouter' }}
# Add a placeholder job that will always run when tests are disabled
test-skipped:
runs-on: ubuntu-latest
needs: check-tests
if: needs.check-tests.outputs.run-tests != 'true'
steps:
- name: Tests skipped
run: echo "Tests are temporarily disabled"
build-docker:
runs-on: ubuntu-latest
# Depend on both jobs, GitHub Actions will automatically skip the disabled one
needs: [test, test-skipped]
# Only run this job for tagged versions or main branch
if: always() && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main') && (needs.test.result == 'success' || needs.test.result == 'skipped') && (needs.test-skipped.result == 'success' || needs.test-skipped.result == 'skipped')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Check if Docker Hub credentials are available
- name: Check Docker Hub credentials
id: check-docker-credentials
run: |
if [[ -n "${{ secrets.DOCKER_USERNAME }}" && -n "${{ secrets.DOCKER_PASSWORD }}" ]]; then
echo "has_credentials=true" >> $GITHUB_OUTPUT
else
echo "has_credentials=false" >> $GITHUB_OUTPUT
fi
# Only push to Docker Hub if we have the secrets configured
- name: Login to Docker Hub
if: steps.check-docker-credentials.outputs.has_credentials == 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# Build and optionally push backend image
- name: Build and push Backend Docker image
uses: docker/build-push-action@v6
with:
context: .
file: backend/Dockerfile
tags: |
${{ steps.check-docker-credentials.outputs.has_credentials == 'true' && format('{0}/emailessence-backend:{1}', secrets.DOCKER_USERNAME, startsWith(github.ref, 'refs/tags/') && github.ref_name || 'latest') || 'emailessence-backend:latest' }}
push: ${{ steps.check-docker-credentials.outputs.has_credentials == 'true' }}
# Build and publish dev Docker image for backend branch
build-docker-dev:
runs-on: ubuntu-latest
# Depend on both jobs, GitHub Actions will automatically skip the disabled one
needs: [test, test-skipped]
# Only run this job for pushes to the backend branch
if: always() && github.ref == 'refs/heads/backend' && (needs.test.result == 'success' || needs.test.result == 'skipped') && (needs.test-skipped.result == 'success' || needs.test-skipped.result == 'skipped')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Check if Docker Hub credentials are available
- name: Check Docker Hub credentials
id: check-docker-credentials
run: |
if [[ -n "${{ secrets.DOCKER_USERNAME }}" && -n "${{ secrets.DOCKER_PASSWORD }}" ]]; then
echo "has_credentials=true" >> $GITHUB_OUTPUT
else
echo "has_credentials=false" >> $GITHUB_OUTPUT
fi
# Only push to Docker Hub if we have the secrets configured
- name: Login to Docker Hub
if: steps.check-docker-credentials.outputs.has_credentials == 'true'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# Build and optionally push backend image with dev tag
- name: Build and push Backend Docker image (dev)
uses: docker/build-push-action@v2
with:
context: .
file: backend/Dockerfile
tags: |
${{ steps.check-docker-credentials.outputs.has_credentials == 'true' && format('{0}/emailessence-backend:dev', secrets.DOCKER_USERNAME) || 'emailessence-backend:dev' }}
push: ${{ steps.check-docker-credentials.outputs.has_credentials == 'true' }}
# This job is informational only - notifying that Render handles deployment
deploy-notification:
runs-on: ubuntu-latest
needs: build-docker
if: success() && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
steps:
- name: Deployment Information
run: |
echo "Docker image build completed successfully."
echo "Deployment to production is handled by Render automatically."
echo "No additional deployment steps needed in GitHub Actions."
- name: Trigger Render Deployment
if: env.RENDER_DEPLOY_HOOK_URL != ''
run: |
curl -X POST ${{ secrets.RENDER_DEPLOY_HOOK_URL }}
env:
RENDER_DEPLOY_HOOK_URL: ${{ secrets.RENDER_DEPLOY_HOOK_URL }}