-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (96 loc) · 3.32 KB
/
Copy pathrelease.yml
File metadata and controls
107 lines (96 loc) · 3.32 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
name: Release
# Build + push the two production images, then deploy with Helm:
# push to main -> build -> deploy to STAGING
# push tag v* -> build -> deploy to PRODUCTION (gated by the environment's
# required reviewers)
# manual -> build only (workflow_dispatch)
#
# Deploys are OFF until a cluster exists. To enable, set the repository
# variable DEPLOY_ENABLED=true (Settings -> Secrets and variables -> Actions ->
# Variables) and add the per-environment secret:
# staging / production: KUBE_CONFIG (base64-encoded kubeconfig for the cluster)
# Until then the deploy jobs are skipped and this workflow only builds + pushes
# images to GHCR (using the built-in GITHUB_TOKEN, packages: write).
on:
push:
branches: [main]
tags: ["v*"]
workflow_dispatch:
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
env:
REGISTRY: ghcr.io
jobs:
images:
name: Build & push (${{ matrix.component }})
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
include:
- component: backend
context: backend
dockerfile: backend/Dockerfile.prod
- component: frontend
context: frontend
dockerfile: frontend/Dockerfile.prod
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Image metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/querywise-${{ matrix.component }}
tags: |
type=raw,value=${{ github.sha }}
type=ref,event=branch
type=semver,pattern={{version}}
type=raw,value=latest,enable={{is_default_branch}}
- name: Build & push
uses: docker/build-push-action@v6
with:
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# Frontend is built same-origin; nginx proxies /api to the backend.
build-args: ${{ matrix.component == 'frontend' && 'VITE_API_URL=' || '' }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy-staging:
name: Deploy to staging
needs: images
if: github.ref == 'refs/heads/main' && vars.DEPLOY_ENABLED == 'true'
runs-on: ubuntu-latest
environment: staging
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/helm-deploy
with:
environment: staging
image_tag: ${{ github.sha }}
kube_config: ${{ secrets.KUBE_CONFIG }}
deploy-prod:
name: Deploy to production
needs: images
if: startsWith(github.ref, 'refs/tags/v') && vars.DEPLOY_ENABLED == 'true'
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/helm-deploy
with:
environment: production
image_tag: ${{ github.sha }}
kube_config: ${{ secrets.KUBE_CONFIG }}