Skip to content

Commit e40824d

Browse files
committed
Use Docker-based Firstrade Cloud Run deploy
1 parent 172736b commit e40824d

3 files changed

Lines changed: 50 additions & 6 deletions

File tree

.dockerignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.git
2+
.github
3+
.pytest_cache
4+
.runtime
5+
.venv
6+
__pycache__
7+
*.py[cod]
8+
.env
9+
ft_cookies*.json

.github/workflows/sync-cloud-run-env.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ env:
99
GCP_PROJECT_NUMBER: "1088907247379"
1010
GCP_WORKLOAD_IDENTITY_PROVIDER: projects/1088907247379/locations/global/workloadIdentityPools/github-actions/providers/github-main
1111
GCP_WORKLOAD_IDENTITY_SERVICE_ACCOUNT: firstrade-platform-deploy@firstradequant.iam.gserviceaccount.com
12-
GCP_CLOUD_BUILD_SERVICE_ACCOUNT: projects/firstradequant/serviceAccounts/firstrade-platform-build@firstradequant.iam.gserviceaccount.com
12+
GCP_RUNTIME_SERVICE_ACCOUNT: firstrade-platform-runtime@firstradequant.iam.gserviceaccount.com
1313
GCP_ARTIFACT_REGISTRY_HOSTNAME: us-central1-docker.pkg.dev
1414
GCP_ARTIFACT_REGISTRY_REPOSITORY: cloud-run-source-deploy
1515

@@ -115,16 +115,32 @@ jobs:
115115
project_id: ${{ env.GCP_PROJECT_ID }}
116116
version: ">= 416.0.0"
117117

118-
- name: Build and deploy Cloud Run image
118+
- name: Build, push, and deploy Cloud Run image
119119
if: steps.deploy_config.outputs.enabled == 'true'
120120
run: |
121121
set -euo pipefail
122122
123-
gcloud builds submit . \
123+
image_repo="${GCP_ARTIFACT_REGISTRY_HOSTNAME}/${GCP_PROJECT_ID}/${GCP_ARTIFACT_REGISTRY_REPOSITORY}/firstradeplatform/${CLOUD_RUN_SERVICE}"
124+
image="${image_repo}:${GITHUB_SHA}"
125+
126+
gcloud auth configure-docker "${GCP_ARTIFACT_REGISTRY_HOSTNAME}" --quiet
127+
docker build --pull -t "${image}" .
128+
docker push "${image}"
129+
130+
gcloud run deploy "${CLOUD_RUN_SERVICE}" \
124131
--project="${GCP_PROJECT_ID}" \
125-
--config=cloudbuild.yaml \
126-
--service-account="${GCP_CLOUD_BUILD_SERVICE_ACCOUNT}" \
127-
--substitutions="COMMIT_SHA=${GITHUB_SHA},REPO_NAME=firstradequant,_AR_HOSTNAME=${GCP_ARTIFACT_REGISTRY_HOSTNAME},_AR_PROJECT_ID=${GCP_PROJECT_ID},_AR_REPOSITORY=${GCP_ARTIFACT_REGISTRY_REPOSITORY},_DEPLOY_REGION=${CLOUD_RUN_REGION},_PLATFORM=managed,_SERVICE_NAME=${CLOUD_RUN_SERVICE}"
132+
--region="${CLOUD_RUN_REGION}" \
133+
--platform=managed \
134+
--image="${image}" \
135+
--service-account="${GCP_RUNTIME_SERVICE_ACCOUNT}" \
136+
--ingress=internal \
137+
--max-instances=1 \
138+
--concurrency=80 \
139+
--memory=512Mi \
140+
--cpu=1 \
141+
--timeout=300s \
142+
--labels="managed-by=github-actions,commit-sha=${GITHUB_SHA},github-run-id=${GITHUB_RUN_ID}" \
143+
--quiet
128144
129145
- name: Check whether env sync is enabled
130146
id: env_sync_config

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM python:3.12-slim
2+
3+
ENV PYTHONUNBUFFERED=1 \
4+
PIP_NO_CACHE_DIR=1 \
5+
PORT=8080
6+
7+
WORKDIR /app
8+
9+
RUN apt-get update \
10+
&& apt-get install -y --no-install-recommends git \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
COPY requirements.txt ./
14+
RUN python -m pip install --upgrade pip \
15+
&& python -m pip install -r requirements.txt
16+
17+
COPY . .
18+
19+
CMD ["gunicorn", "--bind", ":8080", "main:app"]

0 commit comments

Comments
 (0)