-
Notifications
You must be signed in to change notification settings - Fork 1
96 lines (92 loc) · 3.21 KB
/
cicd.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
name: CICD
on:
push:
branches: [ main ]
env:
GCLOUD_PROJECT: hemslo-chat-search
GCLOUD_REGION: us-west1
GCLOUD_REGISTRY: us-west1-docker.pkg.dev
GCLOUD_SERVICE: chat-search
GITHUB_REGISTRY: ghcr.io
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.GITHUB_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: google-github-actions/auth@v2
id: gcloud_auth
with:
credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }}
token_format: access_token
- name: Login to Google Cloud Artifact Registry
uses: docker/login-action@v3
with:
registry: ${{ env.GCLOUD_REGISTRY }}
username: oauth2accesstoken
password: ${{ steps.gcloud_auth.outputs.access_token }}
- name: Docker meta
uses: docker/metadata-action@v4
id: meta
with:
images: |
${{ env.GCLOUD_REGISTRY }}/${{ env.GCLOUD_PROJECT }}/${{ env.GCLOUD_SERVICE }}/${{ env.GCLOUD_SERVICE }}
${{ env.GITHUB_REGISTRY }}/${{ github.repository }}
tags: |
type=raw,value=latest
type=sha
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
outputs:
image: ${{ fromJSON(steps.meta.outputs.json).tags[1] }}
deploy:
needs: build
runs-on: ubuntu-latest
environment: demo
env:
OTEL_EXPORTER_OTLP_ENDPOINT: ${{ vars.OTEL_EXPORTER_OTLP_ENDPOINT }}
OTEL_EXPORTER_OTLP_HEADERS_SECRET_NAME: ${{ vars.OTEL_EXPORTER_OTLP_HEADERS_SECRET_NAME || 'OTEL_EXPORTER_OTLP_HEADERS' }}
OTEL_EXPORTER_OTLP_HEADERS_SECRET_VERSION: ${{ vars.OTEL_EXPORTER_OTLP_HEADERS_SECRET_VERSION || 'latest' }}
OTEL_EXPORTER_OTLP_PROTOCOL: ${{ vars.OTEL_EXPORTER_OTLP_PROTOCOL }}
OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED: ${{ vars.OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED || 'true' }}
OTEL_SERVICE_NAME: ${{ vars.OTEL_SERVICE_NAME || 'chat-search' }}
DOTENV_SECRET_VERSION: ${{ vars.DOTENV_SECRET_VERSION || 'latest' }}
DOTENV_SECRET_NAME: ${{ vars.DOTENV_SECRET_NAME || 'DOTENV' }}
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }}
- name: Create Service YAML
run: envsubst < ./service.template.yaml > service.yaml
env:
SERVICE: ${{ env.GCLOUD_SERVICE }}
IMAGE: ${{ needs.build.outputs.image }}
- name: Deploy to Cloud Run
uses: google-github-actions/deploy-cloudrun@v2
with:
service: ${{ env.GCLOUD_SERVICE }}
region: ${{ env.GCLOUD_REGION }}
metadata: service.yaml