-
Notifications
You must be signed in to change notification settings - Fork 0
88 lines (78 loc) · 2.66 KB
/
cd.yml
File metadata and controls
88 lines (78 loc) · 2.66 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
name: CD Pipeline
on:
workflow_dispatch:
inputs:
environment:
description: 'Target environment'
required: true
default: 'prod'
type: choice
options:
- prod
workflow_run:
workflows: ["CI Pipeline"]
types:
- completed
branches:
- main
env:
REGISTRY: docker.io
NAMESPACE: backend
jobs:
deploy:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
environment: prod
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to DockerHub
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_ACCESS_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.REGISTRY_REPOSITORY }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
type=gha
type=registry,ref=${{ secrets.REGISTRY_REPOSITORY }}:buildcache
cache-to: |
type=gha,mode=max
type=registry,ref=${{ secrets.REGISTRY_REPOSITORY }}:buildcache,mode=max
- name: Extract SHA-suffixed tag
id: extract_tag
run: |
# Find the tag with SHA suffix (format: branch-sha)
TAGS='${{ steps.meta.outputs.tags }}'
SHA_TAG=$(echo "$TAGS" | grep -E '.*-[a-f0-9]{7}$' | head -1 | cut -d':' -f2)
echo "tag=$SHA_TAG" >> $GITHUB_OUTPUT
- name: Deploy with Helm
uses: ./.github/actions/helm-deploy
with:
image_tag: ${{ steps.extract_tag.outputs.tag }}
registry_repository: ${{ secrets.REGISTRY_REPOSITORY }}
kube_config_data: ${{ secrets.KUBE_CONFIG_DATA }}
helm_values_env: ${{ secrets.HELM_VALUES_ENV }}
helm_values_persistence_hostpath: ${{ secrets.HELM_VALUES_PERSISTENCE_HOSTPATH }}
helm_values_persistence_nodename: ${{ secrets.HELM_VALUES_PERSISTENCE_NODENAME }}
helm_set_files: 'configMapData.download=scripts/download.sh'
namespace: ${{ env.NAMESPACE }}
github_token: ${{ secrets.GITHUB_TOKEN }}