-
Notifications
You must be signed in to change notification settings - Fork 0
126 lines (106 loc) · 3.27 KB
/
cd.yml
File metadata and controls
126 lines (106 loc) · 3.27 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
name: pinit-task CD
on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
type: choice
options:
- info
- warning
- debug
push:
branches: [ "master" ]
permissions:
contents: read
packages: write
jobs:
build-test-push-deploy:
runs-on: [ arc-runner-set ]
env:
IMAGE_REPO: ghcr.io/pinit-scheduler/pinit-task/app
NAMESPACE: pinit
DEPLOYMENT_NAME: pinit-task
CONTAINER_NAME: app
MANIFEST_PATH: k8s/deployment.yaml
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "21"
cache: gradle
- name: Check Docker availability
run: docker info
- name: Build & Test
run: ./gradlew clean generateProto test build
- name: Upload test artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: cd-test-artifacts
if-no-files-found: warn
path: |
build/test-results/test/**
build/reports/tests/test/**
build/testcontainers-logs/**
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build & Push Image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ env.IMAGE_REPO }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Install kubectl (if needed)
uses: azure/setup-kubectl@v4
with:
version: v1.33.6
- name: Create kubeconfig from in-cluster ServiceAccount
shell: bash
run: |
TOKEN="$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)"
CA_PATH="/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
cat > kubeconfig <<EOF
apiVersion: v1
kind: Config
clusters:
- name: in-cluster
cluster:
server: https://kubernetes.default.svc
certificate-authority: ${CA_PATH}
contexts:
- name: in-cluster
context:
cluster: in-cluster
namespace: ${NAMESPACE}
user: sa
current-context: in-cluster
users:
- name: sa
user:
token: ${TOKEN}
EOF
echo "KUBECONFIG=$PWD/kubeconfig" >> $GITHUB_ENV
- name: Install envsubst
run: sudo apt-get update && sudo apt-get install -y gettext-base
- name: Deploy (apply manifest with GITHUB_SHA substitution)
shell: bash
run: |
command -v envsubst >/dev/null 2>&1 || (echo "envsubst not found" && exit 1)
export GITHUB_SHA="${{ github.sha }}"
envsubst < "${MANIFEST_PATH}" | kubectl apply -f -
- name: Rollout status
run: kubectl rollout status deployment/${{ env.DEPLOYMENT_NAME }} -n ${{ env.NAMESPACE }} --timeout=180s