forked from cohere-ai/cohere-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
139 lines (108 loc) · 4.16 KB
/
docker_push_backend.yml
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
name: Create and publish backend image
on:
release:
types: [published]
workflow_dispatch:
inputs:
tags:
description: 'Docker image tag (e.g: v0.0.1)'
required: false
type: string
env:
IMAGE_NAME: cohere-toolkit-backend
jobs:
build-and-push-backend-image:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Login
uses: google-github-actions/setup-gcloud@v0
with:
project_id: ${{ vars.GCP_PROJECT_ID }}
service_account_email: [email protected]
service_account_key: ${{ secrets.GCP_SA_KEY }}
- name: Configure Docker
run: gcloud auth configure-docker --quiet
- name: Checkout repository
uses: actions/checkout@v2
- run: 'echo "$KEY" > ./key.json'
shell: bash
env:
KEY: ${{ secrets.GCP_SA_KEY }}
# - name: Checkout code
# uses: actions/checkout@v2
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v1
# - name: Decode and write GCP key to file
# run: echo "${{ secrets.GCP_SA_KEY_B64 }}" | base64 --decode > /tmp/gcp_sa_key.json
# - name: Authenticate to Google Cloud
# run: |
# gcloud auth activate-service-account --key-file=/tmp/gcp_sa_key.json
# gcloud auth configure-docker us-docker.pkg.dev --quiet
# - name: Checkout repository
# uses: actions/checkout@v4
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v1
# - name: Authenticate with service account
# uses: google-github-actions/auth@v1
# with:
# credentials_json: ${{ secrets.GCP_SA_KEY }}
# # - name: Login
# # uses: google-github-actions/setup-gcloud@v1
# - name: Set up Cloud SDK
# uses: google-github-actions/setup-gcloud@v1
# with:
# project_id: ${{ vars.GCP_PROJECT_ID }}
# service_account_key: ${{ secrets.GCP_SA_KEY }}
# - name: Configure Docker to use Google Cloud credentials
# run: gcloud auth configure-docker us-docker.pkg.dev
# export_default_credentials: true
# - name: Configure Docker
# run: yes | gcloud auth configure-docker us-docker.pkg.dev
# - name: Checkout repository
# uses: actions/checkout@v2
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ vars.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build Docker image
run: |
docker build -t ${{ env.IMAGE_NAME }} -f ./src/backend/Dockerfile .
# - name: Pull docker hello-world image
# run: docker pull hello-world
# - name: Tag Docker image
# run: |
# docker tag hello-world ${{ vars.REGISTRY }}/hello-world
# # Save the SA key to a file so that it can be used by the docker build
# - name: Save SA key to file
# run: echo "${{ secrets.GCP_SA_KEY }}" > /tmp/gcp_sa_key.json
# - name: Try auth again!
# run: |
# gcloud auth activate-service-account --key-file /tmp/gcp_sa_key.json
# gcloud auth configure-docker --quiet
# docker login -u _json_key -p "$(cat /tmp/gcp_sa_key.json)" https://gcr.io
# - name: Push Docker image
# run: |
# docker push ${{ vars.REGISTRY }}/hello-world
- name: Tag Docker image
run: |
docker tag ${{ env.IMAGE_NAME }} ${{ steps.meta.outputs.tags }}
- name: Push Docker image
env:
THE_TAGS: ${{ steps.meta.outputs.tags }}
run: |
docker push ${{ steps.meta.outputs.tags }}
# Deploy the image to Cloud Run
- name: Deploy to Cloud Run
run: |
gcloud run deploy ${{ env.IMAGE_NAME }} \
--image ${{ steps.meta.outputs.tags }} \
--platform managed \
--region us-central1 \
--allow-unauthenticated \
--update-env-vars DATABASE_URL=${{ secrets.DATABASE_URL }},COHERE_API_KEY=${{ secrets.COHERE_API_KEY }} \
--memory 4Gi \
--cpu 4
--max-instances 1